blob: 164bb89d0b6a7b246d5ce98d874220029ebcfb5e [file] [log] [blame]
Chris Lattner57ad3782011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner57ad3782011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattner57ad3782011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregor577f75a2009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
Chandler Carruth55fc8732012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3e4c6c42011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Alexey Bataev4fa7eab2013-07-19 03:13:43 +000027#include "clang/AST/StmtOpenMP.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000028#include "clang/Lex/Preprocessor.h"
Chandler Carruth55fc8732012-12-04 09:13:33 +000029#include "clang/Sema/Designator.h"
30#include "clang/Sema/Lookup.h"
31#include "clang/Sema/Ownership.h"
32#include "clang/Sema/ParsedTemplate.h"
33#include "clang/Sema/ScopeInfo.h"
34#include "clang/Sema/SemaDiagnostic.h"
35#include "clang/Sema/SemaInternal.h"
David Blaikiea71f9d02011-09-22 02:34:54 +000036#include "llvm/ADT/ArrayRef.h"
John McCalla2becad2009-10-21 00:40:46 +000037#include "llvm/Support/ErrorHandling.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000038#include <algorithm>
39
40namespace clang {
John McCall781472f2010-08-25 08:40:02 +000041using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000042
Douglas Gregor577f75a2009-08-04 16:50:30 +000043/// \brief A semantic tree transformation that allows one to transform one
44/// abstract syntax tree into another.
45///
Mike Stump1eb44332009-09-09 15:08:12 +000046/// A new tree transformation is defined by creating a new subclass \c X of
47/// \c TreeTransform<X> and then overriding certain operations to provide
48/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000049/// instantiation is implemented as a tree transformation where the
50/// transformation of TemplateTypeParmType nodes involves substituting the
51/// template arguments for their corresponding template parameters; a similar
52/// transformation is performed for non-type template parameters and
53/// template template parameters.
54///
55/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000056/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000057/// override any of the transformation or rebuild operators by providing an
58/// operation with the same signature as the default implementation. The
59/// overridding function should not be virtual.
60///
61/// Semantic tree transformations are split into two stages, either of which
62/// can be replaced by a subclass. The "transform" step transforms an AST node
63/// or the parts of an AST node using the various transformation functions,
64/// then passes the pieces on to the "rebuild" step, which constructs a new AST
65/// node of the appropriate kind from the pieces. The default transformation
66/// routines recursively transform the operands to composite AST nodes (e.g.,
67/// the pointee type of a PointerType node) and, if any of those operand nodes
68/// were changed by the transformation, invokes the rebuild operation to create
69/// a new AST node.
70///
Mike Stump1eb44332009-09-09 15:08:12 +000071/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000072/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor9151c112011-03-02 18:50:38 +000073/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000074/// TransformTemplateName(), or TransformTemplateArgument() with entirely
75/// new implementations.
76///
77/// For more fine-grained transformations, subclasses can replace any of the
78/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000079/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000080/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000081/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000082/// parameters. Additionally, subclasses can override the \c RebuildXXX
83/// functions to control how AST nodes are rebuilt when their operands change.
84/// By default, \c TreeTransform will invoke semantic analysis to rebuild
85/// AST nodes. However, certain other tree transformations (e.g, cloning) may
86/// be able to use more efficient rebuild steps.
87///
88/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000089/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000090/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
91/// operands have not changed (\c AlwaysRebuild()), and customize the
92/// default locations and entity names used for type-checking
93/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000094template<typename Derived>
95class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000096 /// \brief Private RAII object that helps us forget and then re-remember
97 /// the template argument corresponding to a partially-substituted parameter
98 /// pack.
99 class ForgetPartiallySubstitutedPackRAII {
100 Derived &Self;
101 TemplateArgument Old;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000102
Douglas Gregord3731192011-01-10 07:32:04 +0000103 public:
104 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
105 Old = Self.ForgetPartiallySubstitutedPack();
106 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000107
Douglas Gregord3731192011-01-10 07:32:04 +0000108 ~ForgetPartiallySubstitutedPackRAII() {
109 Self.RememberPartiallySubstitutedPack(Old);
110 }
111 };
Chad Rosier4a9d7952012-08-08 18:46:20 +0000112
Douglas Gregor577f75a2009-08-04 16:50:30 +0000113protected:
114 Sema &SemaRef;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000115
Douglas Gregordfca6f52012-02-13 22:00:16 +0000116 /// \brief The set of local declarations that have been transformed, for
117 /// cases where we are forced to build new declarations within the transformer
118 /// rather than in the subclass (e.g., lambda closure types).
119 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000120
Mike Stump1eb44332009-09-09 15:08:12 +0000121public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000122 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000123 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000124
Douglas Gregor577f75a2009-08-04 16:50:30 +0000125 /// \brief Retrieves a reference to the derived class.
126 Derived &getDerived() { return static_cast<Derived&>(*this); }
127
128 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000129 const Derived &getDerived() const {
130 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000131 }
132
John McCall60d7b3a2010-08-24 06:29:42 +0000133 static inline ExprResult Owned(Expr *E) { return E; }
134 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000135
Douglas Gregor577f75a2009-08-04 16:50:30 +0000136 /// \brief Retrieves a reference to the semantic analysis object used for
137 /// this tree transform.
138 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000139
Douglas Gregor577f75a2009-08-04 16:50:30 +0000140 /// \brief Whether the transformation should always rebuild AST nodes, even
141 /// if none of the children have changed.
142 ///
143 /// Subclasses may override this function to specify when the transformation
144 /// should rebuild all AST nodes.
145 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000146
Douglas Gregor577f75a2009-08-04 16:50:30 +0000147 /// \brief Returns the location of the entity being transformed, if that
148 /// information was not available elsewhere in the AST.
149 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000150 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000151 /// provide an alternative implementation that provides better location
152 /// information.
153 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000154
Douglas Gregor577f75a2009-08-04 16:50:30 +0000155 /// \brief Returns the name of the entity being transformed, if that
156 /// information was not available elsewhere in the AST.
157 ///
158 /// By default, returns an empty name. Subclasses can provide an alternative
159 /// implementation with a more precise name.
160 DeclarationName getBaseEntity() { return DeclarationName(); }
161
Douglas Gregorb98b1992009-08-11 05:31:07 +0000162 /// \brief Sets the "base" location and entity when that
163 /// information is known based on another transformation.
164 ///
165 /// By default, the source location and entity are ignored. Subclasses can
166 /// override this function to provide a customized implementation.
167 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000168
Douglas Gregorb98b1992009-08-11 05:31:07 +0000169 /// \brief RAII object that temporarily sets the base location and entity
170 /// used for reporting diagnostics in types.
171 class TemporaryBase {
172 TreeTransform &Self;
173 SourceLocation OldLocation;
174 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000175
Douglas Gregorb98b1992009-08-11 05:31:07 +0000176 public:
177 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000178 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000179 OldLocation = Self.getDerived().getBaseLocation();
180 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000181
Douglas Gregorae201f72011-01-25 17:51:48 +0000182 if (Location.isValid())
183 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000184 }
Mike Stump1eb44332009-09-09 15:08:12 +0000185
Douglas Gregorb98b1992009-08-11 05:31:07 +0000186 ~TemporaryBase() {
187 Self.getDerived().setBase(OldLocation, OldEntity);
188 }
189 };
Mike Stump1eb44332009-09-09 15:08:12 +0000190
191 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000192 /// transformed.
193 ///
194 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000195 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000196 /// not change. For example, template instantiation need not traverse
197 /// non-dependent types.
198 bool AlreadyTransformed(QualType T) {
199 return T.isNull();
200 }
201
Douglas Gregor6eef5192009-12-14 19:27:10 +0000202 /// \brief Determine whether the given call argument should be dropped, e.g.,
203 /// because it is a default argument.
204 ///
205 /// Subclasses can provide an alternative implementation of this routine to
206 /// determine which kinds of call arguments get dropped. By default,
207 /// CXXDefaultArgument nodes are dropped (prior to transformation).
208 bool DropCallArgument(Expr *E) {
209 return E->isDefaultArgument();
210 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000211
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000212 /// \brief Determine whether we should expand a pack expansion with the
213 /// given set of parameter packs into separate arguments by repeatedly
214 /// transforming the pattern.
215 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000216 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000217 /// Subclasses can override this routine to provide different behavior.
218 ///
219 /// \param EllipsisLoc The location of the ellipsis that identifies the
220 /// pack expansion.
221 ///
222 /// \param PatternRange The source range that covers the entire pattern of
223 /// the pack expansion.
224 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000225 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000226 /// pattern.
227 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000228 /// \param ShouldExpand Will be set to \c true if the transformer should
229 /// expand the corresponding pack expansions into separate arguments. When
230 /// set, \c NumExpansions must also be set.
231 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000232 /// \param RetainExpansion Whether the caller should add an unexpanded
233 /// pack expansion after all of the expanded arguments. This is used
234 /// when extending explicitly-specified template argument packs per
235 /// C++0x [temp.arg.explicit]p9.
236 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000237 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000238 /// the expanded form of the corresponding pack expansion. This is both an
239 /// input and an output parameter, which can be set by the caller if the
240 /// number of expansions is known a priori (e.g., due to a prior substitution)
241 /// and will be set by the callee when the number of expansions is known.
242 /// The callee must set this value when \c ShouldExpand is \c true; it may
243 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000244 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000245 /// \returns true if an error occurred (e.g., because the parameter packs
246 /// are to be instantiated with arguments of different lengths), false
247 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000248 /// must be set.
249 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
250 SourceRange PatternRange,
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +0000251 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000252 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000253 bool &RetainExpansion,
David Blaikiedc84cd52013-02-20 22:23:23 +0000254 Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000255 ShouldExpand = false;
256 return false;
257 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000258
Douglas Gregord3731192011-01-10 07:32:04 +0000259 /// \brief "Forget" about the partially-substituted pack template argument,
260 /// when performing an instantiation that must preserve the parameter pack
261 /// use.
262 ///
263 /// This routine is meant to be overridden by the template instantiator.
264 TemplateArgument ForgetPartiallySubstitutedPack() {
265 return TemplateArgument();
266 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000267
Douglas Gregord3731192011-01-10 07:32:04 +0000268 /// \brief "Remember" the partially-substituted pack template argument
269 /// after performing an instantiation that must preserve the parameter pack
270 /// use.
271 ///
272 /// This routine is meant to be overridden by the template instantiator.
273 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000274
Douglas Gregor12c9c002011-01-07 16:43:16 +0000275 /// \brief Note to the derived class when a function parameter pack is
276 /// being expanded.
277 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000278
Douglas Gregor577f75a2009-08-04 16:50:30 +0000279 /// \brief Transforms the given type into another type.
280 ///
John McCalla2becad2009-10-21 00:40:46 +0000281 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000282 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000283 /// function. This is expensive, but we don't mind, because
284 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000285 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000286 ///
287 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000288 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000289
John McCalla2becad2009-10-21 00:40:46 +0000290 /// \brief Transforms the given type-with-location into a new
291 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000292 ///
John McCalla2becad2009-10-21 00:40:46 +0000293 /// By default, this routine transforms a type by delegating to the
294 /// appropriate TransformXXXType to build a new type. Subclasses
295 /// may override this function (to take over all type
296 /// transformations) or some set of the TransformXXXType functions
297 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000298 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000299
300 /// \brief Transform the given type-with-location into a new
301 /// type, collecting location information in the given builder
302 /// as necessary.
303 ///
John McCall43fed0d2010-11-12 08:19:04 +0000304 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000305
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000306 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000307 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000308 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000309 /// appropriate TransformXXXStmt function to transform a specific kind of
310 /// statement or the TransformExpr() function to transform an expression.
311 /// Subclasses may override this function to transform statements using some
312 /// other mechanism.
313 ///
314 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000315 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000316
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000317 /// \brief Transform the given statement.
318 ///
319 /// By default, this routine transforms a statement by delegating to the
320 /// appropriate TransformOMPXXXClause function to transform a specific kind
321 /// of clause. Subclasses may override this function to transform statements
322 /// using some other mechanism.
323 ///
324 /// \returns the transformed OpenMP clause.
325 OMPClause *TransformOMPClause(OMPClause *S);
326
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000327 /// \brief Transform the given expression.
328 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000329 /// By default, this routine transforms an expression by delegating to the
330 /// appropriate TransformXXXExpr function to build a new expression.
331 /// Subclasses may override this function to transform expressions using some
332 /// other mechanism.
333 ///
334 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000335 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000336
Richard Smithc83c2302012-12-19 01:39:02 +0000337 /// \brief Transform the given initializer.
338 ///
339 /// By default, this routine transforms an initializer by stripping off the
340 /// semantic nodes added by initialization, then passing the result to
341 /// TransformExpr or TransformExprs.
342 ///
343 /// \returns the transformed initializer.
344 ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
345
Douglas Gregoraa165f82011-01-03 19:04:46 +0000346 /// \brief Transform the given list of expressions.
347 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000348 /// This routine transforms a list of expressions by invoking
349 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregoraa165f82011-01-03 19:04:46 +0000350 /// support for variadic templates by expanding any pack expansions (if the
351 /// derived class permits such expansion) along the way. When pack expansions
352 /// are present, the number of outputs may not equal the number of inputs.
353 ///
354 /// \param Inputs The set of expressions to be transformed.
355 ///
356 /// \param NumInputs The number of expressions in \c Inputs.
357 ///
358 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier4a9d7952012-08-08 18:46:20 +0000359 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregoraa165f82011-01-03 19:04:46 +0000360 /// be.
361 ///
362 /// \param Outputs The transformed input expressions will be added to this
363 /// vector.
364 ///
365 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
366 /// due to transformation.
367 ///
368 /// \returns true if an error occurred, false otherwise.
369 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +0000370 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000371 bool *ArgChanged = 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000372
Douglas Gregor577f75a2009-08-04 16:50:30 +0000373 /// \brief Transform the given declaration, which is referenced from a type
374 /// or expression.
375 ///
Douglas Gregordfca6f52012-02-13 22:00:16 +0000376 /// By default, acts as the identity function on declarations, unless the
377 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregordcee1a12009-08-06 05:28:30 +0000378 /// may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000379 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregordfca6f52012-02-13 22:00:16 +0000380 llvm::DenseMap<Decl *, Decl *>::iterator Known
381 = TransformedLocalDecls.find(D);
382 if (Known != TransformedLocalDecls.end())
383 return Known->second;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000384
385 return D;
Douglas Gregordfca6f52012-02-13 22:00:16 +0000386 }
Douglas Gregor43959a92009-08-20 07:17:43 +0000387
Chad Rosier4a9d7952012-08-08 18:46:20 +0000388 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregordfca6f52012-02-13 22:00:16 +0000389 /// place them on the new declaration.
390 ///
391 /// By default, this operation does nothing. Subclasses may override this
392 /// behavior to transform attributes.
393 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000394
Douglas Gregordfca6f52012-02-13 22:00:16 +0000395 /// \brief Note that a local declaration has been transformed by this
396 /// transformer.
397 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000398 /// Local declarations are typically transformed via a call to
Douglas Gregordfca6f52012-02-13 22:00:16 +0000399 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
400 /// the transformer itself has to transform the declarations. This routine
401 /// can be overridden by a subclass that keeps track of such mappings.
402 void transformedLocalDecl(Decl *Old, Decl *New) {
403 TransformedLocalDecls[Old] = New;
404 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000405
Douglas Gregor43959a92009-08-20 07:17:43 +0000406 /// \brief Transform the definition of the given declaration.
407 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000408 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000409 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000410 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
411 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000412 }
Mike Stump1eb44332009-09-09 15:08:12 +0000413
Douglas Gregor6cd21982009-10-20 05:58:46 +0000414 /// \brief Transform the given declaration, which was the first part of a
415 /// nested-name-specifier in a member access expression.
416 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000417 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000418 /// identifier in a nested-name-specifier of a member access expression, e.g.,
419 /// the \c T in \c x->T::member
420 ///
421 /// By default, invokes TransformDecl() to transform the declaration.
422 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000423 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
424 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000425 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000426
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000427 /// \brief Transform the given nested-name-specifier with source-location
428 /// information.
429 ///
430 /// By default, transforms all of the types and declarations within the
431 /// nested-name-specifier. Subclasses may override this function to provide
432 /// alternate behavior.
433 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
434 NestedNameSpecifierLoc NNS,
435 QualType ObjectType = QualType(),
436 NamedDecl *FirstQualifierInScope = 0);
437
Douglas Gregor81499bb2009-09-03 22:13:48 +0000438 /// \brief Transform the given declaration name.
439 ///
440 /// By default, transforms the types of conversion function, constructor,
441 /// and destructor names and then (if needed) rebuilds the declaration name.
442 /// Identifiers and selectors are returned unmodified. Sublcasses may
443 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000444 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000445 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000446
Douglas Gregor577f75a2009-08-04 16:50:30 +0000447 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000448 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000449 /// \param SS The nested-name-specifier that qualifies the template
450 /// name. This nested-name-specifier must already have been transformed.
451 ///
452 /// \param Name The template name to transform.
453 ///
454 /// \param NameLoc The source location of the template name.
455 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000456 /// \param ObjectType If we're translating a template name within a member
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000457 /// access expression, this is the type of the object whose member template
458 /// is being referenced.
459 ///
460 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
461 /// also refers to a name within the current (lexical) scope, this is the
462 /// declaration it refers to.
463 ///
464 /// By default, transforms the template name by transforming the declarations
465 /// and nested-name-specifiers that occur within the template name.
466 /// Subclasses may override this function to provide alternate behavior.
467 TemplateName TransformTemplateName(CXXScopeSpec &SS,
468 TemplateName Name,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000469 SourceLocation NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000470 QualType ObjectType = QualType(),
471 NamedDecl *FirstQualifierInScope = 0);
472
Douglas Gregor577f75a2009-08-04 16:50:30 +0000473 /// \brief Transform the given template argument.
474 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000475 /// By default, this operation transforms the type, expression, or
476 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000477 /// new template argument from the transformed result. Subclasses may
478 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000479 ///
480 /// Returns true if there was an error.
481 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
482 TemplateArgumentLoc &Output);
483
Douglas Gregorfcc12532010-12-20 17:31:10 +0000484 /// \brief Transform the given set of template arguments.
485 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000486 /// By default, this operation transforms all of the template arguments
Douglas Gregorfcc12532010-12-20 17:31:10 +0000487 /// in the input set using \c TransformTemplateArgument(), and appends
488 /// the transformed arguments to the output list.
489 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000490 /// Note that this overload of \c TransformTemplateArguments() is merely
491 /// a convenience function. Subclasses that wish to override this behavior
492 /// should override the iterator-based member template version.
493 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000494 /// \param Inputs The set of template arguments to be transformed.
495 ///
496 /// \param NumInputs The number of template arguments in \p Inputs.
497 ///
498 /// \param Outputs The set of transformed template arguments output by this
499 /// routine.
500 ///
501 /// Returns true if an error occurred.
502 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
503 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000504 TemplateArgumentListInfo &Outputs) {
505 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
506 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000507
508 /// \brief Transform the given set of template arguments.
509 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000510 /// By default, this operation transforms all of the template arguments
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000511 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier4a9d7952012-08-08 18:46:20 +0000512 /// the transformed arguments to the output list.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000513 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000514 /// \param First An iterator to the first template argument.
515 ///
516 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000517 ///
518 /// \param Outputs The set of transformed template arguments output by this
519 /// routine.
520 ///
521 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000522 template<typename InputIterator>
523 bool TransformTemplateArguments(InputIterator First,
524 InputIterator Last,
525 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000526
John McCall833ca992009-10-29 08:12:44 +0000527 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
528 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
529 TemplateArgumentLoc &ArgLoc);
530
John McCalla93c9342009-12-07 02:54:59 +0000531 /// \brief Fakes up a TypeSourceInfo for a type.
532 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
533 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000534 getDerived().getBaseLocation());
535 }
Mike Stump1eb44332009-09-09 15:08:12 +0000536
John McCalla2becad2009-10-21 00:40:46 +0000537#define ABSTRACT_TYPELOC(CLASS, PARENT)
538#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000539 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000540#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000541
Douglas Gregorcefc3af2012-04-16 07:05:22 +0000542 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
543 FunctionProtoTypeLoc TL,
544 CXXRecordDecl *ThisContext,
545 unsigned ThisTypeQuals);
546
John Wiegley28bbe4b2011-04-28 01:08:34 +0000547 StmtResult
548 TransformSEHHandler(Stmt *Handler);
549
Chad Rosier4a9d7952012-08-08 18:46:20 +0000550 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000551 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
552 TemplateSpecializationTypeLoc TL,
553 TemplateName Template);
554
Chad Rosier4a9d7952012-08-08 18:46:20 +0000555 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000556 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
557 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000558 TemplateName Template,
559 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000560
Chad Rosier4a9d7952012-08-08 18:46:20 +0000561 QualType
Douglas Gregora88f09f2011-02-28 17:23:35 +0000562 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000563 DependentTemplateSpecializationTypeLoc TL,
564 NestedNameSpecifierLoc QualifierLoc);
565
John McCall21ef0fa2010-03-11 09:03:00 +0000566 /// \brief Transforms the parameters of a function type into the
567 /// given vectors.
568 ///
569 /// The result vectors should be kept in sync; null entries in the
570 /// variables vector are acceptable.
571 ///
572 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000573 bool TransformFunctionTypeParams(SourceLocation Loc,
574 ParmVarDecl **Params, unsigned NumParams,
575 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000576 SmallVectorImpl<QualType> &PTypes,
577 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000578
579 /// \brief Transforms a single function-type parameter. Return null
580 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000581 ///
582 /// \param indexAdjustment - A number to add to the parameter's
583 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000584 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000585 int indexAdjustment,
David Blaikiedc84cd52013-02-20 22:23:23 +0000586 Optional<unsigned> NumExpansions,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000587 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000588
John McCall43fed0d2010-11-12 08:19:04 +0000589 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000590
John McCall60d7b3a2010-08-24 06:29:42 +0000591 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
592 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000593
Richard Smith612409e2012-07-25 03:56:55 +0000594 /// \brief Transform the captures and body of a lambda expression.
595 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator);
596
Richard Smithefeeccf2012-10-21 03:28:35 +0000597 ExprResult TransformAddressOfOperand(Expr *E);
598 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
599 bool IsAddressOfOperand);
600
Douglas Gregor43959a92009-08-20 07:17:43 +0000601#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000602 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000603#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000604 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000605#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000606#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000607
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000608#define OPENMP_CLAUSE(Name, Class) \
609 OMPClause *Transform ## Class(Class *S);
610#include "clang/Basic/OpenMPKinds.def"
611
Douglas Gregor577f75a2009-08-04 16:50:30 +0000612 /// \brief Build a new pointer type given its pointee type.
613 ///
614 /// By default, performs semantic analysis when building the pointer type.
615 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000616 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000617
618 /// \brief Build a new block pointer type given its pointee type.
619 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000620 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000621 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000622 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000623
John McCall85737a72009-10-30 00:06:24 +0000624 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000625 ///
John McCall85737a72009-10-30 00:06:24 +0000626 /// By default, performs semantic analysis when building the
627 /// reference type. Subclasses may override this routine to provide
628 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000629 ///
John McCall85737a72009-10-30 00:06:24 +0000630 /// \param LValue whether the type was written with an lvalue sigil
631 /// or an rvalue sigil.
632 QualType RebuildReferenceType(QualType ReferentType,
633 bool LValue,
634 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000635
Douglas Gregor577f75a2009-08-04 16:50:30 +0000636 /// \brief Build a new member pointer type given the pointee type and the
637 /// class type it refers into.
638 ///
639 /// By default, performs semantic analysis when building the member pointer
640 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000641 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
642 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000643
Douglas Gregor577f75a2009-08-04 16:50:30 +0000644 /// \brief Build a new array type given the element type, size
645 /// modifier, size of the array (if known), size expression, and index type
646 /// qualifiers.
647 ///
648 /// By default, performs semantic analysis when building the array type.
649 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000650 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000651 QualType RebuildArrayType(QualType ElementType,
652 ArrayType::ArraySizeModifier SizeMod,
653 const llvm::APInt *Size,
654 Expr *SizeExpr,
655 unsigned IndexTypeQuals,
656 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000657
Douglas Gregor577f75a2009-08-04 16:50:30 +0000658 /// \brief Build a new constant array type given the element type, size
659 /// modifier, (known) size of the array, and index type qualifiers.
660 ///
661 /// By default, performs semantic analysis when building the array type.
662 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000663 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000664 ArrayType::ArraySizeModifier SizeMod,
665 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000666 unsigned IndexTypeQuals,
667 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000668
Douglas Gregor577f75a2009-08-04 16:50:30 +0000669 /// \brief Build a new incomplete array type given the element type, size
670 /// modifier, and index type qualifiers.
671 ///
672 /// By default, performs semantic analysis when building the array type.
673 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000674 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000675 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000676 unsigned IndexTypeQuals,
677 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000678
Mike Stump1eb44332009-09-09 15:08:12 +0000679 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000680 /// size modifier, size expression, and index type qualifiers.
681 ///
682 /// By default, performs semantic analysis when building the array type.
683 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000684 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000685 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000686 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000687 unsigned IndexTypeQuals,
688 SourceRange BracketsRange);
689
Mike Stump1eb44332009-09-09 15:08:12 +0000690 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000691 /// size modifier, size expression, and index type qualifiers.
692 ///
693 /// By default, performs semantic analysis when building the array type.
694 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000695 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000696 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000697 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000698 unsigned IndexTypeQuals,
699 SourceRange BracketsRange);
700
701 /// \brief Build a new vector type given the element type and
702 /// number of elements.
703 ///
704 /// By default, performs semantic analysis when building the vector type.
705 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000706 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000707 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000708
Douglas Gregor577f75a2009-08-04 16:50:30 +0000709 /// \brief Build a new extended vector type given the element type and
710 /// number of elements.
711 ///
712 /// By default, performs semantic analysis when building the vector type.
713 /// Subclasses may override this routine to provide different behavior.
714 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
715 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000716
717 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000718 /// given the element type and number of elements.
719 ///
720 /// By default, performs semantic analysis when building the vector type.
721 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000722 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000723 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000724 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000725
Douglas Gregor577f75a2009-08-04 16:50:30 +0000726 /// \brief Build a new function type.
727 ///
728 /// By default, performs semantic analysis when building the function type.
729 /// Subclasses may override this routine to provide different behavior.
730 QualType RebuildFunctionProtoType(QualType T,
Jordan Rosebea522f2013-03-08 21:51:21 +0000731 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +0000732 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump1eb44332009-09-09 15:08:12 +0000733
John McCalla2becad2009-10-21 00:40:46 +0000734 /// \brief Build a new unprototyped function type.
735 QualType RebuildFunctionNoProtoType(QualType ResultType);
736
John McCalled976492009-12-04 22:46:56 +0000737 /// \brief Rebuild an unresolved typename type, given the decl that
738 /// the UnresolvedUsingTypenameDecl was transformed to.
739 QualType RebuildUnresolvedUsingType(Decl *D);
740
Douglas Gregor577f75a2009-08-04 16:50:30 +0000741 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000742 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000743 return SemaRef.Context.getTypeDeclType(Typedef);
744 }
745
746 /// \brief Build a new class/struct/union type.
747 QualType RebuildRecordType(RecordDecl *Record) {
748 return SemaRef.Context.getTypeDeclType(Record);
749 }
750
751 /// \brief Build a new Enum type.
752 QualType RebuildEnumType(EnumDecl *Enum) {
753 return SemaRef.Context.getTypeDeclType(Enum);
754 }
John McCall7da24312009-09-05 00:15:47 +0000755
Mike Stump1eb44332009-09-09 15:08:12 +0000756 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000757 ///
758 /// By default, performs semantic analysis when building the typeof type.
759 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000760 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000761
Mike Stump1eb44332009-09-09 15:08:12 +0000762 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000763 ///
764 /// By default, builds a new TypeOfType with the given underlying type.
765 QualType RebuildTypeOfType(QualType Underlying);
766
Sean Huntca63c202011-05-24 22:41:36 +0000767 /// \brief Build a new unary transform type.
768 QualType RebuildUnaryTransformType(QualType BaseType,
769 UnaryTransformType::UTTKind UKind,
770 SourceLocation Loc);
771
Richard Smitha2c36462013-04-26 16:15:35 +0000772 /// \brief Build a new C++11 decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000773 ///
774 /// By default, performs semantic analysis when building the decltype type.
775 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000776 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000777
Richard Smitha2c36462013-04-26 16:15:35 +0000778 /// \brief Build a new C++11 auto type.
Richard Smith34b41d92011-02-20 03:19:35 +0000779 ///
780 /// By default, builds a new AutoType with the given deduced type.
Richard Smitha2c36462013-04-26 16:15:35 +0000781 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smithdc7a4f52013-04-30 13:56:41 +0000782 // Note, IsDependent is always false here: we implicitly convert an 'auto'
783 // which has been deduced to a dependent type into an undeduced 'auto', so
784 // that we'll retry deduction after the transformation.
Faisal Valiecb58192013-08-22 01:49:11 +0000785 // FIXME: Can we assume the same about IsParameterPack?
786 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
787 /*IsDependent*/ false,
788 /*IsParameterPack*/ false);
Richard Smith34b41d92011-02-20 03:19:35 +0000789 }
790
Douglas Gregor577f75a2009-08-04 16:50:30 +0000791 /// \brief Build a new template specialization type.
792 ///
793 /// By default, performs semantic analysis when building the template
794 /// specialization type. Subclasses may override this routine to provide
795 /// different behavior.
796 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000797 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000798 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000799
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000800 /// \brief Build a new parenthesized type.
801 ///
802 /// By default, builds a new ParenType type from the inner type.
803 /// Subclasses may override this routine to provide different behavior.
804 QualType RebuildParenType(QualType InnerType) {
805 return SemaRef.Context.getParenType(InnerType);
806 }
807
Douglas Gregor577f75a2009-08-04 16:50:30 +0000808 /// \brief Build a new qualified name type.
809 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000810 /// By default, builds a new ElaboratedType type from the keyword,
811 /// the nested-name-specifier and the named type.
812 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000813 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
814 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000815 NestedNameSpecifierLoc QualifierLoc,
816 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000817 return SemaRef.Context.getElaboratedType(Keyword,
818 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000819 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000820 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000821
822 /// \brief Build a new typename type that refers to a template-id.
823 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000824 /// By default, builds a new DependentNameType type from the
825 /// nested-name-specifier and the given type. Subclasses may override
826 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000827 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000828 ElaboratedTypeKeyword Keyword,
829 NestedNameSpecifierLoc QualifierLoc,
830 const IdentifierInfo *Name,
831 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000832 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000833 // Rebuild the template name.
834 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000835 CXXScopeSpec SS;
836 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000837 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000838 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000839
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000840 if (InstName.isNull())
841 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000842
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000843 // If it's still dependent, make a dependent specialization.
844 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000845 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
846 QualifierLoc.getNestedNameSpecifier(),
847 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000848 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000849
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000850 // Otherwise, make an elaborated type wrapping a non-dependent
851 // specialization.
852 QualType T =
853 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
854 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000855
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000856 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
857 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000858
859 return SemaRef.Context.getElaboratedType(Keyword,
860 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000861 T);
862 }
863
Douglas Gregor577f75a2009-08-04 16:50:30 +0000864 /// \brief Build a new typename type that refers to an identifier.
865 ///
866 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000867 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000868 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000869 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000870 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000871 NestedNameSpecifierLoc QualifierLoc,
872 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000873 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000874 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000875 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000876
Douglas Gregor2494dd02011-03-01 01:34:45 +0000877 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000878 // If the name is still dependent, just build a new dependent name type.
879 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000880 return SemaRef.Context.getDependentNameType(Keyword,
881 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000882 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000883 }
884
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000885 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000886 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000887 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000888
889 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
890
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000891 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000892 // into a non-dependent elaborated-type-specifier. Find the tag we're
893 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000894 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000895 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
896 if (!DC)
897 return QualType();
898
John McCall56138762010-05-27 06:40:31 +0000899 if (SemaRef.RequireCompleteDeclContext(SS, DC))
900 return QualType();
901
Douglas Gregor40336422010-03-31 22:19:08 +0000902 TagDecl *Tag = 0;
903 SemaRef.LookupQualifiedName(Result, DC);
904 switch (Result.getResultKind()) {
905 case LookupResult::NotFound:
906 case LookupResult::NotFoundInCurrentInstantiation:
907 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000908
Douglas Gregor40336422010-03-31 22:19:08 +0000909 case LookupResult::Found:
910 Tag = Result.getAsSingle<TagDecl>();
911 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000912
Douglas Gregor40336422010-03-31 22:19:08 +0000913 case LookupResult::FoundOverloaded:
914 case LookupResult::FoundUnresolvedValue:
915 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000916
Douglas Gregor40336422010-03-31 22:19:08 +0000917 case LookupResult::Ambiguous:
918 // Let the LookupResult structure handle ambiguities.
919 return QualType();
920 }
921
922 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000923 // Check where the name exists but isn't a tag type and use that to emit
924 // better diagnostics.
925 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
926 SemaRef.LookupQualifiedName(Result, DC);
927 switch (Result.getResultKind()) {
928 case LookupResult::Found:
929 case LookupResult::FoundOverloaded:
930 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000931 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000932 unsigned Kind = 0;
933 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000934 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
935 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000936 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
937 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
938 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000939 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000940 default:
941 // FIXME: Would be nice to highlight just the source range.
942 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
943 << Kind << Id << DC;
944 break;
945 }
Douglas Gregor40336422010-03-31 22:19:08 +0000946 return QualType();
947 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000948
Richard Trieubbf34c02011-06-10 03:11:26 +0000949 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
950 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000951 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000952 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
953 return QualType();
954 }
955
956 // Build the elaborated-type-specifier type.
957 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000958 return SemaRef.Context.getElaboratedType(Keyword,
959 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000960 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000961 }
Mike Stump1eb44332009-09-09 15:08:12 +0000962
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000963 /// \brief Build a new pack expansion type.
964 ///
965 /// By default, builds a new PackExpansionType type from the given pattern.
966 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000967 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000968 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000969 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +0000970 Optional<unsigned> NumExpansions) {
Douglas Gregorcded4f62011-01-14 17:04:44 +0000971 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
972 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000973 }
974
Eli Friedmanb001de72011-10-06 23:00:33 +0000975 /// \brief Build a new atomic type given its value type.
976 ///
977 /// By default, performs semantic analysis when building the atomic type.
978 /// Subclasses may override this routine to provide different behavior.
979 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
980
Douglas Gregord1067e52009-08-06 06:41:21 +0000981 /// \brief Build a new template name given a nested name specifier, a flag
982 /// indicating whether the "template" keyword was provided, and the template
983 /// that the template name refers to.
984 ///
985 /// By default, builds the new template name directly. Subclasses may override
986 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000987 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000988 bool TemplateKW,
989 TemplateDecl *Template);
990
Douglas Gregord1067e52009-08-06 06:41:21 +0000991 /// \brief Build a new template name given a nested name specifier and the
992 /// name that is referred to as a template.
993 ///
994 /// By default, performs semantic analysis to determine whether the name can
995 /// be resolved to a specific template, then builds the appropriate kind of
996 /// template name. Subclasses may override this routine to provide different
997 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000998 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
999 const IdentifierInfo &Name,
1000 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00001001 QualType ObjectType,
1002 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00001003
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001004 /// \brief Build a new template name given a nested name specifier and the
1005 /// overloaded operator name that is referred to as a template.
1006 ///
1007 /// By default, performs semantic analysis to determine whether the name can
1008 /// be resolved to a specific template, then builds the appropriate kind of
1009 /// template name. Subclasses may override this routine to provide different
1010 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001011 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001012 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001013 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001014 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001015
1016 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +00001017 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001018 ///
1019 /// By default, performs semantic analysis to determine whether the name can
1020 /// be resolved to a specific template, then builds the appropriate kind of
1021 /// template name. Subclasses may override this routine to provide different
1022 /// behavior.
1023 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1024 const TemplateArgument &ArgPack) {
1025 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1026 }
1027
Douglas Gregor43959a92009-08-20 07:17:43 +00001028 /// \brief Build a new compound statement.
1029 ///
1030 /// By default, performs semantic analysis to build the new statement.
1031 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001032 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001033 MultiStmtArg Statements,
1034 SourceLocation RBraceLoc,
1035 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001036 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001037 IsStmtExpr);
1038 }
1039
1040 /// \brief Build a new case statement.
1041 ///
1042 /// By default, performs semantic analysis to build the new statement.
1043 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001044 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001045 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001046 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001047 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001048 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001049 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001050 ColonLoc);
1051 }
Mike Stump1eb44332009-09-09 15:08:12 +00001052
Douglas Gregor43959a92009-08-20 07:17:43 +00001053 /// \brief Attach the body to a new case statement.
1054 ///
1055 /// By default, performs semantic analysis to build the new statement.
1056 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001057 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001058 getSema().ActOnCaseStmtBody(S, Body);
1059 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001060 }
Mike Stump1eb44332009-09-09 15:08:12 +00001061
Douglas Gregor43959a92009-08-20 07:17:43 +00001062 /// \brief Build a new default statement.
1063 ///
1064 /// By default, performs semantic analysis to build the new statement.
1065 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001066 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001067 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001068 Stmt *SubStmt) {
1069 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001070 /*CurScope=*/0);
1071 }
Mike Stump1eb44332009-09-09 15:08:12 +00001072
Douglas Gregor43959a92009-08-20 07:17:43 +00001073 /// \brief Build a new label statement.
1074 ///
1075 /// By default, performs semantic analysis to build the new statement.
1076 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001077 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1078 SourceLocation ColonLoc, Stmt *SubStmt) {
1079 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001080 }
Mike Stump1eb44332009-09-09 15:08:12 +00001081
Richard Smith534986f2012-04-14 00:33:13 +00001082 /// \brief Build a new label statement.
1083 ///
1084 /// By default, performs semantic analysis to build the new statement.
1085 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001086 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1087 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001088 Stmt *SubStmt) {
1089 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1090 }
1091
Douglas Gregor43959a92009-08-20 07:17:43 +00001092 /// \brief Build a new "if" statement.
1093 ///
1094 /// By default, performs semantic analysis to build the new statement.
1095 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001096 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001097 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001098 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001099 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001100 }
Mike Stump1eb44332009-09-09 15:08:12 +00001101
Douglas Gregor43959a92009-08-20 07:17:43 +00001102 /// \brief Start building a new switch statement.
1103 ///
1104 /// By default, performs semantic analysis to build the new statement.
1105 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001106 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001107 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001108 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001109 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001110 }
Mike Stump1eb44332009-09-09 15:08:12 +00001111
Douglas Gregor43959a92009-08-20 07:17:43 +00001112 /// \brief Attach the body to the switch statement.
1113 ///
1114 /// By default, performs semantic analysis to build the new statement.
1115 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001116 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001117 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001118 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001119 }
1120
1121 /// \brief Build a new while statement.
1122 ///
1123 /// By default, performs semantic analysis to build the new statement.
1124 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001125 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1126 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001127 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001128 }
Mike Stump1eb44332009-09-09 15:08:12 +00001129
Douglas Gregor43959a92009-08-20 07:17:43 +00001130 /// \brief Build a new do-while statement.
1131 ///
1132 /// By default, performs semantic analysis to build the new statement.
1133 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001134 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001135 SourceLocation WhileLoc, SourceLocation LParenLoc,
1136 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001137 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1138 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001139 }
1140
1141 /// \brief Build a new for statement.
1142 ///
1143 /// By default, performs semantic analysis to build the new statement.
1144 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001145 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001146 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001147 VarDecl *CondVar, Sema::FullExprArg Inc,
1148 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001149 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001150 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001151 }
Mike Stump1eb44332009-09-09 15:08:12 +00001152
Douglas Gregor43959a92009-08-20 07:17:43 +00001153 /// \brief Build a new goto statement.
1154 ///
1155 /// By default, performs semantic analysis to build the new statement.
1156 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001157 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1158 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001159 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001160 }
1161
1162 /// \brief Build a new indirect goto statement.
1163 ///
1164 /// By default, performs semantic analysis to build the new statement.
1165 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001166 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001167 SourceLocation StarLoc,
1168 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001169 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001170 }
Mike Stump1eb44332009-09-09 15:08:12 +00001171
Douglas Gregor43959a92009-08-20 07:17:43 +00001172 /// \brief Build a new return statement.
1173 ///
1174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001176 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001177 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001178 }
Mike Stump1eb44332009-09-09 15:08:12 +00001179
Douglas Gregor43959a92009-08-20 07:17:43 +00001180 /// \brief Build a new declaration statement.
1181 ///
1182 /// By default, performs semantic analysis to build the new statement.
1183 /// Subclasses may override this routine to provide different behavior.
Rafael Espindola4549d7f2013-07-09 12:05:01 +00001184 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1185 SourceLocation StartLoc, SourceLocation EndLoc) {
1186 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith406c38e2011-02-23 00:37:57 +00001187 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001188 }
Mike Stump1eb44332009-09-09 15:08:12 +00001189
Anders Carlsson703e3942010-01-24 05:50:09 +00001190 /// \brief Build a new inline asm statement.
1191 ///
1192 /// By default, performs semantic analysis to build the new statement.
1193 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001194 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1195 bool IsVolatile, unsigned NumOutputs,
1196 unsigned NumInputs, IdentifierInfo **Names,
1197 MultiExprArg Constraints, MultiExprArg Exprs,
1198 Expr *AsmString, MultiExprArg Clobbers,
1199 SourceLocation RParenLoc) {
1200 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1201 NumInputs, Names, Constraints, Exprs,
1202 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001203 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001204
Chad Rosier8cd64b42012-06-11 20:47:18 +00001205 /// \brief Build a new MS style inline asm statement.
1206 ///
1207 /// By default, performs semantic analysis to build the new statement.
1208 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001209 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallaeeacf72013-05-03 00:10:13 +00001210 ArrayRef<Token> AsmToks,
1211 StringRef AsmString,
1212 unsigned NumOutputs, unsigned NumInputs,
1213 ArrayRef<StringRef> Constraints,
1214 ArrayRef<StringRef> Clobbers,
1215 ArrayRef<Expr*> Exprs,
1216 SourceLocation EndLoc) {
1217 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1218 NumOutputs, NumInputs,
1219 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001220 }
1221
James Dennett699c9042012-06-15 07:13:21 +00001222 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001223 ///
1224 /// By default, performs semantic analysis to build the new statement.
1225 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001226 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001227 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001228 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001229 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001230 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001231 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001232 }
1233
Douglas Gregorbe270a02010-04-26 17:57:08 +00001234 /// \brief Rebuild an Objective-C exception declaration.
1235 ///
1236 /// By default, performs semantic analysis to build the new declaration.
1237 /// Subclasses may override this routine to provide different behavior.
1238 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1239 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001240 return getSema().BuildObjCExceptionDecl(TInfo, T,
1241 ExceptionDecl->getInnerLocStart(),
1242 ExceptionDecl->getLocation(),
1243 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001244 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001245
James Dennett699c9042012-06-15 07:13:21 +00001246 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001247 ///
1248 /// By default, performs semantic analysis to build the new statement.
1249 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001250 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001251 SourceLocation RParenLoc,
1252 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001253 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001254 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001255 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001256 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001257
James Dennett699c9042012-06-15 07:13:21 +00001258 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001259 ///
1260 /// By default, performs semantic analysis to build the new statement.
1261 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001262 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001263 Stmt *Body) {
1264 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001265 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001266
James Dennett699c9042012-06-15 07:13:21 +00001267 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001268 ///
1269 /// By default, performs semantic analysis to build the new statement.
1270 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001271 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001272 Expr *Operand) {
1273 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001274 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001275
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00001276 /// \brief Build a new OpenMP parallel directive.
1277 ///
1278 /// By default, performs semantic analysis to build the new statement.
1279 /// Subclasses may override this routine to provide different behavior.
1280 StmtResult RebuildOMPParallelDirective(ArrayRef<OMPClause *> Clauses,
1281 Stmt *AStmt,
1282 SourceLocation StartLoc,
1283 SourceLocation EndLoc) {
1284 return getSema().ActOnOpenMPParallelDirective(Clauses, AStmt,
1285 StartLoc, EndLoc);
1286 }
1287
1288 /// \brief Build a new OpenMP 'default' clause.
1289 ///
1290 /// By default, performs semantic analysis to build the new statement.
1291 /// Subclasses may override this routine to provide different behavior.
1292 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1293 SourceLocation KindKwLoc,
1294 SourceLocation StartLoc,
1295 SourceLocation LParenLoc,
1296 SourceLocation EndLoc) {
1297 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1298 StartLoc, LParenLoc, EndLoc);
1299 }
1300
1301 /// \brief Build a new OpenMP 'private' clause.
1302 ///
1303 /// By default, performs semantic analysis to build the new statement.
1304 /// Subclasses may override this routine to provide different behavior.
1305 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1306 SourceLocation StartLoc,
1307 SourceLocation LParenLoc,
1308 SourceLocation EndLoc) {
1309 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1310 EndLoc);
1311 }
1312
James Dennett699c9042012-06-15 07:13:21 +00001313 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001314 ///
1315 /// By default, performs semantic analysis to build the new statement.
1316 /// Subclasses may override this routine to provide different behavior.
1317 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1318 Expr *object) {
1319 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1320 }
1321
James Dennett699c9042012-06-15 07:13:21 +00001322 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001323 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001324 /// By default, performs semantic analysis to build the new statement.
1325 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001326 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001327 Expr *Object, Stmt *Body) {
1328 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001329 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001330
James Dennett699c9042012-06-15 07:13:21 +00001331 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001332 ///
1333 /// By default, performs semantic analysis to build the new statement.
1334 /// Subclasses may override this routine to provide different behavior.
1335 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1336 Stmt *Body) {
1337 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1338 }
John McCall990567c2011-07-27 01:07:15 +00001339
Douglas Gregorc3203e72010-04-22 23:10:45 +00001340 /// \brief Build a new Objective-C fast enumeration statement.
1341 ///
1342 /// By default, performs semantic analysis to build the new statement.
1343 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001344 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001345 Stmt *Element,
1346 Expr *Collection,
1347 SourceLocation RParenLoc,
1348 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001349 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001350 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001351 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001352 RParenLoc);
1353 if (ForEachStmt.isInvalid())
1354 return StmtError();
1355
1356 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001357 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001358
Douglas Gregor43959a92009-08-20 07:17:43 +00001359 /// \brief Build a new C++ exception declaration.
1360 ///
1361 /// By default, performs semantic analysis to build the new decaration.
1362 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001363 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001364 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001365 SourceLocation StartLoc,
1366 SourceLocation IdLoc,
1367 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001368 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1369 StartLoc, IdLoc, Id);
1370 if (Var)
1371 getSema().CurContext->addDecl(Var);
1372 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001373 }
1374
1375 /// \brief Build a new C++ catch statement.
1376 ///
1377 /// By default, performs semantic analysis to build the new statement.
1378 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001379 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001380 VarDecl *ExceptionDecl,
1381 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001382 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1383 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001384 }
Mike Stump1eb44332009-09-09 15:08:12 +00001385
Douglas Gregor43959a92009-08-20 07:17:43 +00001386 /// \brief Build a new C++ try statement.
1387 ///
1388 /// By default, performs semantic analysis to build the new statement.
1389 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelm21adb0c2013-08-22 09:20:03 +00001390 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1391 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001392 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001393 }
Mike Stump1eb44332009-09-09 15:08:12 +00001394
Richard Smithad762fc2011-04-14 22:09:26 +00001395 /// \brief Build a new C++0x range-based for statement.
1396 ///
1397 /// By default, performs semantic analysis to build the new statement.
1398 /// Subclasses may override this routine to provide different behavior.
1399 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1400 SourceLocation ColonLoc,
1401 Stmt *Range, Stmt *BeginEnd,
1402 Expr *Cond, Expr *Inc,
1403 Stmt *LoopVar,
1404 SourceLocation RParenLoc) {
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001405 // If we've just learned that the range is actually an Objective-C
1406 // collection, treat this as an Objective-C fast enumeration loop.
1407 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1408 if (RangeStmt->isSingleDecl()) {
1409 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39b60dc2013-05-02 18:35:56 +00001410 if (RangeVar->isInvalidDecl())
1411 return StmtError();
1412
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001413 Expr *RangeExpr = RangeVar->getInit();
1414 if (!RangeExpr->isTypeDependent() &&
1415 RangeExpr->getType()->isObjCObjectPointerType())
1416 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1417 RParenLoc);
1418 }
1419 }
1420 }
1421
Richard Smithad762fc2011-04-14 22:09:26 +00001422 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001423 Cond, Inc, LoopVar, RParenLoc,
1424 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001425 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001426
1427 /// \brief Build a new C++0x range-based for statement.
1428 ///
1429 /// By default, performs semantic analysis to build the new statement.
1430 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001431 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001432 bool IsIfExists,
1433 NestedNameSpecifierLoc QualifierLoc,
1434 DeclarationNameInfo NameInfo,
1435 Stmt *Nested) {
1436 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1437 QualifierLoc, NameInfo, Nested);
1438 }
1439
Richard Smithad762fc2011-04-14 22:09:26 +00001440 /// \brief Attach body to a C++0x range-based for statement.
1441 ///
1442 /// By default, performs semantic analysis to finish the new statement.
1443 /// Subclasses may override this routine to provide different behavior.
1444 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1445 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1446 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001447
John Wiegley28bbe4b2011-04-28 01:08:34 +00001448 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1449 SourceLocation TryLoc,
1450 Stmt *TryBlock,
1451 Stmt *Handler) {
1452 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1453 }
1454
1455 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1456 Expr *FilterExpr,
1457 Stmt *Block) {
1458 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1459 }
1460
1461 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1462 Stmt *Block) {
1463 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1464 }
1465
Douglas Gregorb98b1992009-08-11 05:31:07 +00001466 /// \brief Build a new expression that references a declaration.
1467 ///
1468 /// By default, performs semantic analysis to build the new expression.
1469 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001470 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001471 LookupResult &R,
1472 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001473 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1474 }
1475
1476
1477 /// \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.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001481 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001482 ValueDecl *VD,
1483 const DeclarationNameInfo &NameInfo,
1484 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001485 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001486 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001487
1488 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001489
1490 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001491 }
Mike Stump1eb44332009-09-09 15:08:12 +00001492
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001494 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001495 /// By default, performs semantic analysis to build the new expression.
1496 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001497 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001498 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001499 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001500 }
1501
Douglas Gregora71d8192009-09-04 17:36:40 +00001502 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001503 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001504 /// By default, performs semantic analysis to build the new expression.
1505 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001506 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001507 SourceLocation OperatorLoc,
1508 bool isArrow,
1509 CXXScopeSpec &SS,
1510 TypeSourceInfo *ScopeType,
1511 SourceLocation CCLoc,
1512 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001513 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001514
Douglas Gregorb98b1992009-08-11 05:31:07 +00001515 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001516 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001517 /// By default, performs semantic analysis to build the new expression.
1518 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001519 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001520 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001521 Expr *SubExpr) {
1522 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001523 }
Mike Stump1eb44332009-09-09 15:08:12 +00001524
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001525 /// \brief Build a new builtin offsetof expression.
1526 ///
1527 /// By default, performs semantic analysis to build the new expression.
1528 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001529 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001530 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001531 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001532 unsigned NumComponents,
1533 SourceLocation RParenLoc) {
1534 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1535 NumComponents, RParenLoc);
1536 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001537
1538 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001539 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001540 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001541 /// By default, performs semantic analysis to build the new expression.
1542 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001543 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1544 SourceLocation OpLoc,
1545 UnaryExprOrTypeTrait ExprKind,
1546 SourceRange R) {
1547 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001548 }
1549
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001550 /// \brief Build a new sizeof, alignof or vec step expression with an
1551 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001552 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001553 /// By default, performs semantic analysis to build the new expression.
1554 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001555 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1556 UnaryExprOrTypeTrait ExprKind,
1557 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001558 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001559 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001560 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001561 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001562
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001563 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001564 }
Mike Stump1eb44332009-09-09 15:08:12 +00001565
Douglas Gregorb98b1992009-08-11 05:31:07 +00001566 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001567 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001568 /// By default, performs semantic analysis to build the new expression.
1569 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001570 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001571 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001572 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001573 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001574 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1575 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001576 RBracketLoc);
1577 }
1578
1579 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001580 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001581 /// By default, performs semantic analysis to build the new expression.
1582 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001583 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001584 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001585 SourceLocation RParenLoc,
1586 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001587 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001588 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001589 }
1590
1591 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001592 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001593 /// By default, performs semantic analysis to build the new expression.
1594 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001595 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001596 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001597 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001598 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001599 const DeclarationNameInfo &MemberNameInfo,
1600 ValueDecl *Member,
1601 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001602 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001603 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001604 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1605 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001606 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001607 // We have a reference to an unnamed field. This is always the
1608 // base of an anonymous struct/union member access, i.e. the
1609 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001610 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001611 assert(Member->getType()->isRecordType() &&
1612 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001613
Richard Smith9138b4e2011-10-26 19:06:56 +00001614 BaseResult =
1615 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001616 QualifierLoc.getNestedNameSpecifier(),
1617 FoundDecl, Member);
1618 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001619 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001620 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001621 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001622 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001623 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001624 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001625 cast<FieldDecl>(Member)->getType(),
1626 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001627 return getSema().Owned(ME);
1628 }
Mike Stump1eb44332009-09-09 15:08:12 +00001629
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001630 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001631 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001632
John Wiegley429bb272011-04-08 18:41:53 +00001633 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001634 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001635
John McCall6bb80172010-03-30 21:47:33 +00001636 // FIXME: this involves duplicating earlier analysis in a lot of
1637 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001638 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001639 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001640 R.resolveKind();
1641
John McCall9ae2f072010-08-23 23:25:46 +00001642 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001643 SS, TemplateKWLoc,
1644 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001645 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001646 }
Mike Stump1eb44332009-09-09 15:08:12 +00001647
Douglas Gregorb98b1992009-08-11 05:31:07 +00001648 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001649 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001650 /// By default, performs semantic analysis to build the new expression.
1651 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001652 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001653 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001654 Expr *LHS, Expr *RHS) {
1655 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001656 }
1657
1658 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001659 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001660 /// By default, performs semantic analysis to build the new expression.
1661 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001662 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001663 SourceLocation QuestionLoc,
1664 Expr *LHS,
1665 SourceLocation ColonLoc,
1666 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001667 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1668 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001669 }
1670
Douglas Gregorb98b1992009-08-11 05:31:07 +00001671 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001672 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001673 /// By default, performs semantic analysis to build the new expression.
1674 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001675 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001676 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001677 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001678 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001679 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001680 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001681 }
Mike Stump1eb44332009-09-09 15:08:12 +00001682
Douglas Gregorb98b1992009-08-11 05:31:07 +00001683 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001684 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001685 /// By default, performs semantic analysis to build the new expression.
1686 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001687 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001688 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001689 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001690 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001691 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001692 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001693 }
Mike Stump1eb44332009-09-09 15:08:12 +00001694
Douglas Gregorb98b1992009-08-11 05:31:07 +00001695 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001696 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001697 /// By default, performs semantic analysis to build the new expression.
1698 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001699 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001700 SourceLocation OpLoc,
1701 SourceLocation AccessorLoc,
1702 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001703
John McCall129e2df2009-11-30 22:42:35 +00001704 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001705 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001706 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001707 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001708 SS, SourceLocation(),
1709 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001710 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001711 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001712 }
Mike Stump1eb44332009-09-09 15:08:12 +00001713
Douglas Gregorb98b1992009-08-11 05:31:07 +00001714 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001715 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001716 /// By default, performs semantic analysis to build the new expression.
1717 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001718 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001719 MultiExprArg Inits,
1720 SourceLocation RBraceLoc,
1721 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001722 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001723 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001724 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001725 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001726
Douglas Gregore48319a2009-11-09 17:16:50 +00001727 // Patch in the result type we were given, which may have been computed
1728 // when the initial InitListExpr was built.
1729 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1730 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001731 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001732 }
Mike Stump1eb44332009-09-09 15:08:12 +00001733
Douglas Gregorb98b1992009-08-11 05:31:07 +00001734 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001735 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001736 /// By default, performs semantic analysis to build the new expression.
1737 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001738 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001739 MultiExprArg ArrayExprs,
1740 SourceLocation EqualOrColonLoc,
1741 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001742 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001743 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001744 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001745 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001746 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001747 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001748
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001749 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001750 }
Mike Stump1eb44332009-09-09 15:08:12 +00001751
Douglas Gregorb98b1992009-08-11 05:31:07 +00001752 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001753 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001754 /// By default, builds the implicit value initialization without performing
1755 /// any semantic analysis. Subclasses may override this routine to provide
1756 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001757 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001758 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1759 }
Mike Stump1eb44332009-09-09 15:08:12 +00001760
Douglas Gregorb98b1992009-08-11 05:31:07 +00001761 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001762 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001763 /// By default, performs semantic analysis to build the new expression.
1764 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001765 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001766 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001767 SourceLocation RParenLoc) {
1768 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001769 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001770 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001771 }
1772
1773 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001774 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001775 /// By default, performs semantic analysis to build the new expression.
1776 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001777 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001778 MultiExprArg SubExprs,
1779 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001780 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001781 }
Mike Stump1eb44332009-09-09 15:08:12 +00001782
Douglas Gregorb98b1992009-08-11 05:31:07 +00001783 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001784 ///
1785 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001786 /// rather than attempting to map the label statement itself.
1787 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001788 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001789 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001790 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791 }
Mike Stump1eb44332009-09-09 15:08:12 +00001792
Douglas Gregorb98b1992009-08-11 05:31:07 +00001793 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001794 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001795 /// By default, performs semantic analysis to build the new expression.
1796 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001797 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001798 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001799 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001800 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001801 }
Mike Stump1eb44332009-09-09 15:08:12 +00001802
Douglas Gregorb98b1992009-08-11 05:31:07 +00001803 /// \brief Build a new __builtin_choose_expr expression.
1804 ///
1805 /// By default, performs semantic analysis to build the new expression.
1806 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001807 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001808 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001809 SourceLocation RParenLoc) {
1810 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001811 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001812 RParenLoc);
1813 }
Mike Stump1eb44332009-09-09 15:08:12 +00001814
Peter Collingbournef111d932011-04-15 00:35:48 +00001815 /// \brief Build a new generic selection expression.
1816 ///
1817 /// By default, performs semantic analysis to build the new expression.
1818 /// Subclasses may override this routine to provide different behavior.
1819 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1820 SourceLocation DefaultLoc,
1821 SourceLocation RParenLoc,
1822 Expr *ControllingExpr,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001823 ArrayRef<TypeSourceInfo *> Types,
1824 ArrayRef<Expr *> Exprs) {
Peter Collingbournef111d932011-04-15 00:35:48 +00001825 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001826 ControllingExpr, Types, Exprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00001827 }
1828
Douglas Gregorb98b1992009-08-11 05:31:07 +00001829 /// \brief Build a new overloaded operator call expression.
1830 ///
1831 /// By default, performs semantic analysis to build the new expression.
1832 /// The semantic analysis provides the behavior of template instantiation,
1833 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001834 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001835 /// argument-dependent lookup, etc. Subclasses may override this routine to
1836 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001837 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001838 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001839 Expr *Callee,
1840 Expr *First,
1841 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001842
1843 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001844 /// reinterpret_cast.
1845 ///
1846 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001847 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001848 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001849 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001850 Stmt::StmtClass Class,
1851 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001852 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001853 SourceLocation RAngleLoc,
1854 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001855 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001856 SourceLocation RParenLoc) {
1857 switch (Class) {
1858 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001859 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001860 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001861 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001862
1863 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001864 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001865 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001866 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001867
Douglas Gregorb98b1992009-08-11 05:31:07 +00001868 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001869 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001870 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001871 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001872 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001873
Douglas Gregorb98b1992009-08-11 05:31:07 +00001874 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001875 return getDerived().RebuildCXXConstCastExpr(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 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001880 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001881 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001882 }
Mike Stump1eb44332009-09-09 15:08:12 +00001883
Douglas Gregorb98b1992009-08-11 05:31:07 +00001884 /// \brief Build a new C++ static_cast expression.
1885 ///
1886 /// By default, performs semantic analysis to build the new expression.
1887 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001888 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001889 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001890 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001891 SourceLocation RAngleLoc,
1892 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001893 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001894 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001895 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001896 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001897 SourceRange(LAngleLoc, RAngleLoc),
1898 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001899 }
1900
1901 /// \brief Build a new C++ dynamic_cast expression.
1902 ///
1903 /// By default, performs semantic analysis to build the new expression.
1904 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001905 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001906 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001907 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001908 SourceLocation RAngleLoc,
1909 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001910 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001911 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001912 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001913 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001914 SourceRange(LAngleLoc, RAngleLoc),
1915 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001916 }
1917
1918 /// \brief Build a new C++ reinterpret_cast expression.
1919 ///
1920 /// By default, performs semantic analysis to build the new expression.
1921 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001922 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001923 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001924 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001925 SourceLocation RAngleLoc,
1926 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001927 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001928 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001929 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001930 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001931 SourceRange(LAngleLoc, RAngleLoc),
1932 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001933 }
1934
1935 /// \brief Build a new C++ const_cast expression.
1936 ///
1937 /// By default, performs semantic analysis to build the new expression.
1938 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001939 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001940 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001941 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001942 SourceLocation RAngleLoc,
1943 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001944 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001945 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001946 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001947 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001948 SourceRange(LAngleLoc, RAngleLoc),
1949 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001950 }
Mike Stump1eb44332009-09-09 15:08:12 +00001951
Douglas Gregorb98b1992009-08-11 05:31:07 +00001952 /// \brief Build a new C++ functional-style cast expression.
1953 ///
1954 /// By default, performs semantic analysis to build the new expression.
1955 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001956 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1957 SourceLocation LParenLoc,
1958 Expr *Sub,
1959 SourceLocation RParenLoc) {
1960 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001961 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001962 RParenLoc);
1963 }
Mike Stump1eb44332009-09-09 15:08:12 +00001964
Douglas Gregorb98b1992009-08-11 05:31:07 +00001965 /// \brief Build a new C++ typeid(type) expression.
1966 ///
1967 /// By default, performs semantic analysis to build the new expression.
1968 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001969 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001970 SourceLocation TypeidLoc,
1971 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001972 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001973 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001974 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001975 }
Mike Stump1eb44332009-09-09 15:08:12 +00001976
Francois Pichet01b7c302010-09-08 12:20:18 +00001977
Douglas Gregorb98b1992009-08-11 05:31:07 +00001978 /// \brief Build a new C++ typeid(expr) expression.
1979 ///
1980 /// By default, performs semantic analysis to build the new expression.
1981 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001982 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001983 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001984 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001985 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001986 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001987 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001988 }
1989
Francois Pichet01b7c302010-09-08 12:20:18 +00001990 /// \brief Build a new C++ __uuidof(type) expression.
1991 ///
1992 /// By default, performs semantic analysis to build the new expression.
1993 /// Subclasses may override this routine to provide different behavior.
1994 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1995 SourceLocation TypeidLoc,
1996 TypeSourceInfo *Operand,
1997 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001998 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00001999 RParenLoc);
2000 }
2001
2002 /// \brief Build a new C++ __uuidof(expr) expression.
2003 ///
2004 /// By default, performs semantic analysis to build the new expression.
2005 /// Subclasses may override this routine to provide different behavior.
2006 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2007 SourceLocation TypeidLoc,
2008 Expr *Operand,
2009 SourceLocation RParenLoc) {
2010 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2011 RParenLoc);
2012 }
2013
Douglas Gregorb98b1992009-08-11 05:31:07 +00002014 /// \brief Build a new C++ "this" expression.
2015 ///
2016 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00002017 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00002018 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002019 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00002020 QualType ThisType,
2021 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00002022 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002023 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00002024 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2025 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002026 }
2027
2028 /// \brief Build a new C++ throw expression.
2029 ///
2030 /// By default, performs semantic analysis to build the new expression.
2031 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00002032 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2033 bool IsThrownVariableInScope) {
2034 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002035 }
2036
2037 /// \brief Build a new C++ default-argument expression.
2038 ///
2039 /// By default, builds a new default-argument expression, which does not
2040 /// require any semantic analysis. Subclasses may override this routine to
2041 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002042 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00002043 ParmVarDecl *Param) {
2044 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2045 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002046 }
2047
Richard Smithc3bf52c2013-04-20 22:23:05 +00002048 /// \brief Build a new C++11 default-initialization expression.
2049 ///
2050 /// By default, builds a new default field initialization expression, which
2051 /// does not require any semantic analysis. Subclasses may override this
2052 /// routine to provide different behavior.
2053 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2054 FieldDecl *Field) {
2055 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2056 Field));
2057 }
2058
Douglas Gregorb98b1992009-08-11 05:31:07 +00002059 /// \brief Build a new C++ zero-initialization expression.
2060 ///
2061 /// By default, performs semantic analysis to build the new expression.
2062 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002063 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2064 SourceLocation LParenLoc,
2065 SourceLocation RParenLoc) {
2066 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002067 None, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002068 }
Mike Stump1eb44332009-09-09 15:08:12 +00002069
Douglas Gregorb98b1992009-08-11 05:31:07 +00002070 /// \brief Build a new C++ "new" expression.
2071 ///
2072 /// By default, performs semantic analysis to build the new expression.
2073 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002074 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002075 bool UseGlobal,
2076 SourceLocation PlacementLParen,
2077 MultiExprArg PlacementArgs,
2078 SourceLocation PlacementRParen,
2079 SourceRange TypeIdParens,
2080 QualType AllocatedType,
2081 TypeSourceInfo *AllocatedTypeInfo,
2082 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002083 SourceRange DirectInitRange,
2084 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00002085 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002086 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002087 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002088 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002089 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002090 AllocatedType,
2091 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002092 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002093 DirectInitRange,
2094 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002095 }
Mike Stump1eb44332009-09-09 15:08:12 +00002096
Douglas Gregorb98b1992009-08-11 05:31:07 +00002097 /// \brief Build a new C++ "delete" expression.
2098 ///
2099 /// By default, performs semantic analysis to build the new expression.
2100 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002101 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002102 bool IsGlobalDelete,
2103 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002104 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002105 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002106 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002107 }
Mike Stump1eb44332009-09-09 15:08:12 +00002108
Douglas Gregorb98b1992009-08-11 05:31:07 +00002109 /// \brief Build a new unary type trait expression.
2110 ///
2111 /// By default, performs semantic analysis to build the new expression.
2112 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002113 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002114 SourceLocation StartLoc,
2115 TypeSourceInfo *T,
2116 SourceLocation RParenLoc) {
2117 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002118 }
2119
Francois Pichet6ad6f282010-12-07 00:08:36 +00002120 /// \brief Build a new binary 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.
2124 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2125 SourceLocation StartLoc,
2126 TypeSourceInfo *LhsT,
2127 TypeSourceInfo *RhsT,
2128 SourceLocation RParenLoc) {
2129 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2130 }
2131
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002132 /// \brief Build a new type trait expression.
2133 ///
2134 /// By default, performs semantic analysis to build the new expression.
2135 /// Subclasses may override this routine to provide different behavior.
2136 ExprResult RebuildTypeTrait(TypeTrait Trait,
2137 SourceLocation StartLoc,
2138 ArrayRef<TypeSourceInfo *> Args,
2139 SourceLocation RParenLoc) {
2140 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2141 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002142
John Wiegley21ff2e52011-04-28 00:16:57 +00002143 /// \brief Build a new array 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 RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2148 SourceLocation StartLoc,
2149 TypeSourceInfo *TSInfo,
2150 Expr *DimExpr,
2151 SourceLocation RParenLoc) {
2152 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2153 }
2154
John Wiegley55262202011-04-25 06:54:41 +00002155 /// \brief Build a new expression trait expression.
2156 ///
2157 /// By default, performs semantic analysis to build the new expression.
2158 /// Subclasses may override this routine to provide different behavior.
2159 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2160 SourceLocation StartLoc,
2161 Expr *Queried,
2162 SourceLocation RParenLoc) {
2163 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2164 }
2165
Mike Stump1eb44332009-09-09 15:08:12 +00002166 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002167 /// expression.
2168 ///
2169 /// By default, performs semantic analysis to build the new expression.
2170 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002171 ExprResult RebuildDependentScopeDeclRefExpr(
2172 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002173 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002174 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002175 const TemplateArgumentListInfo *TemplateArgs,
2176 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002177 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002178 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002179
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002180 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002181 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002182 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002183
Richard Smithefeeccf2012-10-21 03:28:35 +00002184 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2185 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002186 }
2187
2188 /// \brief Build a new template-id expression.
2189 ///
2190 /// By default, performs semantic analysis to build the new expression.
2191 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002192 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002193 SourceLocation TemplateKWLoc,
2194 LookupResult &R,
2195 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002196 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002197 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2198 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002199 }
2200
2201 /// \brief Build a new object-construction expression.
2202 ///
2203 /// By default, performs semantic analysis to build the new expression.
2204 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002205 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002206 SourceLocation Loc,
2207 CXXConstructorDecl *Constructor,
2208 bool IsElidable,
2209 MultiExprArg Args,
2210 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002211 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002212 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002213 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002214 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002215 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002216 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002217 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002218 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002219
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002220 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002221 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002222 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002223 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002224 RequiresZeroInit, ConstructKind,
2225 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002226 }
2227
2228 /// \brief Build a new object-construction expression.
2229 ///
2230 /// By default, performs semantic analysis to build the new expression.
2231 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002232 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2233 SourceLocation LParenLoc,
2234 MultiExprArg Args,
2235 SourceLocation RParenLoc) {
2236 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002237 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002238 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002239 RParenLoc);
2240 }
2241
2242 /// \brief Build a new object-construction expression.
2243 ///
2244 /// By default, performs semantic analysis to build the new expression.
2245 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002246 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2247 SourceLocation LParenLoc,
2248 MultiExprArg Args,
2249 SourceLocation RParenLoc) {
2250 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002251 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002252 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002253 RParenLoc);
2254 }
Mike Stump1eb44332009-09-09 15:08:12 +00002255
Douglas Gregorb98b1992009-08-11 05:31:07 +00002256 /// \brief Build a new member reference expression.
2257 ///
2258 /// By default, performs semantic analysis to build the new expression.
2259 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002260 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002261 QualType BaseType,
2262 bool IsArrow,
2263 SourceLocation OperatorLoc,
2264 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002265 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002266 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002267 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002268 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002269 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002270 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002271
John McCall9ae2f072010-08-23 23:25:46 +00002272 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002273 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002274 SS, TemplateKWLoc,
2275 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002276 MemberNameInfo,
2277 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002278 }
2279
John McCall129e2df2009-11-30 22:42:35 +00002280 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002281 ///
2282 /// By default, performs semantic analysis to build the new expression.
2283 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002284 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2285 SourceLocation OperatorLoc,
2286 bool IsArrow,
2287 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002288 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002289 NamedDecl *FirstQualifierInScope,
2290 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002291 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002292 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002293 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002294
John McCall9ae2f072010-08-23 23:25:46 +00002295 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002296 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002297 SS, TemplateKWLoc,
2298 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002299 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002300 }
Mike Stump1eb44332009-09-09 15:08:12 +00002301
Sebastian Redl2e156222010-09-10 20:55:43 +00002302 /// \brief Build a new noexcept expression.
2303 ///
2304 /// By default, performs semantic analysis to build the new expression.
2305 /// Subclasses may override this routine to provide different behavior.
2306 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2307 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2308 }
2309
Douglas Gregoree8aff02011-01-04 17:33:58 +00002310 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002311 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2312 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002313 SourceLocation RParenLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002314 Optional<unsigned> Length) {
Douglas Gregor089e8932011-10-10 18:59:29 +00002315 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002316 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2317 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002318 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002319
2320 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2321 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002322 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002323 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002324
Patrick Beardeb382ec2012-04-19 00:25:12 +00002325 /// \brief Build a new Objective-C boxed expression.
2326 ///
2327 /// By default, performs semantic analysis to build the new expression.
2328 /// Subclasses may override this routine to provide different behavior.
2329 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2330 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2331 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002332
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002333 /// \brief Build a new Objective-C array literal.
2334 ///
2335 /// By default, performs semantic analysis to build the new expression.
2336 /// Subclasses may override this routine to provide different behavior.
2337 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2338 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002339 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002340 MultiExprArg(Elements, NumElements));
2341 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002342
2343 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002344 Expr *Base, Expr *Key,
2345 ObjCMethodDecl *getterMethod,
2346 ObjCMethodDecl *setterMethod) {
2347 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2348 getterMethod, setterMethod);
2349 }
2350
2351 /// \brief Build a new Objective-C dictionary literal.
2352 ///
2353 /// By default, performs semantic analysis to build the new expression.
2354 /// Subclasses may override this routine to provide different behavior.
2355 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2356 ObjCDictionaryElement *Elements,
2357 unsigned NumElements) {
2358 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2359 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002360
James Dennett699c9042012-06-15 07:13:21 +00002361 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002362 ///
2363 /// By default, performs semantic analysis to build the new expression.
2364 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002365 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002366 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002367 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002368 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002369 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002370 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002371
Douglas Gregor92e986e2010-04-22 16:44:27 +00002372 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002373 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002374 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002375 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002376 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002377 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002378 MultiExprArg Args,
2379 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002380 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2381 ReceiverTypeInfo->getType(),
2382 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002383 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002384 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002385 }
2386
2387 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002388 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002389 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002390 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002391 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002392 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002393 MultiExprArg Args,
2394 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002395 return SemaRef.BuildInstanceMessage(Receiver,
2396 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002397 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002398 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002399 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002400 }
2401
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002402 /// \brief Build a new Objective-C ivar reference expression.
2403 ///
2404 /// By default, performs semantic analysis to build the new expression.
2405 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002406 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002407 SourceLocation IvarLoc,
2408 bool IsArrow, bool IsFreeIvar) {
2409 // FIXME: We lose track of the IsFreeIvar bit.
2410 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002411 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002412 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2413 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002414 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002415 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002416 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002417 false);
John Wiegley429bb272011-04-08 18:41:53 +00002418 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002419 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002420
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002421 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002422 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002423
John Wiegley429bb272011-04-08 18:41:53 +00002424 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002425 /*FIXME:*/IvarLoc, IsArrow,
2426 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002427 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002428 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002429 /*TemplateArgs=*/0);
2430 }
Douglas Gregore3303542010-04-26 20:47:02 +00002431
2432 /// \brief Build a new Objective-C property reference expression.
2433 ///
2434 /// By default, performs semantic analysis to build the new expression.
2435 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002436 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002437 ObjCPropertyDecl *Property,
2438 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002439 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002440 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002441 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2442 Sema::LookupMemberName);
2443 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002444 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002445 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002446 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002447 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002448 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002449
Douglas Gregore3303542010-04-26 20:47:02 +00002450 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002451 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002452
John Wiegley429bb272011-04-08 18:41:53 +00002453 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002454 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002455 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002456 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002457 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002458 /*TemplateArgs=*/0);
2459 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002460
John McCall12f78a62010-12-02 01:19:52 +00002461 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002462 ///
2463 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002464 /// Subclasses may override this routine to provide different behavior.
2465 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2466 ObjCMethodDecl *Getter,
2467 ObjCMethodDecl *Setter,
2468 SourceLocation PropertyLoc) {
2469 // Since these expressions can only be value-dependent, we do not
2470 // need to perform semantic analysis again.
2471 return Owned(
2472 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2473 VK_LValue, OK_ObjCProperty,
2474 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002475 }
2476
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002477 /// \brief Build a new Objective-C "isa" expression.
2478 ///
2479 /// By default, performs semantic analysis to build the new expression.
2480 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002481 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002482 SourceLocation OpLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002483 bool IsArrow) {
2484 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002485 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002486 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2487 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002488 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002489 OpLoc,
John McCalld226f652010-08-21 09:40:31 +00002490 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002491 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002492 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002493
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002494 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002495 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002496
John Wiegley429bb272011-04-08 18:41:53 +00002497 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002498 OpLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002499 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002500 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002501 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002502 /*TemplateArgs=*/0);
2503 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002504
Douglas Gregorb98b1992009-08-11 05:31:07 +00002505 /// \brief Build a new shuffle vector expression.
2506 ///
2507 /// By default, performs semantic analysis to build the new expression.
2508 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002509 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002510 MultiExprArg SubExprs,
2511 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002512 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002513 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002514 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2515 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2516 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002517 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002518
Douglas Gregorb98b1992009-08-11 05:31:07 +00002519 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002520 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002521 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2522 SemaRef.Context.BuiltinFnTy,
2523 VK_RValue, BuiltinLoc);
2524 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2525 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2526 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002527
2528 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002529 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002530 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002531 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002532 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002533 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002534
Douglas Gregorb98b1992009-08-11 05:31:07 +00002535 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002536 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002537 }
John McCall43fed0d2010-11-12 08:19:04 +00002538
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002539 /// \brief Build a new template argument pack expansion.
2540 ///
2541 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002542 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002543 /// different behavior.
2544 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002545 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002546 Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002547 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002548 case TemplateArgument::Expression: {
2549 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002550 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2551 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002552 if (Result.isInvalid())
2553 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002554
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002555 return TemplateArgumentLoc(Result.get(), Result.get());
2556 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002557
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002558 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002559 return TemplateArgumentLoc(TemplateArgument(
2560 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002561 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002562 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002563 Pattern.getTemplateNameLoc(),
2564 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002565
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002566 case TemplateArgument::Null:
2567 case TemplateArgument::Integral:
2568 case TemplateArgument::Declaration:
2569 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002570 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002571 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002572 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002573
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002574 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002575 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002576 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002577 EllipsisLoc,
2578 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002579 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2580 Expansion);
2581 break;
2582 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002583
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002584 return TemplateArgumentLoc();
2585 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002586
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002587 /// \brief Build a new expression pack expansion.
2588 ///
2589 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002590 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002591 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002592 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002593 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002594 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002595 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002596
2597 /// \brief Build a new atomic operation expression.
2598 ///
2599 /// By default, performs semantic analysis to build the new expression.
2600 /// Subclasses may override this routine to provide different behavior.
2601 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2602 MultiExprArg SubExprs,
2603 QualType RetTy,
2604 AtomicExpr::AtomicOp Op,
2605 SourceLocation RParenLoc) {
2606 // Just create the expression; there is not any interesting semantic
2607 // analysis here because we can't actually build an AtomicExpr until
2608 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002609 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002610 RParenLoc);
2611 }
2612
John McCall43fed0d2010-11-12 08:19:04 +00002613private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002614 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2615 QualType ObjectType,
2616 NamedDecl *FirstQualifierInScope,
2617 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002618
2619 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2620 QualType ObjectType,
2621 NamedDecl *FirstQualifierInScope,
2622 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002623};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002624
Douglas Gregor43959a92009-08-20 07:17:43 +00002625template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002626StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002627 if (!S)
2628 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002629
Douglas Gregor43959a92009-08-20 07:17:43 +00002630 switch (S->getStmtClass()) {
2631 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002632
Douglas Gregor43959a92009-08-20 07:17:43 +00002633 // Transform individual statement nodes
2634#define STMT(Node, Parent) \
2635 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002636#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002637#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002638#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002639
Douglas Gregor43959a92009-08-20 07:17:43 +00002640 // Transform expressions by calling TransformExpr.
2641#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002642#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002643#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002644#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002645 {
John McCall60d7b3a2010-08-24 06:29:42 +00002646 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002647 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002648 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002649
Richard Smith41956372013-01-14 22:39:08 +00002650 return getSema().ActOnExprStmt(E);
Douglas Gregor43959a92009-08-20 07:17:43 +00002651 }
Mike Stump1eb44332009-09-09 15:08:12 +00002652 }
2653
John McCall3fa5cae2010-10-26 07:05:15 +00002654 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002655}
Mike Stump1eb44332009-09-09 15:08:12 +00002656
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002657template<typename Derived>
2658OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2659 if (!S)
2660 return S;
2661
2662 switch (S->getClauseKind()) {
2663 default: break;
2664 // Transform individual clause nodes
2665#define OPENMP_CLAUSE(Name, Class) \
2666 case OMPC_ ## Name : \
2667 return getDerived().Transform ## Class(cast<Class>(S));
2668#include "clang/Basic/OpenMPKinds.def"
2669 }
2670
2671 return S;
2672}
2673
Mike Stump1eb44332009-09-09 15:08:12 +00002674
Douglas Gregor670444e2009-08-04 22:27:00 +00002675template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002676ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002677 if (!E)
2678 return SemaRef.Owned(E);
2679
2680 switch (E->getStmtClass()) {
2681 case Stmt::NoStmtClass: break;
2682#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002683#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002684#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002685 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002686#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002687 }
2688
John McCall3fa5cae2010-10-26 07:05:15 +00002689 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002690}
2691
2692template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002693ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2694 bool CXXDirectInit) {
2695 // Initializers are instantiated like expressions, except that various outer
2696 // layers are stripped.
2697 if (!Init)
2698 return SemaRef.Owned(Init);
2699
2700 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2701 Init = ExprTemp->getSubExpr();
2702
Richard Smith858c2c32013-05-30 22:40:16 +00002703 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2704 Init = MTE->GetTemporaryExpr();
2705
Richard Smithc83c2302012-12-19 01:39:02 +00002706 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2707 Init = Binder->getSubExpr();
2708
2709 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2710 Init = ICE->getSubExprAsWritten();
2711
Richard Smith7c3e6152013-06-12 22:31:48 +00002712 if (CXXStdInitializerListExpr *ILE =
2713 dyn_cast<CXXStdInitializerListExpr>(Init))
2714 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2715
Richard Smith5cf15892012-12-21 08:13:35 +00002716 // If this is not a direct-initializer, we only need to reconstruct
2717 // InitListExprs. Other forms of copy-initialization will be a no-op if
2718 // the initializer is already the right type.
2719 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2720 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2721 return getDerived().TransformExpr(Init);
2722
2723 // Revert value-initialization back to empty parens.
2724 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2725 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002726 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002727 Parens.getEnd());
2728 }
2729
2730 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2731 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002732 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002733 SourceLocation());
2734
2735 // Revert initialization by constructor back to a parenthesized or braced list
2736 // of expressions. Any other form of initializer can just be reused directly.
2737 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002738 return getDerived().TransformExpr(Init);
2739
2740 SmallVector<Expr*, 8> NewArgs;
2741 bool ArgChanged = false;
2742 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2743 /*IsCall*/true, NewArgs, &ArgChanged))
2744 return ExprError();
2745
2746 // If this was list initialization, revert to list form.
2747 if (Construct->isListInitialization())
2748 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2749 Construct->getLocEnd(),
2750 Construct->getType());
2751
Richard Smithc83c2302012-12-19 01:39:02 +00002752 // Build a ParenListExpr to represent anything else.
2753 SourceRange Parens = Construct->getParenRange();
2754 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2755 Parens.getEnd());
2756}
2757
2758template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002759bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2760 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002761 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002762 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002763 bool *ArgChanged) {
2764 for (unsigned I = 0; I != NumInputs; ++I) {
2765 // If requested, drop call arguments that need to be dropped.
2766 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2767 if (ArgChanged)
2768 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002769
Douglas Gregoraa165f82011-01-03 19:04:46 +00002770 break;
2771 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002772
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002773 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2774 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002775
Chris Lattner686775d2011-07-20 06:58:45 +00002776 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002777 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2778 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002779
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002780 // Determine whether the set of unexpanded parameter packs can and should
2781 // be expanded.
2782 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002783 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00002784 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2785 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002786 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2787 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002788 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002789 Expand, RetainExpansion,
2790 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002791 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002792
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002793 if (!Expand) {
2794 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002795 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002796 // expansion.
2797 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2798 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2799 if (OutPattern.isInvalid())
2800 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002801
2802 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002803 Expansion->getEllipsisLoc(),
2804 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002805 if (Out.isInvalid())
2806 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002807
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002808 if (ArgChanged)
2809 *ArgChanged = true;
2810 Outputs.push_back(Out.get());
2811 continue;
2812 }
John McCallc8fc90a2011-07-06 07:30:07 +00002813
2814 // Record right away that the argument was changed. This needs
2815 // to happen even if the array expands to nothing.
2816 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002817
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002818 // The transform has determined that we should perform an elementwise
2819 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002820 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002821 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2822 ExprResult Out = getDerived().TransformExpr(Pattern);
2823 if (Out.isInvalid())
2824 return true;
2825
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002826 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002827 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2828 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002829 if (Out.isInvalid())
2830 return true;
2831 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002832
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002833 Outputs.push_back(Out.get());
2834 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002835
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002836 continue;
2837 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002838
Richard Smithc83c2302012-12-19 01:39:02 +00002839 ExprResult Result =
2840 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2841 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002842 if (Result.isInvalid())
2843 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002844
Douglas Gregoraa165f82011-01-03 19:04:46 +00002845 if (Result.get() != Inputs[I] && ArgChanged)
2846 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002847
2848 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002849 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002850
Douglas Gregoraa165f82011-01-03 19:04:46 +00002851 return false;
2852}
2853
2854template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002855NestedNameSpecifierLoc
2856TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2857 NestedNameSpecifierLoc NNS,
2858 QualType ObjectType,
2859 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002860 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002861 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002862 Qualifier = Qualifier.getPrefix())
2863 Qualifiers.push_back(Qualifier);
2864
2865 CXXScopeSpec SS;
2866 while (!Qualifiers.empty()) {
2867 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2868 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002869
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002870 switch (QNNS->getKind()) {
2871 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002872 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002873 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002874 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002875 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002876 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002877 FirstQualifierInScope, false))
2878 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002879
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002880 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002881
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002882 case NestedNameSpecifier::Namespace: {
2883 NamespaceDecl *NS
2884 = cast_or_null<NamespaceDecl>(
2885 getDerived().TransformDecl(
2886 Q.getLocalBeginLoc(),
2887 QNNS->getAsNamespace()));
2888 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2889 break;
2890 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002891
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002892 case NestedNameSpecifier::NamespaceAlias: {
2893 NamespaceAliasDecl *Alias
2894 = cast_or_null<NamespaceAliasDecl>(
2895 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2896 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002897 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002898 Q.getLocalEndLoc());
2899 break;
2900 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002901
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002902 case NestedNameSpecifier::Global:
2903 // There is no meaningful transformation that one could perform on the
2904 // global scope.
2905 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2906 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002907
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002908 case NestedNameSpecifier::TypeSpecWithTemplate:
2909 case NestedNameSpecifier::TypeSpec: {
2910 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2911 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002912
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002913 if (!TL)
2914 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002915
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002916 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002917 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002918 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002919 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002920 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002921 if (TL.getType()->isEnumeralType())
2922 SemaRef.Diag(TL.getBeginLoc(),
2923 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002924 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2925 Q.getLocalEndLoc());
2926 break;
2927 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002928 // If the nested-name-specifier is an invalid type def, don't emit an
2929 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002930 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2931 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002932 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002933 << TL.getType() << SS.getRange();
2934 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002935 return NestedNameSpecifierLoc();
2936 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002937 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002938
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002939 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002940 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002941 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002942 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002943
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002944 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002945 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002946 !getDerived().AlwaysRebuild())
2947 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002948
2949 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002950 // nested-name-specifier, do so.
2951 if (SS.location_size() == NNS.getDataLength() &&
2952 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2953 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2954
2955 // Allocate new nested-name-specifier location information.
2956 return SS.getWithLocInContext(SemaRef.Context);
2957}
2958
2959template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002960DeclarationNameInfo
2961TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002962::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002963 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002964 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002965 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002966
2967 switch (Name.getNameKind()) {
2968 case DeclarationName::Identifier:
2969 case DeclarationName::ObjCZeroArgSelector:
2970 case DeclarationName::ObjCOneArgSelector:
2971 case DeclarationName::ObjCMultiArgSelector:
2972 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002973 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002974 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002975 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002976
Douglas Gregor81499bb2009-09-03 22:13:48 +00002977 case DeclarationName::CXXConstructorName:
2978 case DeclarationName::CXXDestructorName:
2979 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002980 TypeSourceInfo *NewTInfo;
2981 CanQualType NewCanTy;
2982 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002983 NewTInfo = getDerived().TransformType(OldTInfo);
2984 if (!NewTInfo)
2985 return DeclarationNameInfo();
2986 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002987 }
2988 else {
2989 NewTInfo = 0;
2990 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002991 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002992 if (NewT.isNull())
2993 return DeclarationNameInfo();
2994 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2995 }
Mike Stump1eb44332009-09-09 15:08:12 +00002996
Abramo Bagnara25777432010-08-11 22:01:17 +00002997 DeclarationName NewName
2998 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2999 NewCanTy);
3000 DeclarationNameInfo NewNameInfo(NameInfo);
3001 NewNameInfo.setName(NewName);
3002 NewNameInfo.setNamedTypeInfo(NewTInfo);
3003 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00003004 }
Mike Stump1eb44332009-09-09 15:08:12 +00003005 }
3006
David Blaikieb219cfc2011-09-23 05:06:16 +00003007 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00003008}
3009
3010template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003011TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003012TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3013 TemplateName Name,
3014 SourceLocation NameLoc,
3015 QualType ObjectType,
3016 NamedDecl *FirstQualifierInScope) {
3017 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3018 TemplateDecl *Template = QTN->getTemplateDecl();
3019 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003020
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003021 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003022 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003023 Template));
3024 if (!TransTemplate)
3025 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003026
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003027 if (!getDerived().AlwaysRebuild() &&
3028 SS.getScopeRep() == QTN->getQualifier() &&
3029 TransTemplate == Template)
3030 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003031
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003032 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3033 TransTemplate);
3034 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003035
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003036 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3037 if (SS.getScopeRep()) {
3038 // These apply to the scope specifier, not the template.
3039 ObjectType = QualType();
3040 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003041 }
3042
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003043 if (!getDerived().AlwaysRebuild() &&
3044 SS.getScopeRep() == DTN->getQualifier() &&
3045 ObjectType.isNull())
3046 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003047
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003048 if (DTN->isIdentifier()) {
3049 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003050 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003051 NameLoc,
3052 ObjectType,
3053 FirstQualifierInScope);
3054 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003055
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003056 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3057 ObjectType);
3058 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003059
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003060 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3061 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003062 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003063 Template));
3064 if (!TransTemplate)
3065 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003066
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003067 if (!getDerived().AlwaysRebuild() &&
3068 TransTemplate == Template)
3069 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003070
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003071 return TemplateName(TransTemplate);
3072 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003073
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003074 if (SubstTemplateTemplateParmPackStorage *SubstPack
3075 = Name.getAsSubstTemplateTemplateParmPack()) {
3076 TemplateTemplateParmDecl *TransParam
3077 = cast_or_null<TemplateTemplateParmDecl>(
3078 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3079 if (!TransParam)
3080 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003081
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003082 if (!getDerived().AlwaysRebuild() &&
3083 TransParam == SubstPack->getParameterPack())
3084 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003085
3086 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003087 SubstPack->getArgumentPack());
3088 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003089
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003090 // These should be getting filtered out before they reach the AST.
3091 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003092}
3093
3094template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003095void TreeTransform<Derived>::InventTemplateArgumentLoc(
3096 const TemplateArgument &Arg,
3097 TemplateArgumentLoc &Output) {
3098 SourceLocation Loc = getDerived().getBaseLocation();
3099 switch (Arg.getKind()) {
3100 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003101 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00003102 break;
3103
3104 case TemplateArgument::Type:
3105 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00003106 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00003107
John McCall833ca992009-10-29 08:12:44 +00003108 break;
3109
Douglas Gregor788cd062009-11-11 01:00:40 +00003110 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003111 case TemplateArgument::TemplateExpansion: {
3112 NestedNameSpecifierLocBuilder Builder;
3113 TemplateName Template = Arg.getAsTemplate();
3114 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3115 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3116 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3117 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003118
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003119 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003120 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003121 Builder.getWithLocInContext(SemaRef.Context),
3122 Loc);
3123 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003124 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003125 Builder.getWithLocInContext(SemaRef.Context),
3126 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003127
Douglas Gregor788cd062009-11-11 01:00:40 +00003128 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003129 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003130
John McCall833ca992009-10-29 08:12:44 +00003131 case TemplateArgument::Expression:
3132 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3133 break;
3134
3135 case TemplateArgument::Declaration:
3136 case TemplateArgument::Integral:
3137 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003138 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003139 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003140 break;
3141 }
3142}
3143
3144template<typename Derived>
3145bool TreeTransform<Derived>::TransformTemplateArgument(
3146 const TemplateArgumentLoc &Input,
3147 TemplateArgumentLoc &Output) {
3148 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003149 switch (Arg.getKind()) {
3150 case TemplateArgument::Null:
3151 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003152 case TemplateArgument::Pack:
3153 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003154 case TemplateArgument::NullPtr:
3155 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003156
Douglas Gregor670444e2009-08-04 22:27:00 +00003157 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003158 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003159 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003160 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003161
3162 DI = getDerived().TransformType(DI);
3163 if (!DI) return true;
3164
3165 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3166 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003167 }
Mike Stump1eb44332009-09-09 15:08:12 +00003168
Douglas Gregor788cd062009-11-11 01:00:40 +00003169 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003170 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3171 if (QualifierLoc) {
3172 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3173 if (!QualifierLoc)
3174 return true;
3175 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003176
Douglas Gregor1d752d72011-03-02 18:46:51 +00003177 CXXScopeSpec SS;
3178 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003179 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003180 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3181 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003182 if (Template.isNull())
3183 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003184
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003185 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003186 Input.getTemplateNameLoc());
3187 return false;
3188 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003189
3190 case TemplateArgument::TemplateExpansion:
3191 llvm_unreachable("Caller should expand pack expansions");
3192
Douglas Gregor670444e2009-08-04 22:27:00 +00003193 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003194 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003195 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003196 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003197
John McCall833ca992009-10-29 08:12:44 +00003198 Expr *InputExpr = Input.getSourceExpression();
3199 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3200
Chris Lattner223de242011-04-25 20:37:58 +00003201 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003202 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003203 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003204 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003205 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003206 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003207 }
Mike Stump1eb44332009-09-09 15:08:12 +00003208
Douglas Gregor670444e2009-08-04 22:27:00 +00003209 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003210 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003211}
3212
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003213/// \brief Iterator adaptor that invents template argument location information
3214/// for each of the template arguments in its underlying iterator.
3215template<typename Derived, typename InputIterator>
3216class TemplateArgumentLocInventIterator {
3217 TreeTransform<Derived> &Self;
3218 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003219
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003220public:
3221 typedef TemplateArgumentLoc value_type;
3222 typedef TemplateArgumentLoc reference;
3223 typedef typename std::iterator_traits<InputIterator>::difference_type
3224 difference_type;
3225 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003226
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003227 class pointer {
3228 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003229
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003230 public:
3231 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003232
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003233 const TemplateArgumentLoc *operator->() const { return &Arg; }
3234 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003235
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003236 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003237
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003238 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3239 InputIterator Iter)
3240 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003241
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003242 TemplateArgumentLocInventIterator &operator++() {
3243 ++Iter;
3244 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003245 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003246
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003247 TemplateArgumentLocInventIterator operator++(int) {
3248 TemplateArgumentLocInventIterator Old(*this);
3249 ++(*this);
3250 return Old;
3251 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003252
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003253 reference operator*() const {
3254 TemplateArgumentLoc Result;
3255 Self.InventTemplateArgumentLoc(*Iter, Result);
3256 return Result;
3257 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003258
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003259 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003260
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003261 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3262 const TemplateArgumentLocInventIterator &Y) {
3263 return X.Iter == Y.Iter;
3264 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003265
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003266 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3267 const TemplateArgumentLocInventIterator &Y) {
3268 return X.Iter != Y.Iter;
3269 }
3270};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003271
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003272template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003273template<typename InputIterator>
3274bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3275 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003276 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003277 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003278 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003279 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003280
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003281 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3282 // Unpack argument packs, which we translate them into separate
3283 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003284 // FIXME: We could do much better if we could guarantee that the
3285 // TemplateArgumentLocInfo for the pack expansion would be usable for
3286 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003287 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003288 TemplateArgument::pack_iterator>
3289 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003290 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003291 In.getArgument().pack_begin()),
3292 PackLocIterator(*this,
3293 In.getArgument().pack_end()),
3294 Outputs))
3295 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003296
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003297 continue;
3298 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003299
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003300 if (In.getArgument().isPackExpansion()) {
3301 // We have a pack expansion, for which we will be substituting into
3302 // the pattern.
3303 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003304 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003305 TemplateArgumentLoc Pattern
Eli Friedman850cf512013-06-20 04:11:21 +00003306 = getSema().getTemplateArgumentPackExpansionPattern(
3307 In, Ellipsis, OrigNumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003308
Chris Lattner686775d2011-07-20 06:58:45 +00003309 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003310 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3311 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003312
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003313 // Determine whether the set of unexpanded parameter packs can and should
3314 // be expanded.
3315 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003316 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003317 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003318 if (getDerived().TryExpandParameterPacks(Ellipsis,
3319 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003320 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003321 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003322 RetainExpansion,
3323 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003324 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003325
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003326 if (!Expand) {
3327 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003328 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003329 // expansion.
3330 TemplateArgumentLoc OutPattern;
3331 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3332 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3333 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003334
Douglas Gregorcded4f62011-01-14 17:04:44 +00003335 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3336 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003337 if (Out.getArgument().isNull())
3338 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003339
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003340 Outputs.addArgument(Out);
3341 continue;
3342 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003343
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003344 // The transform has determined that we should perform an elementwise
3345 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003346 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003347 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3348
3349 if (getDerived().TransformTemplateArgument(Pattern, Out))
3350 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003351
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003352 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003353 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3354 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003355 if (Out.getArgument().isNull())
3356 return true;
3357 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003358
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003359 Outputs.addArgument(Out);
3360 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003361
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003362 // If we're supposed to retain a pack expansion, do so by temporarily
3363 // forgetting the partially-substituted parameter pack.
3364 if (RetainExpansion) {
3365 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003366
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003367 if (getDerived().TransformTemplateArgument(Pattern, Out))
3368 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003369
Douglas Gregorcded4f62011-01-14 17:04:44 +00003370 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3371 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003372 if (Out.getArgument().isNull())
3373 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003374
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003375 Outputs.addArgument(Out);
3376 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003377
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003378 continue;
3379 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003380
3381 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003382 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003383 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003384
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003385 Outputs.addArgument(Out);
3386 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003387
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003388 return false;
3389
3390}
3391
Douglas Gregor577f75a2009-08-04 16:50:30 +00003392//===----------------------------------------------------------------------===//
3393// Type transformation
3394//===----------------------------------------------------------------------===//
3395
3396template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003397QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003398 if (getDerived().AlreadyTransformed(T))
3399 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003400
John McCalla2becad2009-10-21 00:40:46 +00003401 // Temporary workaround. All of these transformations should
3402 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003403 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3404 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003405
John McCall43fed0d2010-11-12 08:19:04 +00003406 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003407
John McCalla2becad2009-10-21 00:40:46 +00003408 if (!NewDI)
3409 return QualType();
3410
3411 return NewDI->getType();
3412}
3413
3414template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003415TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003416 // Refine the base location to the type's location.
3417 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3418 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003419 if (getDerived().AlreadyTransformed(DI->getType()))
3420 return DI;
3421
3422 TypeLocBuilder TLB;
3423
3424 TypeLoc TL = DI->getTypeLoc();
3425 TLB.reserve(TL.getFullDataSize());
3426
John McCall43fed0d2010-11-12 08:19:04 +00003427 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003428 if (Result.isNull())
3429 return 0;
3430
John McCalla93c9342009-12-07 02:54:59 +00003431 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003432}
3433
3434template<typename Derived>
3435QualType
John McCall43fed0d2010-11-12 08:19:04 +00003436TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003437 switch (T.getTypeLocClass()) {
3438#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003439#define TYPELOC(CLASS, PARENT) \
3440 case TypeLoc::CLASS: \
3441 return getDerived().Transform##CLASS##Type(TLB, \
3442 T.castAs<CLASS##TypeLoc>());
John McCalla2becad2009-10-21 00:40:46 +00003443#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003444 }
Mike Stump1eb44332009-09-09 15:08:12 +00003445
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003446 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003447}
3448
3449/// FIXME: By default, this routine adds type qualifiers only to types
3450/// that can have qualifiers, and silently suppresses those qualifiers
3451/// that are not permitted (e.g., qualifiers on reference or function
3452/// types). This is the right thing for template instantiation, but
3453/// probably not for other clients.
3454template<typename Derived>
3455QualType
3456TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003457 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003458 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003459
John McCall43fed0d2010-11-12 08:19:04 +00003460 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003461 if (Result.isNull())
3462 return QualType();
3463
3464 // Silently suppress qualifiers if the result type can't be qualified.
3465 // FIXME: this is the right thing for template instantiation, but
3466 // probably not for other clients.
3467 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003468 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003469
John McCallf85e1932011-06-15 23:02:42 +00003470 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003471 // resulting type.
3472 if (Quals.hasObjCLifetime()) {
3473 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3474 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003475 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003476 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003477 // A lifetime qualifier applied to a substituted template parameter
3478 // overrides the lifetime qualifier from the template argument.
Douglas Gregor92d13872013-01-17 23:59:28 +00003479 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003480 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003481 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3482 QualType Replacement = SubstTypeParam->getReplacementType();
3483 Qualifiers Qs = Replacement.getQualifiers();
3484 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003485 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003486 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3487 Qs);
3488 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003489 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003490 Replacement);
3491 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003492 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3493 // 'auto' types behave the same way as template parameters.
3494 QualType Deduced = AutoTy->getDeducedType();
3495 Qualifiers Qs = Deduced.getQualifiers();
3496 Qs.removeObjCLifetime();
3497 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3498 Qs);
Faisal Valiecb58192013-08-22 01:49:11 +00003499 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3500 AutoTy->isDependentType(),
3501 AutoTy->containsUnexpandedParameterPack());
Douglas Gregor92d13872013-01-17 23:59:28 +00003502 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003503 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003504 // Otherwise, complain about the addition of a qualifier to an
3505 // already-qualified type.
Eli Friedman44ee0a72013-06-07 20:31:48 +00003506 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003507 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003508 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003509
Douglas Gregore559ca12011-06-17 22:11:49 +00003510 Quals.removeObjCLifetime();
3511 }
3512 }
3513 }
John McCall28654742010-06-05 06:41:15 +00003514 if (!Quals.empty()) {
3515 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smith9807a2e2013-03-27 23:36:39 +00003516 // BuildQualifiedType might not add qualifiers if they are invalid.
3517 if (Result.hasLocalQualifiers())
3518 TLB.push<QualifiedTypeLoc>(Result);
John McCall28654742010-06-05 06:41:15 +00003519 // No location information to preserve.
3520 }
John McCalla2becad2009-10-21 00:40:46 +00003521
3522 return Result;
3523}
3524
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003525template<typename Derived>
3526TypeLoc
3527TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3528 QualType ObjectType,
3529 NamedDecl *UnqualLookup,
3530 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003531 QualType T = TL.getType();
3532 if (getDerived().AlreadyTransformed(T))
3533 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003534
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003535 TypeLocBuilder TLB;
3536 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003537
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003538 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003539 TemplateSpecializationTypeLoc SpecTL =
3540 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003541
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003542 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003543 getDerived().TransformTemplateName(SS,
3544 SpecTL.getTypePtr()->getTemplateName(),
3545 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003546 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003547 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003548 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003549
3550 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003551 Template);
3552 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003553 DependentTemplateSpecializationTypeLoc SpecTL =
3554 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003555
Douglas Gregora88f09f2011-02-28 17:23:35 +00003556 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003557 = getDerived().RebuildTemplateName(SS,
3558 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003559 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003560 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003561 if (Template.isNull())
3562 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003563
3564 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003565 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003566 Template,
3567 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003568 } else {
3569 // Nothing special needs to be done for these.
3570 Result = getDerived().TransformType(TLB, TL);
3571 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003572
3573 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003574 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003575
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003576 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3577}
3578
Douglas Gregorb71d8212011-03-02 18:32:08 +00003579template<typename Derived>
3580TypeSourceInfo *
3581TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3582 QualType ObjectType,
3583 NamedDecl *UnqualLookup,
3584 CXXScopeSpec &SS) {
3585 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003586
Douglas Gregorb71d8212011-03-02 18:32:08 +00003587 QualType T = TSInfo->getType();
3588 if (getDerived().AlreadyTransformed(T))
3589 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003590
Douglas Gregorb71d8212011-03-02 18:32:08 +00003591 TypeLocBuilder TLB;
3592 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003593
Douglas Gregorb71d8212011-03-02 18:32:08 +00003594 TypeLoc TL = TSInfo->getTypeLoc();
3595 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003596 TemplateSpecializationTypeLoc SpecTL =
3597 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003598
Douglas Gregorb71d8212011-03-02 18:32:08 +00003599 TemplateName Template
3600 = getDerived().TransformTemplateName(SS,
3601 SpecTL.getTypePtr()->getTemplateName(),
3602 SpecTL.getTemplateNameLoc(),
3603 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003604 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003605 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003606
3607 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003608 Template);
3609 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003610 DependentTemplateSpecializationTypeLoc SpecTL =
3611 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003612
Douglas Gregorb71d8212011-03-02 18:32:08 +00003613 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003614 = getDerived().RebuildTemplateName(SS,
3615 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003616 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003617 ObjectType, UnqualLookup);
3618 if (Template.isNull())
3619 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003620
3621 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003622 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003623 Template,
3624 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003625 } else {
3626 // Nothing special needs to be done for these.
3627 Result = getDerived().TransformType(TLB, TL);
3628 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003629
3630 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003631 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003632
Douglas Gregorb71d8212011-03-02 18:32:08 +00003633 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3634}
3635
John McCalla2becad2009-10-21 00:40:46 +00003636template <class TyLoc> static inline
3637QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3638 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3639 NewT.setNameLoc(T.getNameLoc());
3640 return T.getType();
3641}
3642
John McCalla2becad2009-10-21 00:40:46 +00003643template<typename Derived>
3644QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003645 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003646 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3647 NewT.setBuiltinLoc(T.getBuiltinLoc());
3648 if (T.needsExtraLocalData())
3649 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3650 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003651}
Mike Stump1eb44332009-09-09 15:08:12 +00003652
Douglas Gregor577f75a2009-08-04 16:50:30 +00003653template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003654QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003655 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003656 // FIXME: recurse?
3657 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003658}
Mike Stump1eb44332009-09-09 15:08:12 +00003659
Douglas Gregor577f75a2009-08-04 16:50:30 +00003660template<typename Derived>
Reid Kleckner12df2462013-06-24 17:51:48 +00003661QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3662 DecayedTypeLoc TL) {
3663 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3664 if (OriginalType.isNull())
3665 return QualType();
3666
3667 QualType Result = TL.getType();
3668 if (getDerived().AlwaysRebuild() ||
3669 OriginalType != TL.getOriginalLoc().getType())
3670 Result = SemaRef.Context.getDecayedType(OriginalType);
3671 TLB.push<DecayedTypeLoc>(Result);
3672 // Nothing to set for DecayedTypeLoc.
3673 return Result;
3674}
3675
3676template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003677QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003678 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003679 QualType PointeeType
3680 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003681 if (PointeeType.isNull())
3682 return QualType();
3683
3684 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003685 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003686 // A dependent pointer type 'T *' has is being transformed such
3687 // that an Objective-C class type is being replaced for 'T'. The
3688 // resulting pointer type is an ObjCObjectPointerType, not a
3689 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003690 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003691
John McCallc12c5bb2010-05-15 11:32:37 +00003692 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3693 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003694 return Result;
3695 }
John McCall43fed0d2010-11-12 08:19:04 +00003696
Douglas Gregor92e986e2010-04-22 16:44:27 +00003697 if (getDerived().AlwaysRebuild() ||
3698 PointeeType != TL.getPointeeLoc().getType()) {
3699 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3700 if (Result.isNull())
3701 return QualType();
3702 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003703
John McCallf85e1932011-06-15 23:02:42 +00003704 // Objective-C ARC can add lifetime qualifiers to the type that we're
3705 // pointing to.
3706 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003707
Douglas Gregor92e986e2010-04-22 16:44:27 +00003708 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3709 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003710 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003711}
Mike Stump1eb44332009-09-09 15:08:12 +00003712
3713template<typename Derived>
3714QualType
John McCalla2becad2009-10-21 00:40:46 +00003715TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003716 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003717 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003718 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3719 if (PointeeType.isNull())
3720 return QualType();
3721
3722 QualType Result = TL.getType();
3723 if (getDerived().AlwaysRebuild() ||
3724 PointeeType != TL.getPointeeLoc().getType()) {
3725 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003726 TL.getSigilLoc());
3727 if (Result.isNull())
3728 return QualType();
3729 }
3730
Douglas Gregor39968ad2010-04-22 16:50:51 +00003731 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003732 NewT.setSigilLoc(TL.getSigilLoc());
3733 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003734}
3735
John McCall85737a72009-10-30 00:06:24 +00003736/// Transforms a reference type. Note that somewhat paradoxically we
3737/// don't care whether the type itself is an l-value type or an r-value
3738/// type; we only care if the type was *written* as an l-value type
3739/// or an r-value type.
3740template<typename Derived>
3741QualType
3742TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003743 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003744 const ReferenceType *T = TL.getTypePtr();
3745
3746 // Note that this works with the pointee-as-written.
3747 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3748 if (PointeeType.isNull())
3749 return QualType();
3750
3751 QualType Result = TL.getType();
3752 if (getDerived().AlwaysRebuild() ||
3753 PointeeType != T->getPointeeTypeAsWritten()) {
3754 Result = getDerived().RebuildReferenceType(PointeeType,
3755 T->isSpelledAsLValue(),
3756 TL.getSigilLoc());
3757 if (Result.isNull())
3758 return QualType();
3759 }
3760
John McCallf85e1932011-06-15 23:02:42 +00003761 // Objective-C ARC can add lifetime qualifiers to the type that we're
3762 // referring to.
3763 TLB.TypeWasModifiedSafely(
3764 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3765
John McCall85737a72009-10-30 00:06:24 +00003766 // r-value references can be rebuilt as l-value references.
3767 ReferenceTypeLoc NewTL;
3768 if (isa<LValueReferenceType>(Result))
3769 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3770 else
3771 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3772 NewTL.setSigilLoc(TL.getSigilLoc());
3773
3774 return Result;
3775}
3776
Mike Stump1eb44332009-09-09 15:08:12 +00003777template<typename Derived>
3778QualType
John McCalla2becad2009-10-21 00:40:46 +00003779TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003780 LValueReferenceTypeLoc TL) {
3781 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003782}
3783
Mike Stump1eb44332009-09-09 15:08:12 +00003784template<typename Derived>
3785QualType
John McCalla2becad2009-10-21 00:40:46 +00003786TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003787 RValueReferenceTypeLoc TL) {
3788 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003789}
Mike Stump1eb44332009-09-09 15:08:12 +00003790
Douglas Gregor577f75a2009-08-04 16:50:30 +00003791template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003792QualType
John McCalla2becad2009-10-21 00:40:46 +00003793TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003794 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003795 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003796 if (PointeeType.isNull())
3797 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003798
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003799 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3800 TypeSourceInfo* NewClsTInfo = 0;
3801 if (OldClsTInfo) {
3802 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3803 if (!NewClsTInfo)
3804 return QualType();
3805 }
3806
3807 const MemberPointerType *T = TL.getTypePtr();
3808 QualType OldClsType = QualType(T->getClass(), 0);
3809 QualType NewClsType;
3810 if (NewClsTInfo)
3811 NewClsType = NewClsTInfo->getType();
3812 else {
3813 NewClsType = getDerived().TransformType(OldClsType);
3814 if (NewClsType.isNull())
3815 return QualType();
3816 }
Mike Stump1eb44332009-09-09 15:08:12 +00003817
John McCalla2becad2009-10-21 00:40:46 +00003818 QualType Result = TL.getType();
3819 if (getDerived().AlwaysRebuild() ||
3820 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003821 NewClsType != OldClsType) {
3822 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003823 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003824 if (Result.isNull())
3825 return QualType();
3826 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003827
John McCalla2becad2009-10-21 00:40:46 +00003828 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3829 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003830 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003831
3832 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003833}
3834
Mike Stump1eb44332009-09-09 15:08:12 +00003835template<typename Derived>
3836QualType
John McCalla2becad2009-10-21 00:40:46 +00003837TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003838 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003839 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003840 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003841 if (ElementType.isNull())
3842 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003843
John McCalla2becad2009-10-21 00:40:46 +00003844 QualType Result = TL.getType();
3845 if (getDerived().AlwaysRebuild() ||
3846 ElementType != T->getElementType()) {
3847 Result = getDerived().RebuildConstantArrayType(ElementType,
3848 T->getSizeModifier(),
3849 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003850 T->getIndexTypeCVRQualifiers(),
3851 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003852 if (Result.isNull())
3853 return QualType();
3854 }
Eli Friedman457a3772012-01-25 22:19:07 +00003855
3856 // We might have either a ConstantArrayType or a VariableArrayType now:
3857 // a ConstantArrayType is allowed to have an element type which is a
3858 // VariableArrayType if the type is dependent. Fortunately, all array
3859 // types have the same location layout.
3860 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003861 NewTL.setLBracketLoc(TL.getLBracketLoc());
3862 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003863
John McCalla2becad2009-10-21 00:40:46 +00003864 Expr *Size = TL.getSizeExpr();
3865 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003866 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3867 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003868 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003869 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003870 }
3871 NewTL.setSizeExpr(Size);
3872
3873 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003874}
Mike Stump1eb44332009-09-09 15:08:12 +00003875
Douglas Gregor577f75a2009-08-04 16:50:30 +00003876template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003877QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003878 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003879 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003880 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003881 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003882 if (ElementType.isNull())
3883 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003884
John McCalla2becad2009-10-21 00:40:46 +00003885 QualType Result = TL.getType();
3886 if (getDerived().AlwaysRebuild() ||
3887 ElementType != T->getElementType()) {
3888 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003889 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003890 T->getIndexTypeCVRQualifiers(),
3891 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003892 if (Result.isNull())
3893 return QualType();
3894 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003895
John McCalla2becad2009-10-21 00:40:46 +00003896 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3897 NewTL.setLBracketLoc(TL.getLBracketLoc());
3898 NewTL.setRBracketLoc(TL.getRBracketLoc());
3899 NewTL.setSizeExpr(0);
3900
3901 return Result;
3902}
3903
3904template<typename Derived>
3905QualType
3906TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003907 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003908 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003909 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3910 if (ElementType.isNull())
3911 return QualType();
3912
John McCall60d7b3a2010-08-24 06:29:42 +00003913 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003914 = getDerived().TransformExpr(T->getSizeExpr());
3915 if (SizeResult.isInvalid())
3916 return QualType();
3917
John McCall9ae2f072010-08-23 23:25:46 +00003918 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003919
3920 QualType Result = TL.getType();
3921 if (getDerived().AlwaysRebuild() ||
3922 ElementType != T->getElementType() ||
3923 Size != T->getSizeExpr()) {
3924 Result = getDerived().RebuildVariableArrayType(ElementType,
3925 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003926 Size,
John McCalla2becad2009-10-21 00:40:46 +00003927 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003928 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003929 if (Result.isNull())
3930 return QualType();
3931 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003932
John McCalla2becad2009-10-21 00:40:46 +00003933 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3934 NewTL.setLBracketLoc(TL.getLBracketLoc());
3935 NewTL.setRBracketLoc(TL.getRBracketLoc());
3936 NewTL.setSizeExpr(Size);
3937
3938 return Result;
3939}
3940
3941template<typename Derived>
3942QualType
3943TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003944 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003945 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003946 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3947 if (ElementType.isNull())
3948 return QualType();
3949
Richard Smithf6702a32011-12-20 02:08:33 +00003950 // Array bounds are constant expressions.
3951 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3952 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003953
John McCall3b657512011-01-19 10:06:00 +00003954 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3955 Expr *origSize = TL.getSizeExpr();
3956 if (!origSize) origSize = T->getSizeExpr();
3957
3958 ExprResult sizeResult
3959 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003960 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003961 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003962 return QualType();
3963
John McCall3b657512011-01-19 10:06:00 +00003964 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003965
3966 QualType Result = TL.getType();
3967 if (getDerived().AlwaysRebuild() ||
3968 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003969 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003970 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3971 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003972 size,
John McCalla2becad2009-10-21 00:40:46 +00003973 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003974 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003975 if (Result.isNull())
3976 return QualType();
3977 }
John McCalla2becad2009-10-21 00:40:46 +00003978
3979 // We might have any sort of array type now, but fortunately they
3980 // all have the same location layout.
3981 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3982 NewTL.setLBracketLoc(TL.getLBracketLoc());
3983 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003984 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003985
3986 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003987}
Mike Stump1eb44332009-09-09 15:08:12 +00003988
3989template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003990QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003991 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003992 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003993 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003994
3995 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003996 QualType ElementType = getDerived().TransformType(T->getElementType());
3997 if (ElementType.isNull())
3998 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003999
Richard Smithf6702a32011-12-20 02:08:33 +00004000 // Vector sizes are constant expressions.
4001 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4002 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00004003
John McCall60d7b3a2010-08-24 06:29:42 +00004004 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00004005 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004006 if (Size.isInvalid())
4007 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004008
John McCalla2becad2009-10-21 00:40:46 +00004009 QualType Result = TL.getType();
4010 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00004011 ElementType != T->getElementType() ||
4012 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00004013 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00004014 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00004015 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00004016 if (Result.isNull())
4017 return QualType();
4018 }
John McCalla2becad2009-10-21 00:40:46 +00004019
4020 // Result might be dependent or not.
4021 if (isa<DependentSizedExtVectorType>(Result)) {
4022 DependentSizedExtVectorTypeLoc NewTL
4023 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4024 NewTL.setNameLoc(TL.getNameLoc());
4025 } else {
4026 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4027 NewTL.setNameLoc(TL.getNameLoc());
4028 }
4029
4030 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004031}
Mike Stump1eb44332009-09-09 15:08:12 +00004032
4033template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004034QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004035 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004036 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004037 QualType ElementType = getDerived().TransformType(T->getElementType());
4038 if (ElementType.isNull())
4039 return QualType();
4040
John McCalla2becad2009-10-21 00:40:46 +00004041 QualType Result = TL.getType();
4042 if (getDerived().AlwaysRebuild() ||
4043 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00004044 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00004045 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00004046 if (Result.isNull())
4047 return QualType();
4048 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004049
John McCalla2becad2009-10-21 00:40:46 +00004050 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4051 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00004052
John McCalla2becad2009-10-21 00:40:46 +00004053 return Result;
4054}
4055
4056template<typename Derived>
4057QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004058 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004059 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004060 QualType ElementType = getDerived().TransformType(T->getElementType());
4061 if (ElementType.isNull())
4062 return QualType();
4063
4064 QualType Result = TL.getType();
4065 if (getDerived().AlwaysRebuild() ||
4066 ElementType != T->getElementType()) {
4067 Result = getDerived().RebuildExtVectorType(ElementType,
4068 T->getNumElements(),
4069 /*FIXME*/ SourceLocation());
4070 if (Result.isNull())
4071 return QualType();
4072 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004073
John McCalla2becad2009-10-21 00:40:46 +00004074 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4075 NewTL.setNameLoc(TL.getNameLoc());
4076
4077 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004078}
Mike Stump1eb44332009-09-09 15:08:12 +00004079
David Blaikiedc84cd52013-02-20 22:23:23 +00004080template <typename Derived>
4081ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4082 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4083 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00004084 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004085 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004086
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004087 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004088 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004089 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004090 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004091 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004092
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004093 TypeLocBuilder TLB;
4094 TypeLoc NewTL = OldDI->getTypeLoc();
4095 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004096
4097 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004098 OldExpansionTL.getPatternLoc());
4099 if (Result.isNull())
4100 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004101
4102 Result = RebuildPackExpansionType(Result,
4103 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004104 OldExpansionTL.getEllipsisLoc(),
4105 NumExpansions);
4106 if (Result.isNull())
4107 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004108
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004109 PackExpansionTypeLoc NewExpansionTL
4110 = TLB.push<PackExpansionTypeLoc>(Result);
4111 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4112 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4113 } else
4114 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00004115 if (!NewDI)
4116 return 0;
4117
John McCallfb44de92011-05-01 22:35:37 +00004118 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00004119 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00004120
4121 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4122 OldParm->getDeclContext(),
4123 OldParm->getInnerLocStart(),
4124 OldParm->getLocation(),
4125 OldParm->getIdentifier(),
4126 NewDI->getType(),
4127 NewDI,
4128 OldParm->getStorageClass(),
John McCallfb44de92011-05-01 22:35:37 +00004129 /* DefArg */ NULL);
4130 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4131 OldParm->getFunctionScopeIndex() + indexAdjustment);
4132 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004133}
4134
4135template<typename Derived>
4136bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004137 TransformFunctionTypeParams(SourceLocation Loc,
4138 ParmVarDecl **Params, unsigned NumParams,
4139 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004140 SmallVectorImpl<QualType> &OutParamTypes,
4141 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004142 int indexAdjustment = 0;
4143
Douglas Gregora009b592011-01-07 00:20:55 +00004144 for (unsigned i = 0; i != NumParams; ++i) {
4145 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004146 assert(OldParm->getFunctionScopeIndex() == i);
4147
David Blaikiedc84cd52013-02-20 22:23:23 +00004148 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004149 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004150 if (OldParm->isParameterPack()) {
4151 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004152 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004153
Douglas Gregor603cfb42011-01-05 23:12:31 +00004154 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004155 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004156 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004157 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4158 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004159 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4160
Douglas Gregor603cfb42011-01-05 23:12:31 +00004161 // Determine whether we should expand the parameter packs.
4162 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004163 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004164 Optional<unsigned> OrigNumExpansions =
4165 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004166 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004167 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4168 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004169 Unexpanded,
4170 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004171 RetainExpansion,
4172 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004173 return true;
4174 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004175
Douglas Gregor603cfb42011-01-05 23:12:31 +00004176 if (ShouldExpand) {
4177 // Expand the function parameter pack into multiple, separate
4178 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004179 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004180 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004181 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004182 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004183 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004184 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004185 OrigNumExpansions,
4186 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004187 if (!NewParm)
4188 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004189
Douglas Gregora009b592011-01-07 00:20:55 +00004190 OutParamTypes.push_back(NewParm->getType());
4191 if (PVars)
4192 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004193 }
Douglas Gregord3731192011-01-10 07:32:04 +00004194
4195 // If we're supposed to retain a pack expansion, do so by temporarily
4196 // forgetting the partially-substituted parameter pack.
4197 if (RetainExpansion) {
4198 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004199 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004200 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004201 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004202 OrigNumExpansions,
4203 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004204 if (!NewParm)
4205 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004206
Douglas Gregord3731192011-01-10 07:32:04 +00004207 OutParamTypes.push_back(NewParm->getType());
4208 if (PVars)
4209 PVars->push_back(NewParm);
4210 }
4211
John McCallfb44de92011-05-01 22:35:37 +00004212 // The next parameter should have the same adjustment as the
4213 // last thing we pushed, but we post-incremented indexAdjustment
4214 // on every push. Also, if we push nothing, the adjustment should
4215 // go down by one.
4216 indexAdjustment--;
4217
Douglas Gregor603cfb42011-01-05 23:12:31 +00004218 // We're done with the pack expansion.
4219 continue;
4220 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004221
4222 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004223 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004224 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4225 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004226 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004227 NumExpansions,
4228 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004229 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004230 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004231 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004232 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004233
John McCall21ef0fa2010-03-11 09:03:00 +00004234 if (!NewParm)
4235 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004236
Douglas Gregora009b592011-01-07 00:20:55 +00004237 OutParamTypes.push_back(NewParm->getType());
4238 if (PVars)
4239 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004240 continue;
4241 }
John McCall21ef0fa2010-03-11 09:03:00 +00004242
4243 // Deal with the possibility that we don't have a parameter
4244 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004245 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004246 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004247 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004248 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004249 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004250 = dyn_cast<PackExpansionType>(OldType)) {
4251 // We have a function parameter pack that may need to be expanded.
4252 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004253 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004254 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004255
Douglas Gregor603cfb42011-01-05 23:12:31 +00004256 // Determine whether we should expand the parameter packs.
4257 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004258 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004259 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004260 Unexpanded,
4261 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004262 RetainExpansion,
4263 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004264 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004265 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004266
Douglas Gregor603cfb42011-01-05 23:12:31 +00004267 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004268 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004269 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004270 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004271 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4272 QualType NewType = getDerived().TransformType(Pattern);
4273 if (NewType.isNull())
4274 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004275
Douglas Gregora009b592011-01-07 00:20:55 +00004276 OutParamTypes.push_back(NewType);
4277 if (PVars)
4278 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004279 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004280
Douglas Gregor603cfb42011-01-05 23:12:31 +00004281 // We're done with the pack expansion.
4282 continue;
4283 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004284
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004285 // If we're supposed to retain a pack expansion, do so by temporarily
4286 // forgetting the partially-substituted parameter pack.
4287 if (RetainExpansion) {
4288 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4289 QualType NewType = getDerived().TransformType(Pattern);
4290 if (NewType.isNull())
4291 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004292
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004293 OutParamTypes.push_back(NewType);
4294 if (PVars)
4295 PVars->push_back(0);
4296 }
Douglas Gregord3731192011-01-10 07:32:04 +00004297
Chad Rosier4a9d7952012-08-08 18:46:20 +00004298 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004299 // expansion.
4300 OldType = Expansion->getPattern();
4301 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004302 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4303 NewType = getDerived().TransformType(OldType);
4304 } else {
4305 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004306 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004307
Douglas Gregor603cfb42011-01-05 23:12:31 +00004308 if (NewType.isNull())
4309 return true;
4310
4311 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004312 NewType = getSema().Context.getPackExpansionType(NewType,
4313 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004314
Douglas Gregora009b592011-01-07 00:20:55 +00004315 OutParamTypes.push_back(NewType);
4316 if (PVars)
4317 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004318 }
4319
John McCallfb44de92011-05-01 22:35:37 +00004320#ifndef NDEBUG
4321 if (PVars) {
4322 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4323 if (ParmVarDecl *parm = (*PVars)[i])
4324 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004325 }
John McCallfb44de92011-05-01 22:35:37 +00004326#endif
4327
4328 return false;
4329}
John McCall21ef0fa2010-03-11 09:03:00 +00004330
4331template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004332QualType
John McCalla2becad2009-10-21 00:40:46 +00004333TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004334 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004335 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4336}
4337
4338template<typename Derived>
4339QualType
4340TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4341 FunctionProtoTypeLoc TL,
4342 CXXRecordDecl *ThisContext,
4343 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004344 // Transform the parameters and return type.
4345 //
Richard Smithe6975e92012-04-17 00:58:00 +00004346 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004347 // When the function has a trailing return type, we instantiate the
4348 // parameters before the return type, since the return type can then refer
4349 // to the parameters themselves (via decltype, sizeof, etc.).
4350 //
Chris Lattner686775d2011-07-20 06:58:45 +00004351 SmallVector<QualType, 4> ParamTypes;
4352 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004353 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004354
Douglas Gregordab60ad2010-10-01 18:44:50 +00004355 QualType ResultType;
4356
Richard Smith9fbf3272012-08-14 22:51:13 +00004357 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004358 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004359 TL.getParmArray(),
4360 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004361 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004362 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004363 return QualType();
4364
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004365 {
4366 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004367 // If a declaration declares a member function or member function
4368 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004369 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004370 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004371 // declarator.
4372 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004373
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004374 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4375 if (ResultType.isNull())
4376 return QualType();
4377 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004378 }
4379 else {
4380 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4381 if (ResultType.isNull())
4382 return QualType();
4383
Chad Rosier4a9d7952012-08-08 18:46:20 +00004384 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004385 TL.getParmArray(),
4386 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004387 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004388 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004389 return QualType();
4390 }
4391
Richard Smithe6975e92012-04-17 00:58:00 +00004392 // FIXME: Need to transform the exception-specification too.
4393
John McCalla2becad2009-10-21 00:40:46 +00004394 QualType Result = TL.getType();
4395 if (getDerived().AlwaysRebuild() ||
4396 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004397 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004398 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004399 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004400 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004401 if (Result.isNull())
4402 return QualType();
4403 }
Mike Stump1eb44332009-09-09 15:08:12 +00004404
John McCalla2becad2009-10-21 00:40:46 +00004405 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004406 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004407 NewTL.setLParenLoc(TL.getLParenLoc());
4408 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004409 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004410 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4411 NewTL.setArg(i, ParamDecls[i]);
4412
4413 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004414}
Mike Stump1eb44332009-09-09 15:08:12 +00004415
Douglas Gregor577f75a2009-08-04 16:50:30 +00004416template<typename Derived>
4417QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004418 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004419 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004420 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004421 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4422 if (ResultType.isNull())
4423 return QualType();
4424
4425 QualType Result = TL.getType();
4426 if (getDerived().AlwaysRebuild() ||
4427 ResultType != T->getResultType())
4428 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4429
4430 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004431 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004432 NewTL.setLParenLoc(TL.getLParenLoc());
4433 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004434 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004435
4436 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004437}
Mike Stump1eb44332009-09-09 15:08:12 +00004438
John McCalled976492009-12-04 22:46:56 +00004439template<typename Derived> QualType
4440TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004441 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004442 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004443 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004444 if (!D)
4445 return QualType();
4446
4447 QualType Result = TL.getType();
4448 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4449 Result = getDerived().RebuildUnresolvedUsingType(D);
4450 if (Result.isNull())
4451 return QualType();
4452 }
4453
4454 // We might get an arbitrary type spec type back. We should at
4455 // least always get a type spec type, though.
4456 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4457 NewTL.setNameLoc(TL.getNameLoc());
4458
4459 return Result;
4460}
4461
Douglas Gregor577f75a2009-08-04 16:50:30 +00004462template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004463QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004464 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004465 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004466 TypedefNameDecl *Typedef
4467 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4468 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004469 if (!Typedef)
4470 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004471
John McCalla2becad2009-10-21 00:40:46 +00004472 QualType Result = TL.getType();
4473 if (getDerived().AlwaysRebuild() ||
4474 Typedef != T->getDecl()) {
4475 Result = getDerived().RebuildTypedefType(Typedef);
4476 if (Result.isNull())
4477 return QualType();
4478 }
Mike Stump1eb44332009-09-09 15:08:12 +00004479
John McCalla2becad2009-10-21 00:40:46 +00004480 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4481 NewTL.setNameLoc(TL.getNameLoc());
4482
4483 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004484}
Mike Stump1eb44332009-09-09 15:08:12 +00004485
Douglas Gregor577f75a2009-08-04 16:50:30 +00004486template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004487QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004488 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004489 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004490 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4491 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004492
John McCall60d7b3a2010-08-24 06:29:42 +00004493 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004494 if (E.isInvalid())
4495 return QualType();
4496
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004497 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4498 if (E.isInvalid())
4499 return QualType();
4500
John McCalla2becad2009-10-21 00:40:46 +00004501 QualType Result = TL.getType();
4502 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004503 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004504 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004505 if (Result.isNull())
4506 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004507 }
John McCalla2becad2009-10-21 00:40:46 +00004508 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004509
John McCalla2becad2009-10-21 00:40:46 +00004510 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004511 NewTL.setTypeofLoc(TL.getTypeofLoc());
4512 NewTL.setLParenLoc(TL.getLParenLoc());
4513 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004514
4515 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004516}
Mike Stump1eb44332009-09-09 15:08:12 +00004517
4518template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004519QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004520 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004521 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4522 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4523 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004524 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004525
John McCalla2becad2009-10-21 00:40:46 +00004526 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004527 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4528 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004529 if (Result.isNull())
4530 return QualType();
4531 }
Mike Stump1eb44332009-09-09 15:08:12 +00004532
John McCalla2becad2009-10-21 00:40:46 +00004533 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004534 NewTL.setTypeofLoc(TL.getTypeofLoc());
4535 NewTL.setLParenLoc(TL.getLParenLoc());
4536 NewTL.setRParenLoc(TL.getRParenLoc());
4537 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004538
4539 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004540}
Mike Stump1eb44332009-09-09 15:08:12 +00004541
4542template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004543QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004544 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004545 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004546
Douglas Gregor670444e2009-08-04 22:27:00 +00004547 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004548 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4549 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004550
John McCall60d7b3a2010-08-24 06:29:42 +00004551 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004552 if (E.isInvalid())
4553 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004554
Richard Smith76f3f692012-02-22 02:04:18 +00004555 E = getSema().ActOnDecltypeExpression(E.take());
4556 if (E.isInvalid())
4557 return QualType();
4558
John McCalla2becad2009-10-21 00:40:46 +00004559 QualType Result = TL.getType();
4560 if (getDerived().AlwaysRebuild() ||
4561 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004562 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004563 if (Result.isNull())
4564 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004565 }
John McCalla2becad2009-10-21 00:40:46 +00004566 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004567
John McCalla2becad2009-10-21 00:40:46 +00004568 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4569 NewTL.setNameLoc(TL.getNameLoc());
4570
4571 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004572}
4573
4574template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004575QualType TreeTransform<Derived>::TransformUnaryTransformType(
4576 TypeLocBuilder &TLB,
4577 UnaryTransformTypeLoc TL) {
4578 QualType Result = TL.getType();
4579 if (Result->isDependentType()) {
4580 const UnaryTransformType *T = TL.getTypePtr();
4581 QualType NewBase =
4582 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4583 Result = getDerived().RebuildUnaryTransformType(NewBase,
4584 T->getUTTKind(),
4585 TL.getKWLoc());
4586 if (Result.isNull())
4587 return QualType();
4588 }
4589
4590 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4591 NewTL.setKWLoc(TL.getKWLoc());
4592 NewTL.setParensRange(TL.getParensRange());
4593 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4594 return Result;
4595}
4596
4597template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004598QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4599 AutoTypeLoc TL) {
4600 const AutoType *T = TL.getTypePtr();
4601 QualType OldDeduced = T->getDeducedType();
4602 QualType NewDeduced;
4603 if (!OldDeduced.isNull()) {
4604 NewDeduced = getDerived().TransformType(OldDeduced);
4605 if (NewDeduced.isNull())
4606 return QualType();
4607 }
4608
4609 QualType Result = TL.getType();
Richard Smithdc7a4f52013-04-30 13:56:41 +00004610 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4611 T->isDependentType()) {
Richard Smitha2c36462013-04-26 16:15:35 +00004612 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith34b41d92011-02-20 03:19:35 +00004613 if (Result.isNull())
4614 return QualType();
4615 }
4616
4617 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4618 NewTL.setNameLoc(TL.getNameLoc());
4619
4620 return Result;
4621}
4622
4623template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004624QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004625 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004626 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004627 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004628 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4629 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004630 if (!Record)
4631 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004632
John McCalla2becad2009-10-21 00:40:46 +00004633 QualType Result = TL.getType();
4634 if (getDerived().AlwaysRebuild() ||
4635 Record != T->getDecl()) {
4636 Result = getDerived().RebuildRecordType(Record);
4637 if (Result.isNull())
4638 return QualType();
4639 }
Mike Stump1eb44332009-09-09 15:08:12 +00004640
John McCalla2becad2009-10-21 00:40:46 +00004641 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4642 NewTL.setNameLoc(TL.getNameLoc());
4643
4644 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004645}
Mike Stump1eb44332009-09-09 15:08:12 +00004646
4647template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004648QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004649 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004650 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004651 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004652 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4653 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004654 if (!Enum)
4655 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004656
John McCalla2becad2009-10-21 00:40:46 +00004657 QualType Result = TL.getType();
4658 if (getDerived().AlwaysRebuild() ||
4659 Enum != T->getDecl()) {
4660 Result = getDerived().RebuildEnumType(Enum);
4661 if (Result.isNull())
4662 return QualType();
4663 }
Mike Stump1eb44332009-09-09 15:08:12 +00004664
John McCalla2becad2009-10-21 00:40:46 +00004665 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4666 NewTL.setNameLoc(TL.getNameLoc());
4667
4668 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004669}
John McCall7da24312009-09-05 00:15:47 +00004670
John McCall3cb0ebd2010-03-10 03:28:59 +00004671template<typename Derived>
4672QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4673 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004674 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004675 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4676 TL.getTypePtr()->getDecl());
4677 if (!D) return QualType();
4678
4679 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4680 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4681 return T;
4682}
4683
Douglas Gregor577f75a2009-08-04 16:50:30 +00004684template<typename Derived>
4685QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004686 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004687 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004688 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004689}
4690
Mike Stump1eb44332009-09-09 15:08:12 +00004691template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004692QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004693 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004694 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004695 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004696
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004697 // Substitute into the replacement type, which itself might involve something
4698 // that needs to be transformed. This only tends to occur with default
4699 // template arguments of template template parameters.
4700 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4701 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4702 if (Replacement.isNull())
4703 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004704
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004705 // Always canonicalize the replacement type.
4706 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4707 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004708 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004709 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004710
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004711 // Propagate type-source information.
4712 SubstTemplateTypeParmTypeLoc NewTL
4713 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4714 NewTL.setNameLoc(TL.getNameLoc());
4715 return Result;
4716
John McCall49a832b2009-10-18 09:09:24 +00004717}
4718
4719template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004720QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4721 TypeLocBuilder &TLB,
4722 SubstTemplateTypeParmPackTypeLoc TL) {
4723 return TransformTypeSpecType(TLB, TL);
4724}
4725
4726template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004727QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004728 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004729 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004730 const TemplateSpecializationType *T = TL.getTypePtr();
4731
Douglas Gregor1d752d72011-03-02 18:46:51 +00004732 // The nested-name-specifier never matters in a TemplateSpecializationType,
4733 // because we can't have a dependent nested-name-specifier anyway.
4734 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004735 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004736 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4737 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004738 if (Template.isNull())
4739 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004740
John McCall43fed0d2010-11-12 08:19:04 +00004741 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4742}
4743
Eli Friedmanb001de72011-10-06 23:00:33 +00004744template<typename Derived>
4745QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4746 AtomicTypeLoc TL) {
4747 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4748 if (ValueType.isNull())
4749 return QualType();
4750
4751 QualType Result = TL.getType();
4752 if (getDerived().AlwaysRebuild() ||
4753 ValueType != TL.getValueLoc().getType()) {
4754 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4755 if (Result.isNull())
4756 return QualType();
4757 }
4758
4759 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4760 NewTL.setKWLoc(TL.getKWLoc());
4761 NewTL.setLParenLoc(TL.getLParenLoc());
4762 NewTL.setRParenLoc(TL.getRParenLoc());
4763
4764 return Result;
4765}
4766
Chad Rosier4a9d7952012-08-08 18:46:20 +00004767 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004768 /// container that provides a \c getArgLoc() member function.
4769 ///
4770 /// This iterator is intended to be used with the iterator form of
4771 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4772 template<typename ArgLocContainer>
4773 class TemplateArgumentLocContainerIterator {
4774 ArgLocContainer *Container;
4775 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004776
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004777 public:
4778 typedef TemplateArgumentLoc value_type;
4779 typedef TemplateArgumentLoc reference;
4780 typedef int difference_type;
4781 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004782
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004783 class pointer {
4784 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004785
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004786 public:
4787 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004788
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004789 const TemplateArgumentLoc *operator->() const {
4790 return &Arg;
4791 }
4792 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004793
4794
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004795 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004796
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004797 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4798 unsigned Index)
4799 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004800
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004801 TemplateArgumentLocContainerIterator &operator++() {
4802 ++Index;
4803 return *this;
4804 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004805
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004806 TemplateArgumentLocContainerIterator operator++(int) {
4807 TemplateArgumentLocContainerIterator Old(*this);
4808 ++(*this);
4809 return Old;
4810 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004811
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004812 TemplateArgumentLoc operator*() const {
4813 return Container->getArgLoc(Index);
4814 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004815
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004816 pointer operator->() const {
4817 return pointer(Container->getArgLoc(Index));
4818 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004819
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004820 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004821 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004822 return X.Container == Y.Container && X.Index == Y.Index;
4823 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004824
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004825 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004826 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004827 return !(X == Y);
4828 }
4829 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004830
4831
John McCall43fed0d2010-11-12 08:19:04 +00004832template <typename Derived>
4833QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4834 TypeLocBuilder &TLB,
4835 TemplateSpecializationTypeLoc TL,
4836 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004837 TemplateArgumentListInfo NewTemplateArgs;
4838 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4839 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004840 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4841 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004842 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004843 ArgIterator(TL, TL.getNumArgs()),
4844 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004845 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004846
John McCall833ca992009-10-29 08:12:44 +00004847 // FIXME: maybe don't rebuild if all the template arguments are the same.
4848
4849 QualType Result =
4850 getDerived().RebuildTemplateSpecializationType(Template,
4851 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004852 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004853
4854 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004855 // Specializations of template template parameters are represented as
4856 // TemplateSpecializationTypes, and substitution of type alias templates
4857 // within a dependent context can transform them into
4858 // DependentTemplateSpecializationTypes.
4859 if (isa<DependentTemplateSpecializationType>(Result)) {
4860 DependentTemplateSpecializationTypeLoc NewTL
4861 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004862 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004863 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004864 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004865 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004866 NewTL.setLAngleLoc(TL.getLAngleLoc());
4867 NewTL.setRAngleLoc(TL.getRAngleLoc());
4868 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4869 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4870 return Result;
4871 }
4872
John McCall833ca992009-10-29 08:12:44 +00004873 TemplateSpecializationTypeLoc NewTL
4874 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004875 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004876 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4877 NewTL.setLAngleLoc(TL.getLAngleLoc());
4878 NewTL.setRAngleLoc(TL.getRAngleLoc());
4879 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4880 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004881 }
Mike Stump1eb44332009-09-09 15:08:12 +00004882
John McCall833ca992009-10-29 08:12:44 +00004883 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004884}
Mike Stump1eb44332009-09-09 15:08:12 +00004885
Douglas Gregora88f09f2011-02-28 17:23:35 +00004886template <typename Derived>
4887QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4888 TypeLocBuilder &TLB,
4889 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004890 TemplateName Template,
4891 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004892 TemplateArgumentListInfo NewTemplateArgs;
4893 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4894 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4895 typedef TemplateArgumentLocContainerIterator<
4896 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004897 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004898 ArgIterator(TL, TL.getNumArgs()),
4899 NewTemplateArgs))
4900 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004901
Douglas Gregora88f09f2011-02-28 17:23:35 +00004902 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004903
Douglas Gregora88f09f2011-02-28 17:23:35 +00004904 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4905 QualType Result
4906 = getSema().Context.getDependentTemplateSpecializationType(
4907 TL.getTypePtr()->getKeyword(),
4908 DTN->getQualifier(),
4909 DTN->getIdentifier(),
4910 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004911
Douglas Gregora88f09f2011-02-28 17:23:35 +00004912 DependentTemplateSpecializationTypeLoc NewTL
4913 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004914 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004915 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004916 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004917 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004918 NewTL.setLAngleLoc(TL.getLAngleLoc());
4919 NewTL.setRAngleLoc(TL.getRAngleLoc());
4920 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4921 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4922 return Result;
4923 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004924
4925 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004926 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004927 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004928 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004929
Douglas Gregora88f09f2011-02-28 17:23:35 +00004930 if (!Result.isNull()) {
4931 /// FIXME: Wrap this in an elaborated-type-specifier?
4932 TemplateSpecializationTypeLoc NewTL
4933 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004934 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004935 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004936 NewTL.setLAngleLoc(TL.getLAngleLoc());
4937 NewTL.setRAngleLoc(TL.getRAngleLoc());
4938 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4939 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4940 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004941
Douglas Gregora88f09f2011-02-28 17:23:35 +00004942 return Result;
4943}
4944
Mike Stump1eb44332009-09-09 15:08:12 +00004945template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004946QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004947TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004948 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004949 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004950
Douglas Gregor9e876872011-03-01 18:12:44 +00004951 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004952 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004953 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004954 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004955 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4956 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004957 return QualType();
4958 }
Mike Stump1eb44332009-09-09 15:08:12 +00004959
John McCall43fed0d2010-11-12 08:19:04 +00004960 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4961 if (NamedT.isNull())
4962 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004963
Richard Smith3e4c6c42011-05-05 21:57:07 +00004964 // C++0x [dcl.type.elab]p2:
4965 // If the identifier resolves to a typedef-name or the simple-template-id
4966 // resolves to an alias template specialization, the
4967 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004968 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4969 if (const TemplateSpecializationType *TST =
4970 NamedT->getAs<TemplateSpecializationType>()) {
4971 TemplateName Template = TST->getTemplateName();
4972 if (TypeAliasTemplateDecl *TAT =
4973 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4974 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4975 diag::err_tag_reference_non_tag) << 4;
4976 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4977 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004978 }
4979 }
4980
John McCalla2becad2009-10-21 00:40:46 +00004981 QualType Result = TL.getType();
4982 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004983 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004984 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004985 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004986 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004987 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004988 if (Result.isNull())
4989 return QualType();
4990 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004991
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004992 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004993 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004994 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004995 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004996}
Mike Stump1eb44332009-09-09 15:08:12 +00004997
4998template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004999QualType TreeTransform<Derived>::TransformAttributedType(
5000 TypeLocBuilder &TLB,
5001 AttributedTypeLoc TL) {
5002 const AttributedType *oldType = TL.getTypePtr();
5003 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5004 if (modifiedType.isNull())
5005 return QualType();
5006
5007 QualType result = TL.getType();
5008
5009 // FIXME: dependent operand expressions?
5010 if (getDerived().AlwaysRebuild() ||
5011 modifiedType != oldType->getModifiedType()) {
5012 // TODO: this is really lame; we should really be rebuilding the
5013 // equivalent type from first principles.
5014 QualType equivalentType
5015 = getDerived().TransformType(oldType->getEquivalentType());
5016 if (equivalentType.isNull())
5017 return QualType();
5018 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5019 modifiedType,
5020 equivalentType);
5021 }
5022
5023 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5024 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5025 if (TL.hasAttrOperand())
5026 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5027 if (TL.hasAttrExprOperand())
5028 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5029 else if (TL.hasAttrEnumOperand())
5030 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5031
5032 return result;
5033}
5034
5035template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00005036QualType
5037TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5038 ParenTypeLoc TL) {
5039 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5040 if (Inner.isNull())
5041 return QualType();
5042
5043 QualType Result = TL.getType();
5044 if (getDerived().AlwaysRebuild() ||
5045 Inner != TL.getInnerLoc().getType()) {
5046 Result = getDerived().RebuildParenType(Inner);
5047 if (Result.isNull())
5048 return QualType();
5049 }
5050
5051 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5052 NewTL.setLParenLoc(TL.getLParenLoc());
5053 NewTL.setRParenLoc(TL.getRParenLoc());
5054 return Result;
5055}
5056
5057template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00005058QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005059 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00005060 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00005061
Douglas Gregor2494dd02011-03-01 01:34:45 +00005062 NestedNameSpecifierLoc QualifierLoc
5063 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5064 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00005065 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00005066
John McCall33500952010-06-11 00:33:02 +00005067 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00005068 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00005069 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00005070 QualifierLoc,
5071 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00005072 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00005073 if (Result.isNull())
5074 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005075
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005076 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5077 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00005078 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5079
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005080 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005081 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00005082 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00005083 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005084 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005085 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00005086 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005087 NewTL.setNameLoc(TL.getNameLoc());
5088 }
John McCalla2becad2009-10-21 00:40:46 +00005089 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00005090}
Mike Stump1eb44332009-09-09 15:08:12 +00005091
Douglas Gregor577f75a2009-08-04 16:50:30 +00005092template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00005093QualType TreeTransform<Derived>::
5094 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005095 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005096 NestedNameSpecifierLoc QualifierLoc;
5097 if (TL.getQualifierLoc()) {
5098 QualifierLoc
5099 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5100 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00005101 return QualType();
5102 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005103
John McCall43fed0d2010-11-12 08:19:04 +00005104 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005105 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00005106}
5107
5108template<typename Derived>
5109QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005110TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5111 DependentTemplateSpecializationTypeLoc TL,
5112 NestedNameSpecifierLoc QualifierLoc) {
5113 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005114
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005115 TemplateArgumentListInfo NewTemplateArgs;
5116 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5117 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005118
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005119 typedef TemplateArgumentLocContainerIterator<
5120 DependentTemplateSpecializationTypeLoc> ArgIterator;
5121 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5122 ArgIterator(TL, TL.getNumArgs()),
5123 NewTemplateArgs))
5124 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005125
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005126 QualType Result
5127 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5128 QualifierLoc,
5129 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005130 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005131 NewTemplateArgs);
5132 if (Result.isNull())
5133 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005134
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005135 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5136 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005137
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005138 // Copy information relevant to the template specialization.
5139 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005140 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005141 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005142 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005143 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5144 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005145 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005146 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005147
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005148 // Copy information relevant to the elaborated type.
5149 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005150 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005151 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005152 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5153 DependentTemplateSpecializationTypeLoc SpecTL
5154 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005155 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005156 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005157 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005158 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005159 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5160 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005161 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005162 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005163 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005164 TemplateSpecializationTypeLoc SpecTL
5165 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005166 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005167 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005168 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5169 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005170 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005171 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005172 }
5173 return Result;
5174}
5175
5176template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005177QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5178 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005179 QualType Pattern
5180 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005181 if (Pattern.isNull())
5182 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005183
5184 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005185 if (getDerived().AlwaysRebuild() ||
5186 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005187 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005188 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005189 TL.getEllipsisLoc(),
5190 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005191 if (Result.isNull())
5192 return QualType();
5193 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005194
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005195 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5196 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5197 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005198}
5199
5200template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005201QualType
5202TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005203 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005204 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005205 TLB.pushFullCopy(TL);
5206 return TL.getType();
5207}
5208
5209template<typename Derived>
5210QualType
5211TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005212 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005213 // ObjCObjectType is never dependent.
5214 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005215 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005216}
Mike Stump1eb44332009-09-09 15:08:12 +00005217
5218template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005219QualType
5220TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005221 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005222 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005223 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005224 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005225}
5226
Douglas Gregor577f75a2009-08-04 16:50:30 +00005227//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005228// Statement transformation
5229//===----------------------------------------------------------------------===//
5230template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005231StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005232TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005233 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005234}
5235
5236template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005237StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005238TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5239 return getDerived().TransformCompoundStmt(S, false);
5240}
5241
5242template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005243StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005244TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005245 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005246 Sema::CompoundScopeRAII CompoundScope(getSema());
5247
John McCall7114cba2010-08-27 19:56:05 +00005248 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005249 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005250 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005251 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5252 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005253 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005254 if (Result.isInvalid()) {
5255 // Immediately fail if this was a DeclStmt, since it's very
5256 // likely that this will cause problems for future statements.
5257 if (isa<DeclStmt>(*B))
5258 return StmtError();
5259
5260 // Otherwise, just keep processing substatements and fail later.
5261 SubStmtInvalid = true;
5262 continue;
5263 }
Mike Stump1eb44332009-09-09 15:08:12 +00005264
Douglas Gregor43959a92009-08-20 07:17:43 +00005265 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5266 Statements.push_back(Result.takeAs<Stmt>());
5267 }
Mike Stump1eb44332009-09-09 15:08:12 +00005268
John McCall7114cba2010-08-27 19:56:05 +00005269 if (SubStmtInvalid)
5270 return StmtError();
5271
Douglas Gregor43959a92009-08-20 07:17:43 +00005272 if (!getDerived().AlwaysRebuild() &&
5273 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005274 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005275
5276 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005277 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005278 S->getRBracLoc(),
5279 IsStmtExpr);
5280}
Mike Stump1eb44332009-09-09 15:08:12 +00005281
Douglas Gregor43959a92009-08-20 07:17:43 +00005282template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005283StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005284TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005285 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005286 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005287 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5288 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005289
Eli Friedman264c1f82009-11-19 03:14:00 +00005290 // Transform the left-hand case value.
5291 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005292 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005293 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005294 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005295
Eli Friedman264c1f82009-11-19 03:14:00 +00005296 // Transform the right-hand case value (for the GNU case-range extension).
5297 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005298 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005299 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005300 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005301 }
Mike Stump1eb44332009-09-09 15:08:12 +00005302
Douglas Gregor43959a92009-08-20 07:17:43 +00005303 // Build the case statement.
5304 // Case statements are always rebuilt so that they will attached to their
5305 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005306 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005307 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005308 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005309 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005310 S->getColonLoc());
5311 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005312 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005313
Douglas Gregor43959a92009-08-20 07:17:43 +00005314 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005315 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005316 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005317 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005318
Douglas Gregor43959a92009-08-20 07:17:43 +00005319 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005320 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005321}
5322
5323template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005324StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005325TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005326 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005327 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005328 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005329 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005330
Douglas Gregor43959a92009-08-20 07:17:43 +00005331 // Default statements are always rebuilt
5332 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005333 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005334}
Mike Stump1eb44332009-09-09 15:08:12 +00005335
Douglas Gregor43959a92009-08-20 07:17:43 +00005336template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005337StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005338TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005339 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005340 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005341 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005342
Chris Lattner57ad3782011-02-17 20:34:02 +00005343 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5344 S->getDecl());
5345 if (!LD)
5346 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005347
5348
Douglas Gregor43959a92009-08-20 07:17:43 +00005349 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005350 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005351 cast<LabelDecl>(LD), SourceLocation(),
5352 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005353}
Mike Stump1eb44332009-09-09 15:08:12 +00005354
Douglas Gregor43959a92009-08-20 07:17:43 +00005355template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005356StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005357TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5358 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5359 if (SubStmt.isInvalid())
5360 return StmtError();
5361
5362 // TODO: transform attributes
5363 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5364 return S;
5365
5366 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5367 S->getAttrs(),
5368 SubStmt.get());
5369}
5370
5371template<typename Derived>
5372StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005373TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005374 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005375 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005376 VarDecl *ConditionVar = 0;
5377 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005378 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005379 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005380 getDerived().TransformDefinition(
5381 S->getConditionVariable()->getLocation(),
5382 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005383 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005384 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005385 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005386 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005387
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005388 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005389 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005390
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005391 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005392 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005393 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005394 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005395 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005396 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005397
John McCall9ae2f072010-08-23 23:25:46 +00005398 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005399 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005400 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005401
John McCall9ae2f072010-08-23 23:25:46 +00005402 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5403 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005404 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005405
Douglas Gregor43959a92009-08-20 07:17:43 +00005406 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005407 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005408 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005409 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005410
Douglas Gregor43959a92009-08-20 07:17:43 +00005411 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005412 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005413 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005414 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005415
Douglas Gregor43959a92009-08-20 07:17:43 +00005416 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005417 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005418 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005419 Then.get() == S->getThen() &&
5420 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005421 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005422
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005423 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005424 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005425 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005426}
5427
5428template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005429StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005430TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005431 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005432 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005433 VarDecl *ConditionVar = 0;
5434 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005435 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005436 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005437 getDerived().TransformDefinition(
5438 S->getConditionVariable()->getLocation(),
5439 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005440 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005441 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005442 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005443 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005444
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005445 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005446 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005447 }
Mike Stump1eb44332009-09-09 15:08:12 +00005448
Douglas Gregor43959a92009-08-20 07:17:43 +00005449 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005450 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005451 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005452 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005453 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005454 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005455
Douglas Gregor43959a92009-08-20 07:17:43 +00005456 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005457 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005458 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005459 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005460
Douglas Gregor43959a92009-08-20 07:17:43 +00005461 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005462 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5463 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005464}
Mike Stump1eb44332009-09-09 15:08:12 +00005465
Douglas Gregor43959a92009-08-20 07:17:43 +00005466template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005467StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005468TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005469 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005470 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005471 VarDecl *ConditionVar = 0;
5472 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005473 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005474 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005475 getDerived().TransformDefinition(
5476 S->getConditionVariable()->getLocation(),
5477 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005478 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005479 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005480 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005481 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005482
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005483 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005484 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005485
5486 if (S->getCond()) {
5487 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005488 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005489 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005490 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005491 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005492 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005493 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005494 }
Mike Stump1eb44332009-09-09 15:08:12 +00005495
John McCall9ae2f072010-08-23 23:25:46 +00005496 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5497 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005498 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005499
Douglas Gregor43959a92009-08-20 07:17:43 +00005500 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005501 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005502 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005503 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005504
Douglas Gregor43959a92009-08-20 07:17:43 +00005505 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005506 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005507 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005508 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005509 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005510
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005511 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005512 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005513}
Mike Stump1eb44332009-09-09 15:08:12 +00005514
Douglas Gregor43959a92009-08-20 07:17:43 +00005515template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005516StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005517TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005518 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005519 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005520 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005521 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005522
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005523 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005524 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005525 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005526 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005527
Douglas Gregor43959a92009-08-20 07:17:43 +00005528 if (!getDerived().AlwaysRebuild() &&
5529 Cond.get() == S->getCond() &&
5530 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005531 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005532
John McCall9ae2f072010-08-23 23:25:46 +00005533 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5534 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005535 S->getRParenLoc());
5536}
Mike Stump1eb44332009-09-09 15:08:12 +00005537
Douglas Gregor43959a92009-08-20 07:17:43 +00005538template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005539StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005540TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005541 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005542 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005543 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005544 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005545
Douglas Gregor43959a92009-08-20 07:17:43 +00005546 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005547 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005548 VarDecl *ConditionVar = 0;
5549 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005550 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005551 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005552 getDerived().TransformDefinition(
5553 S->getConditionVariable()->getLocation(),
5554 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005555 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005556 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005557 } else {
5558 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005559
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005560 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005561 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005562
5563 if (S->getCond()) {
5564 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005565 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005566 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005567 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005568 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005569
John McCall9ae2f072010-08-23 23:25:46 +00005570 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005571 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005572 }
Mike Stump1eb44332009-09-09 15:08:12 +00005573
Chad Rosier4a9d7952012-08-08 18:46:20 +00005574 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005575 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005576 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005577
Douglas Gregor43959a92009-08-20 07:17:43 +00005578 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005579 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005580 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005581 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005582
Richard Smith41956372013-01-14 22:39:08 +00005583 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005584 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005585 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005586
Douglas Gregor43959a92009-08-20 07:17:43 +00005587 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005588 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005589 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005590 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005591
Douglas Gregor43959a92009-08-20 07:17:43 +00005592 if (!getDerived().AlwaysRebuild() &&
5593 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005594 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005595 Inc.get() == S->getInc() &&
5596 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005597 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005598
Douglas Gregor43959a92009-08-20 07:17:43 +00005599 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005600 Init.get(), FullCond, ConditionVar,
5601 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005602}
5603
5604template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005605StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005606TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005607 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5608 S->getLabel());
5609 if (!LD)
5610 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005611
Douglas Gregor43959a92009-08-20 07:17:43 +00005612 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005613 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005614 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005615}
5616
5617template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005618StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005619TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005620 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005621 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005622 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005623 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005624
Douglas Gregor43959a92009-08-20 07:17:43 +00005625 if (!getDerived().AlwaysRebuild() &&
5626 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005627 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005628
5629 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005630 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005631}
5632
5633template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005634StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005635TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005636 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005637}
Mike Stump1eb44332009-09-09 15:08:12 +00005638
Douglas Gregor43959a92009-08-20 07:17:43 +00005639template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005640StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005641TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005642 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005643}
Mike Stump1eb44332009-09-09 15:08:12 +00005644
Douglas Gregor43959a92009-08-20 07:17:43 +00005645template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005646StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005647TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005648 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005649 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005650 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005651
Mike Stump1eb44332009-09-09 15:08:12 +00005652 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005653 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005654 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005655}
Mike Stump1eb44332009-09-09 15:08:12 +00005656
Douglas Gregor43959a92009-08-20 07:17:43 +00005657template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005658StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005659TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005660 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005661 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005662 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5663 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005664 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5665 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005666 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005667 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005668
Douglas Gregor43959a92009-08-20 07:17:43 +00005669 if (Transformed != *D)
5670 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005671
Douglas Gregor43959a92009-08-20 07:17:43 +00005672 Decls.push_back(Transformed);
5673 }
Mike Stump1eb44332009-09-09 15:08:12 +00005674
Douglas Gregor43959a92009-08-20 07:17:43 +00005675 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005676 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005677
Rafael Espindola4549d7f2013-07-09 12:05:01 +00005678 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005679}
Mike Stump1eb44332009-09-09 15:08:12 +00005680
Douglas Gregor43959a92009-08-20 07:17:43 +00005681template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005682StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005683TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005684
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005685 SmallVector<Expr*, 8> Constraints;
5686 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005687 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005688
John McCall60d7b3a2010-08-24 06:29:42 +00005689 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005690 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005691
5692 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005693
Anders Carlsson703e3942010-01-24 05:50:09 +00005694 // Go through the outputs.
5695 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005696 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005697
Anders Carlsson703e3942010-01-24 05:50:09 +00005698 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005699 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005700
Anders Carlsson703e3942010-01-24 05:50:09 +00005701 // Transform the output expr.
5702 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005703 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005704 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005705 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005706
Anders Carlsson703e3942010-01-24 05:50:09 +00005707 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005708
John McCall9ae2f072010-08-23 23:25:46 +00005709 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005710 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005711
Anders Carlsson703e3942010-01-24 05:50:09 +00005712 // Go through the inputs.
5713 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005714 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005715
Anders Carlsson703e3942010-01-24 05:50:09 +00005716 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005717 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005718
Anders Carlsson703e3942010-01-24 05:50:09 +00005719 // Transform the input expr.
5720 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005721 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005722 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005723 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005724
Anders Carlsson703e3942010-01-24 05:50:09 +00005725 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005726
John McCall9ae2f072010-08-23 23:25:46 +00005727 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005728 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005729
Anders Carlsson703e3942010-01-24 05:50:09 +00005730 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005731 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005732
5733 // Go through the clobbers.
5734 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005735 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005736
5737 // No need to transform the asm string literal.
5738 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005739 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5740 S->isVolatile(), S->getNumOutputs(),
5741 S->getNumInputs(), Names.data(),
5742 Constraints, Exprs, AsmString.get(),
5743 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005744}
5745
Chad Rosier8cd64b42012-06-11 20:47:18 +00005746template<typename Derived>
5747StmtResult
5748TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005749 ArrayRef<Token> AsmToks =
5750 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005751
John McCallaeeacf72013-05-03 00:10:13 +00005752 bool HadError = false, HadChange = false;
5753
5754 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5755 SmallVector<Expr*, 8> TransformedExprs;
5756 TransformedExprs.reserve(SrcExprs.size());
5757 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5758 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5759 if (!Result.isUsable()) {
5760 HadError = true;
5761 } else {
5762 HadChange |= (Result.get() != SrcExprs[i]);
5763 TransformedExprs.push_back(Result.take());
5764 }
5765 }
5766
5767 if (HadError) return StmtError();
5768 if (!HadChange && !getDerived().AlwaysRebuild())
5769 return Owned(S);
5770
Chad Rosier7bd092b2012-08-15 16:53:30 +00005771 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallaeeacf72013-05-03 00:10:13 +00005772 AsmToks, S->getAsmString(),
5773 S->getNumOutputs(), S->getNumInputs(),
5774 S->getAllConstraints(), S->getClobbers(),
5775 TransformedExprs, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005776}
Douglas Gregor43959a92009-08-20 07:17:43 +00005777
5778template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005779StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005780TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005781 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005782 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005783 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005784 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005785
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005786 // Transform the @catch statements (if present).
5787 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005788 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005789 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005790 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005791 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005792 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005793 if (Catch.get() != S->getCatchStmt(I))
5794 AnyCatchChanged = true;
5795 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005796 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005797
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005798 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005799 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005800 if (S->getFinallyStmt()) {
5801 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5802 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005803 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005804 }
5805
5806 // If nothing changed, just retain this statement.
5807 if (!getDerived().AlwaysRebuild() &&
5808 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005809 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005810 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005811 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005812
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005813 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005814 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005815 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005816}
Mike Stump1eb44332009-09-09 15:08:12 +00005817
Douglas Gregor43959a92009-08-20 07:17:43 +00005818template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005819StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005820TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005821 // Transform the @catch parameter, if there is one.
5822 VarDecl *Var = 0;
5823 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5824 TypeSourceInfo *TSInfo = 0;
5825 if (FromVar->getTypeSourceInfo()) {
5826 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5827 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005828 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005829 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005830
Douglas Gregorbe270a02010-04-26 17:57:08 +00005831 QualType T;
5832 if (TSInfo)
5833 T = TSInfo->getType();
5834 else {
5835 T = getDerived().TransformType(FromVar->getType());
5836 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005837 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005838 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005839
Douglas Gregorbe270a02010-04-26 17:57:08 +00005840 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5841 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005842 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005843 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005844
John McCall60d7b3a2010-08-24 06:29:42 +00005845 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005846 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005847 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005848
5849 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005850 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005851 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005852}
Mike Stump1eb44332009-09-09 15:08:12 +00005853
Douglas Gregor43959a92009-08-20 07:17:43 +00005854template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005855StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005856TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005857 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005858 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005859 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005860 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005861
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005862 // If nothing changed, just retain this statement.
5863 if (!getDerived().AlwaysRebuild() &&
5864 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005865 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005866
5867 // Build a new statement.
5868 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005869 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005870}
Mike Stump1eb44332009-09-09 15:08:12 +00005871
Douglas Gregor43959a92009-08-20 07:17:43 +00005872template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005873StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005874TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005875 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005876 if (S->getThrowExpr()) {
5877 Operand = getDerived().TransformExpr(S->getThrowExpr());
5878 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005879 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005880 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005881
Douglas Gregord1377b22010-04-22 21:44:01 +00005882 if (!getDerived().AlwaysRebuild() &&
5883 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005884 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005885
John McCall9ae2f072010-08-23 23:25:46 +00005886 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005887}
Mike Stump1eb44332009-09-09 15:08:12 +00005888
Douglas Gregor43959a92009-08-20 07:17:43 +00005889template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005890StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005891TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005892 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005893 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005894 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005895 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005896 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005897 Object =
5898 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5899 Object.get());
5900 if (Object.isInvalid())
5901 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005902
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005903 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005904 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005905 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005906 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005907
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005908 // If nothing change, just retain the current statement.
5909 if (!getDerived().AlwaysRebuild() &&
5910 Object.get() == S->getSynchExpr() &&
5911 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005912 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005913
5914 // Build a new statement.
5915 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005916 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005917}
5918
5919template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005920StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005921TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5922 ObjCAutoreleasePoolStmt *S) {
5923 // Transform the body.
5924 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5925 if (Body.isInvalid())
5926 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005927
John McCallf85e1932011-06-15 23:02:42 +00005928 // If nothing changed, just retain this statement.
5929 if (!getDerived().AlwaysRebuild() &&
5930 Body.get() == S->getSubStmt())
5931 return SemaRef.Owned(S);
5932
5933 // Build a new statement.
5934 return getDerived().RebuildObjCAutoreleasePoolStmt(
5935 S->getAtLoc(), Body.get());
5936}
5937
5938template<typename Derived>
5939StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005940TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005941 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005942 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005943 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005944 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005945 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005946
Douglas Gregorc3203e72010-04-22 23:10:45 +00005947 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005948 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005949 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005950 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005951
Douglas Gregorc3203e72010-04-22 23:10:45 +00005952 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005953 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005954 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005955 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005956
Douglas Gregorc3203e72010-04-22 23:10:45 +00005957 // If nothing changed, just retain this statement.
5958 if (!getDerived().AlwaysRebuild() &&
5959 Element.get() == S->getElement() &&
5960 Collection.get() == S->getCollection() &&
5961 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005962 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005963
Douglas Gregorc3203e72010-04-22 23:10:45 +00005964 // Build a new statement.
5965 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005966 Element.get(),
5967 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005968 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005969 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005970}
5971
5972
5973template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005974StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005975TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5976 // Transform the exception declaration, if any.
5977 VarDecl *Var = 0;
5978 if (S->getExceptionDecl()) {
5979 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005980 TypeSourceInfo *T = getDerived().TransformType(
5981 ExceptionDecl->getTypeSourceInfo());
5982 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005983 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005984
Douglas Gregor83cb9422010-09-09 17:09:21 +00005985 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005986 ExceptionDecl->getInnerLocStart(),
5987 ExceptionDecl->getLocation(),
5988 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005989 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005990 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005991 }
Mike Stump1eb44332009-09-09 15:08:12 +00005992
Douglas Gregor43959a92009-08-20 07:17:43 +00005993 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005994 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005995 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005996 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005997
Douglas Gregor43959a92009-08-20 07:17:43 +00005998 if (!getDerived().AlwaysRebuild() &&
5999 !Var &&
6000 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00006001 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00006002
6003 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
6004 Var,
John McCall9ae2f072010-08-23 23:25:46 +00006005 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00006006}
Mike Stump1eb44332009-09-09 15:08:12 +00006007
Douglas Gregor43959a92009-08-20 07:17:43 +00006008template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006009StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00006010TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
6011 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006012 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00006013 = getDerived().TransformCompoundStmt(S->getTryBlock());
6014 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006015 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006016
Douglas Gregor43959a92009-08-20 07:17:43 +00006017 // Transform the handlers.
6018 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006019 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00006020 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006021 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00006022 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
6023 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006024 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006025
Douglas Gregor43959a92009-08-20 07:17:43 +00006026 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6027 Handlers.push_back(Handler.takeAs<Stmt>());
6028 }
Mike Stump1eb44332009-09-09 15:08:12 +00006029
Douglas Gregor43959a92009-08-20 07:17:43 +00006030 if (!getDerived().AlwaysRebuild() &&
6031 TryBlock.get() == S->getTryBlock() &&
6032 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006033 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00006034
John McCall9ae2f072010-08-23 23:25:46 +00006035 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006036 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00006037}
Mike Stump1eb44332009-09-09 15:08:12 +00006038
Richard Smithad762fc2011-04-14 22:09:26 +00006039template<typename Derived>
6040StmtResult
6041TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6042 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6043 if (Range.isInvalid())
6044 return StmtError();
6045
6046 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6047 if (BeginEnd.isInvalid())
6048 return StmtError();
6049
6050 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6051 if (Cond.isInvalid())
6052 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006053 if (Cond.get())
6054 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6055 if (Cond.isInvalid())
6056 return StmtError();
6057 if (Cond.get())
6058 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006059
6060 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6061 if (Inc.isInvalid())
6062 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006063 if (Inc.get())
6064 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006065
6066 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6067 if (LoopVar.isInvalid())
6068 return StmtError();
6069
6070 StmtResult NewStmt = S;
6071 if (getDerived().AlwaysRebuild() ||
6072 Range.get() != S->getRangeStmt() ||
6073 BeginEnd.get() != S->getBeginEndStmt() ||
6074 Cond.get() != S->getCond() ||
6075 Inc.get() != S->getInc() ||
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006076 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smithad762fc2011-04-14 22:09:26 +00006077 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6078 S->getColonLoc(), Range.get(),
6079 BeginEnd.get(), Cond.get(),
6080 Inc.get(), LoopVar.get(),
6081 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006082 if (NewStmt.isInvalid())
6083 return StmtError();
6084 }
Richard Smithad762fc2011-04-14 22:09:26 +00006085
6086 StmtResult Body = getDerived().TransformStmt(S->getBody());
6087 if (Body.isInvalid())
6088 return StmtError();
6089
6090 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6091 // it now so we have a new statement to attach the body to.
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006092 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smithad762fc2011-04-14 22:09:26 +00006093 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6094 S->getColonLoc(), Range.get(),
6095 BeginEnd.get(), Cond.get(),
6096 Inc.get(), LoopVar.get(),
6097 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006098 if (NewStmt.isInvalid())
6099 return StmtError();
6100 }
Richard Smithad762fc2011-04-14 22:09:26 +00006101
6102 if (NewStmt.get() == S)
6103 return SemaRef.Owned(S);
6104
6105 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6106}
6107
John Wiegley28bbe4b2011-04-28 01:08:34 +00006108template<typename Derived>
6109StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00006110TreeTransform<Derived>::TransformMSDependentExistsStmt(
6111 MSDependentExistsStmt *S) {
6112 // Transform the nested-name-specifier, if any.
6113 NestedNameSpecifierLoc QualifierLoc;
6114 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006115 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00006116 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6117 if (!QualifierLoc)
6118 return StmtError();
6119 }
6120
6121 // Transform the declaration name.
6122 DeclarationNameInfo NameInfo = S->getNameInfo();
6123 if (NameInfo.getName()) {
6124 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6125 if (!NameInfo.getName())
6126 return StmtError();
6127 }
6128
6129 // Check whether anything changed.
6130 if (!getDerived().AlwaysRebuild() &&
6131 QualifierLoc == S->getQualifierLoc() &&
6132 NameInfo.getName() == S->getNameInfo().getName())
6133 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006134
Douglas Gregorba0513d2011-10-25 01:33:02 +00006135 // Determine whether this name exists, if we can.
6136 CXXScopeSpec SS;
6137 SS.Adopt(QualifierLoc);
6138 bool Dependent = false;
6139 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6140 case Sema::IER_Exists:
6141 if (S->isIfExists())
6142 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006143
Douglas Gregorba0513d2011-10-25 01:33:02 +00006144 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6145
6146 case Sema::IER_DoesNotExist:
6147 if (S->isIfNotExists())
6148 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006149
Douglas Gregorba0513d2011-10-25 01:33:02 +00006150 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006151
Douglas Gregorba0513d2011-10-25 01:33:02 +00006152 case Sema::IER_Dependent:
6153 Dependent = true;
6154 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006155
Douglas Gregor65019ac2011-10-25 03:44:56 +00006156 case Sema::IER_Error:
6157 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006158 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006159
Douglas Gregorba0513d2011-10-25 01:33:02 +00006160 // We need to continue with the instantiation, so do so now.
6161 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6162 if (SubStmt.isInvalid())
6163 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006164
Douglas Gregorba0513d2011-10-25 01:33:02 +00006165 // If we have resolved the name, just transform to the substatement.
6166 if (!Dependent)
6167 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006168
Douglas Gregorba0513d2011-10-25 01:33:02 +00006169 // The name is still dependent, so build a dependent expression again.
6170 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6171 S->isIfExists(),
6172 QualifierLoc,
6173 NameInfo,
6174 SubStmt.get());
6175}
6176
6177template<typename Derived>
John McCall76da55d2013-04-16 07:28:30 +00006178ExprResult
6179TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6180 NestedNameSpecifierLoc QualifierLoc;
6181 if (E->getQualifierLoc()) {
6182 QualifierLoc
6183 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6184 if (!QualifierLoc)
6185 return ExprError();
6186 }
6187
6188 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6189 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6190 if (!PD)
6191 return ExprError();
6192
6193 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6194 if (Base.isInvalid())
6195 return ExprError();
6196
6197 return new (SemaRef.getASTContext())
6198 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6199 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6200 QualifierLoc, E->getMemberLoc());
6201}
6202
6203template<typename Derived>
Douglas Gregorba0513d2011-10-25 01:33:02 +00006204StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006205TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6206 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6207 if(TryBlock.isInvalid()) return StmtError();
6208
6209 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6210 if(!getDerived().AlwaysRebuild() &&
6211 TryBlock.get() == S->getTryBlock() &&
6212 Handler.get() == S->getHandler())
6213 return SemaRef.Owned(S);
6214
6215 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6216 S->getTryLoc(),
6217 TryBlock.take(),
6218 Handler.take());
6219}
6220
6221template<typename Derived>
6222StmtResult
6223TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6224 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6225 if(Block.isInvalid()) return StmtError();
6226
6227 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6228 Block.take());
6229}
6230
6231template<typename Derived>
6232StmtResult
6233TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6234 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6235 if(FilterExpr.isInvalid()) return StmtError();
6236
6237 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6238 if(Block.isInvalid()) return StmtError();
6239
6240 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6241 FilterExpr.take(),
6242 Block.take());
6243}
6244
6245template<typename Derived>
6246StmtResult
6247TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6248 if(isa<SEHFinallyStmt>(Handler))
6249 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6250 else
6251 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6252}
6253
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006254template<typename Derived>
6255StmtResult
6256TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6257 // Transform the clauses
Robert Wilhelme7205c02013-08-10 12:33:24 +00006258 SmallVector<OMPClause *, 5> TClauses;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006259 ArrayRef<OMPClause *> Clauses = D->clauses();
6260 TClauses.reserve(Clauses.size());
6261 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6262 I != E; ++I) {
6263 if (*I) {
6264 OMPClause *Clause = getDerived().TransformOMPClause(*I);
6265 if (!Clause)
6266 return StmtError();
6267 TClauses.push_back(Clause);
6268 }
6269 else {
6270 TClauses.push_back(0);
6271 }
6272 }
6273 if (!D->getAssociatedStmt())
6274 return StmtError();
6275 StmtResult AssociatedStmt =
6276 getDerived().TransformStmt(D->getAssociatedStmt());
6277 if (AssociatedStmt.isInvalid())
6278 return StmtError();
6279
6280 return getDerived().RebuildOMPParallelDirective(TClauses,
6281 AssociatedStmt.take(),
6282 D->getLocStart(),
6283 D->getLocEnd());
6284}
6285
6286template<typename Derived>
6287OMPClause *
6288TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6289 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6290 C->getDefaultKindKwLoc(),
6291 C->getLocStart(),
6292 C->getLParenLoc(),
6293 C->getLocEnd());
6294}
6295
6296template<typename Derived>
6297OMPClause *
6298TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Robert Wilhelme7205c02013-08-10 12:33:24 +00006299 SmallVector<Expr *, 5> Vars;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006300 Vars.reserve(C->varlist_size());
6301 for (OMPVarList<OMPPrivateClause>::varlist_iterator I = C->varlist_begin(),
6302 E = C->varlist_end();
6303 I != E; ++I) {
6304 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6305 if (EVar.isInvalid())
6306 return 0;
6307 Vars.push_back(EVar.take());
6308 }
6309 return getDerived().RebuildOMPPrivateClause(Vars,
6310 C->getLocStart(),
6311 C->getLParenLoc(),
6312 C->getLocEnd());
6313}
6314
Douglas Gregor43959a92009-08-20 07:17:43 +00006315//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006316// Expression transformation
6317//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006318template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006319ExprResult
John McCall454feb92009-12-08 09:21:05 +00006320TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006321 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006322}
Mike Stump1eb44332009-09-09 15:08:12 +00006323
6324template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006325ExprResult
John McCall454feb92009-12-08 09:21:05 +00006326TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006327 NestedNameSpecifierLoc QualifierLoc;
6328 if (E->getQualifierLoc()) {
6329 QualifierLoc
6330 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6331 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006332 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006333 }
John McCalldbd872f2009-12-08 09:08:17 +00006334
6335 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006336 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6337 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006338 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006339 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006340
John McCallec8045d2010-08-17 21:27:17 +00006341 DeclarationNameInfo NameInfo = E->getNameInfo();
6342 if (NameInfo.getName()) {
6343 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6344 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006345 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006346 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006347
6348 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006349 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006350 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006351 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006352 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006353
6354 // Mark it referenced in the new context regardless.
6355 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006356 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006357
John McCall3fa5cae2010-10-26 07:05:15 +00006358 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006359 }
John McCalldbd872f2009-12-08 09:08:17 +00006360
6361 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006362 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006363 TemplateArgs = &TransArgs;
6364 TransArgs.setLAngleLoc(E->getLAngleLoc());
6365 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006366 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6367 E->getNumTemplateArgs(),
6368 TransArgs))
6369 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006370 }
6371
Chad Rosier4a9d7952012-08-08 18:46:20 +00006372 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006373 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006374}
Mike Stump1eb44332009-09-09 15:08:12 +00006375
Douglas Gregorb98b1992009-08-11 05:31:07 +00006376template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006377ExprResult
John McCall454feb92009-12-08 09:21:05 +00006378TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006379 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006380}
Mike Stump1eb44332009-09-09 15:08:12 +00006381
Douglas Gregorb98b1992009-08-11 05:31:07 +00006382template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006383ExprResult
John McCall454feb92009-12-08 09:21:05 +00006384TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006385 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006386}
Mike Stump1eb44332009-09-09 15:08:12 +00006387
Douglas Gregorb98b1992009-08-11 05:31:07 +00006388template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006389ExprResult
John McCall454feb92009-12-08 09:21:05 +00006390TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006391 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006392}
Mike Stump1eb44332009-09-09 15:08:12 +00006393
Douglas Gregorb98b1992009-08-11 05:31:07 +00006394template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006395ExprResult
John McCall454feb92009-12-08 09:21:05 +00006396TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006397 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006398}
Mike Stump1eb44332009-09-09 15:08:12 +00006399
Douglas Gregorb98b1992009-08-11 05:31:07 +00006400template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006401ExprResult
John McCall454feb92009-12-08 09:21:05 +00006402TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006403 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006404}
6405
6406template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006407ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006408TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis391ca9f2013-04-09 01:17:02 +00006409 if (FunctionDecl *FD = E->getDirectCallee())
6410 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smith9fcce652012-03-07 08:35:16 +00006411 return SemaRef.MaybeBindToTemporary(E);
6412}
6413
6414template<typename Derived>
6415ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006416TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6417 ExprResult ControllingExpr =
6418 getDerived().TransformExpr(E->getControllingExpr());
6419 if (ControllingExpr.isInvalid())
6420 return ExprError();
6421
Chris Lattner686775d2011-07-20 06:58:45 +00006422 SmallVector<Expr *, 4> AssocExprs;
6423 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006424 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6425 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6426 if (TS) {
6427 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6428 if (!AssocType)
6429 return ExprError();
6430 AssocTypes.push_back(AssocType);
6431 } else {
6432 AssocTypes.push_back(0);
6433 }
6434
6435 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6436 if (AssocExpr.isInvalid())
6437 return ExprError();
6438 AssocExprs.push_back(AssocExpr.release());
6439 }
6440
6441 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6442 E->getDefaultLoc(),
6443 E->getRParenLoc(),
6444 ControllingExpr.release(),
Dmitri Gribenko80613222013-05-10 13:06:58 +00006445 AssocTypes,
6446 AssocExprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00006447}
6448
6449template<typename Derived>
6450ExprResult
John McCall454feb92009-12-08 09:21:05 +00006451TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006452 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006453 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006454 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006455
Douglas Gregorb98b1992009-08-11 05:31:07 +00006456 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006457 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006458
John McCall9ae2f072010-08-23 23:25:46 +00006459 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006460 E->getRParen());
6461}
6462
Richard Smithefeeccf2012-10-21 03:28:35 +00006463/// \brief The operand of a unary address-of operator has special rules: it's
6464/// allowed to refer to a non-static member of a class even if there's no 'this'
6465/// object available.
6466template<typename Derived>
6467ExprResult
6468TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6469 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6470 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6471 else
6472 return getDerived().TransformExpr(E);
6473}
6474
Mike Stump1eb44332009-09-09 15:08:12 +00006475template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006476ExprResult
John McCall454feb92009-12-08 09:21:05 +00006477TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smith82b00012013-05-21 23:29:46 +00006478 ExprResult SubExpr;
6479 if (E->getOpcode() == UO_AddrOf)
6480 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6481 else
6482 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006483 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006484 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006485
Douglas Gregorb98b1992009-08-11 05:31:07 +00006486 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006487 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006488
Douglas Gregorb98b1992009-08-11 05:31:07 +00006489 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6490 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006491 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006492}
Mike Stump1eb44332009-09-09 15:08:12 +00006493
Douglas Gregorb98b1992009-08-11 05:31:07 +00006494template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006495ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006496TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6497 // Transform the type.
6498 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6499 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006500 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006501
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006502 // Transform all of the components into components similar to what the
6503 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006504 // FIXME: It would be slightly more efficient in the non-dependent case to
6505 // just map FieldDecls, rather than requiring the rebuilder to look for
6506 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006507 // template code that we don't care.
6508 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006509 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006510 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006511 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006512 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6513 const Node &ON = E->getComponent(I);
6514 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006515 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006516 Comp.LocStart = ON.getSourceRange().getBegin();
6517 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006518 switch (ON.getKind()) {
6519 case Node::Array: {
6520 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006521 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006522 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006523 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006524
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006525 ExprChanged = ExprChanged || Index.get() != FromIndex;
6526 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006527 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006528 break;
6529 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006530
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006531 case Node::Field:
6532 case Node::Identifier:
6533 Comp.isBrackets = false;
6534 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006535 if (!Comp.U.IdentInfo)
6536 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006537
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006538 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006539
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006540 case Node::Base:
6541 // Will be recomputed during the rebuild.
6542 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006543 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006544
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006545 Components.push_back(Comp);
6546 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006547
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006548 // If nothing changed, retain the existing expression.
6549 if (!getDerived().AlwaysRebuild() &&
6550 Type == E->getTypeSourceInfo() &&
6551 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006552 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006553
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006554 // Build a new offsetof expression.
6555 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6556 Components.data(), Components.size(),
6557 E->getRParenLoc());
6558}
6559
6560template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006561ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006562TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6563 assert(getDerived().AlreadyTransformed(E->getType()) &&
6564 "opaque value expression requires transformation");
6565 return SemaRef.Owned(E);
6566}
6567
6568template<typename Derived>
6569ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006570TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006571 // Rebuild the syntactic form. The original syntactic form has
6572 // opaque-value expressions in it, so strip those away and rebuild
6573 // the result. This is a really awful way of doing this, but the
6574 // better solution (rebuilding the semantic expressions and
6575 // rebinding OVEs as necessary) doesn't work; we'd need
6576 // TreeTransform to not strip away implicit conversions.
6577 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6578 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006579 if (result.isInvalid()) return ExprError();
6580
6581 // If that gives us a pseudo-object result back, the pseudo-object
6582 // expression must have been an lvalue-to-rvalue conversion which we
6583 // should reapply.
6584 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6585 result = SemaRef.checkPseudoObjectRValue(result.take());
6586
6587 return result;
6588}
6589
6590template<typename Derived>
6591ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006592TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6593 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006594 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006595 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006596
John McCalla93c9342009-12-07 02:54:59 +00006597 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006598 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006599 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006600
John McCall5ab75172009-11-04 07:28:41 +00006601 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006602 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006603
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006604 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6605 E->getKind(),
6606 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006607 }
Mike Stump1eb44332009-09-09 15:08:12 +00006608
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006609 // C++0x [expr.sizeof]p1:
6610 // The operand is either an expression, which is an unevaluated operand
6611 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006612 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6613 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006614
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006615 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6616 if (SubExpr.isInvalid())
6617 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006618
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006619 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6620 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006621
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006622 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6623 E->getOperatorLoc(),
6624 E->getKind(),
6625 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006626}
Mike Stump1eb44332009-09-09 15:08:12 +00006627
Douglas Gregorb98b1992009-08-11 05:31:07 +00006628template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006629ExprResult
John McCall454feb92009-12-08 09:21:05 +00006630TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006631 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006632 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006633 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006634
John McCall60d7b3a2010-08-24 06:29:42 +00006635 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006636 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006637 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006638
6639
Douglas Gregorb98b1992009-08-11 05:31:07 +00006640 if (!getDerived().AlwaysRebuild() &&
6641 LHS.get() == E->getLHS() &&
6642 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006643 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006644
John McCall9ae2f072010-08-23 23:25:46 +00006645 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006646 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006647 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006648 E->getRBracketLoc());
6649}
Mike Stump1eb44332009-09-09 15:08:12 +00006650
6651template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006652ExprResult
John McCall454feb92009-12-08 09:21:05 +00006653TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006654 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006655 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006656 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006657 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006658
6659 // Transform arguments.
6660 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006661 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006662 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006663 &ArgChanged))
6664 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006665
Douglas Gregorb98b1992009-08-11 05:31:07 +00006666 if (!getDerived().AlwaysRebuild() &&
6667 Callee.get() == E->getCallee() &&
6668 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006669 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006670
Douglas Gregorb98b1992009-08-11 05:31:07 +00006671 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006672 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006673 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006674 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006675 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006676 E->getRParenLoc());
6677}
Mike Stump1eb44332009-09-09 15:08:12 +00006678
6679template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006680ExprResult
John McCall454feb92009-12-08 09:21:05 +00006681TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006682 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006683 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006684 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006685
Douglas Gregor40d96a62011-02-28 21:54:11 +00006686 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006687 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006688 QualifierLoc
6689 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006690
Douglas Gregor40d96a62011-02-28 21:54:11 +00006691 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006692 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006693 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006694 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006695
Eli Friedmanf595cc42009-12-04 06:40:45 +00006696 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006697 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6698 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006699 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006700 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006701
John McCall6bb80172010-03-30 21:47:33 +00006702 NamedDecl *FoundDecl = E->getFoundDecl();
6703 if (FoundDecl == E->getMemberDecl()) {
6704 FoundDecl = Member;
6705 } else {
6706 FoundDecl = cast_or_null<NamedDecl>(
6707 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6708 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006709 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006710 }
6711
Douglas Gregorb98b1992009-08-11 05:31:07 +00006712 if (!getDerived().AlwaysRebuild() &&
6713 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006714 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006715 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006716 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006717 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006718
Anders Carlsson1f240322009-12-22 05:24:09 +00006719 // Mark it referenced in the new context regardless.
6720 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006721 SemaRef.MarkMemberReferenced(E);
6722
John McCall3fa5cae2010-10-26 07:05:15 +00006723 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006724 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006725
John McCalld5532b62009-11-23 01:53:49 +00006726 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006727 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006728 TransArgs.setLAngleLoc(E->getLAngleLoc());
6729 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006730 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6731 E->getNumTemplateArgs(),
6732 TransArgs))
6733 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006734 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006735
Douglas Gregorb98b1992009-08-11 05:31:07 +00006736 // FIXME: Bogus source location for the operator
6737 SourceLocation FakeOperatorLoc
6738 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6739
John McCallc2233c52010-01-15 08:34:02 +00006740 // FIXME: to do this check properly, we will need to preserve the
6741 // first-qualifier-in-scope here, just in case we had a dependent
6742 // base (and therefore couldn't do the check) and a
6743 // nested-name-qualifier (and therefore could do the lookup).
6744 NamedDecl *FirstQualifierInScope = 0;
6745
John McCall9ae2f072010-08-23 23:25:46 +00006746 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006747 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006748 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006749 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006750 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006751 Member,
John McCall6bb80172010-03-30 21:47:33 +00006752 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006753 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006754 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006755 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006756}
Mike Stump1eb44332009-09-09 15:08:12 +00006757
Douglas Gregorb98b1992009-08-11 05:31:07 +00006758template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006759ExprResult
John McCall454feb92009-12-08 09:21:05 +00006760TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006761 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006762 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006763 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006764
John McCall60d7b3a2010-08-24 06:29:42 +00006765 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006766 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006767 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006768
Douglas Gregorb98b1992009-08-11 05:31:07 +00006769 if (!getDerived().AlwaysRebuild() &&
6770 LHS.get() == E->getLHS() &&
6771 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006772 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006773
Lang Hamesbe9af122012-10-02 04:45:10 +00006774 Sema::FPContractStateRAII FPContractState(getSema());
6775 getSema().FPFeatures.fp_contract = E->isFPContractable();
6776
Douglas Gregorb98b1992009-08-11 05:31:07 +00006777 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006778 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006779}
6780
Mike Stump1eb44332009-09-09 15:08:12 +00006781template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006782ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006783TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006784 CompoundAssignOperator *E) {
6785 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006786}
Mike Stump1eb44332009-09-09 15:08:12 +00006787
Douglas Gregorb98b1992009-08-11 05:31:07 +00006788template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006789ExprResult TreeTransform<Derived>::
6790TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6791 // Just rebuild the common and RHS expressions and see whether we
6792 // get any changes.
6793
6794 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6795 if (commonExpr.isInvalid())
6796 return ExprError();
6797
6798 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6799 if (rhs.isInvalid())
6800 return ExprError();
6801
6802 if (!getDerived().AlwaysRebuild() &&
6803 commonExpr.get() == e->getCommon() &&
6804 rhs.get() == e->getFalseExpr())
6805 return SemaRef.Owned(e);
6806
6807 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6808 e->getQuestionLoc(),
6809 0,
6810 e->getColonLoc(),
6811 rhs.get());
6812}
6813
6814template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006815ExprResult
John McCall454feb92009-12-08 09:21:05 +00006816TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006817 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006818 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006819 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006820
John McCall60d7b3a2010-08-24 06:29:42 +00006821 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006822 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006823 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006824
John McCall60d7b3a2010-08-24 06:29:42 +00006825 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006826 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006827 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006828
Douglas Gregorb98b1992009-08-11 05:31:07 +00006829 if (!getDerived().AlwaysRebuild() &&
6830 Cond.get() == E->getCond() &&
6831 LHS.get() == E->getLHS() &&
6832 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006833 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006834
John McCall9ae2f072010-08-23 23:25:46 +00006835 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006836 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006837 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006838 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006839 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006840}
Mike Stump1eb44332009-09-09 15:08:12 +00006841
6842template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006843ExprResult
John McCall454feb92009-12-08 09:21:05 +00006844TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006845 // Implicit casts are eliminated during transformation, since they
6846 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006847 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006848}
Mike Stump1eb44332009-09-09 15:08:12 +00006849
Douglas Gregorb98b1992009-08-11 05:31:07 +00006850template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006851ExprResult
John McCall454feb92009-12-08 09:21:05 +00006852TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006853 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6854 if (!Type)
6855 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006856
John McCall60d7b3a2010-08-24 06:29:42 +00006857 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006858 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006859 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006860 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006861
Douglas Gregorb98b1992009-08-11 05:31:07 +00006862 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006863 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006864 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006865 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006866
John McCall9d125032010-01-15 18:39:57 +00006867 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006868 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006869 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006870 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006871}
Mike Stump1eb44332009-09-09 15:08:12 +00006872
Douglas Gregorb98b1992009-08-11 05:31:07 +00006873template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006874ExprResult
John McCall454feb92009-12-08 09:21:05 +00006875TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006876 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6877 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6878 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006879 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006880
John McCall60d7b3a2010-08-24 06:29:42 +00006881 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006882 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006883 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006884
Douglas Gregorb98b1992009-08-11 05:31:07 +00006885 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006886 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006887 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006888 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006889
John McCall1d7d8d62010-01-19 22:33:45 +00006890 // Note: the expression type doesn't necessarily match the
6891 // type-as-written, but that's okay, because it should always be
6892 // derivable from the initializer.
6893
John McCall42f56b52010-01-18 19:35:47 +00006894 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006895 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006896 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006897}
Mike Stump1eb44332009-09-09 15:08:12 +00006898
Douglas Gregorb98b1992009-08-11 05:31:07 +00006899template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006900ExprResult
John McCall454feb92009-12-08 09:21:05 +00006901TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006902 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006903 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006904 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006905
Douglas Gregorb98b1992009-08-11 05:31:07 +00006906 if (!getDerived().AlwaysRebuild() &&
6907 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006908 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006909
Douglas Gregorb98b1992009-08-11 05:31:07 +00006910 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006911 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006912 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006913 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006914 E->getAccessorLoc(),
6915 E->getAccessor());
6916}
Mike Stump1eb44332009-09-09 15:08:12 +00006917
Douglas Gregorb98b1992009-08-11 05:31:07 +00006918template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006919ExprResult
John McCall454feb92009-12-08 09:21:05 +00006920TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006921 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006922
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006923 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006924 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006925 Inits, &InitChanged))
6926 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006927
Douglas Gregorb98b1992009-08-11 05:31:07 +00006928 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006929 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006930
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006931 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006932 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006933}
Mike Stump1eb44332009-09-09 15:08:12 +00006934
Douglas Gregorb98b1992009-08-11 05:31:07 +00006935template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006936ExprResult
John McCall454feb92009-12-08 09:21:05 +00006937TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006938 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006939
Douglas Gregor43959a92009-08-20 07:17:43 +00006940 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006941 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006942 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006943 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006944
Douglas Gregor43959a92009-08-20 07:17:43 +00006945 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006946 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006947 bool ExprChanged = false;
6948 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6949 DEnd = E->designators_end();
6950 D != DEnd; ++D) {
6951 if (D->isFieldDesignator()) {
6952 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6953 D->getDotLoc(),
6954 D->getFieldLoc()));
6955 continue;
6956 }
Mike Stump1eb44332009-09-09 15:08:12 +00006957
Douglas Gregorb98b1992009-08-11 05:31:07 +00006958 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006959 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006960 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006961 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006962
6963 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006964 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006965
Douglas Gregorb98b1992009-08-11 05:31:07 +00006966 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6967 ArrayExprs.push_back(Index.release());
6968 continue;
6969 }
Mike Stump1eb44332009-09-09 15:08:12 +00006970
Douglas Gregorb98b1992009-08-11 05:31:07 +00006971 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006972 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006973 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6974 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006975 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006976
John McCall60d7b3a2010-08-24 06:29:42 +00006977 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006978 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006979 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006980
6981 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006982 End.get(),
6983 D->getLBracketLoc(),
6984 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006985
Douglas Gregorb98b1992009-08-11 05:31:07 +00006986 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6987 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006988
Douglas Gregorb98b1992009-08-11 05:31:07 +00006989 ArrayExprs.push_back(Start.release());
6990 ArrayExprs.push_back(End.release());
6991 }
Mike Stump1eb44332009-09-09 15:08:12 +00006992
Douglas Gregorb98b1992009-08-11 05:31:07 +00006993 if (!getDerived().AlwaysRebuild() &&
6994 Init.get() == E->getInit() &&
6995 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006996 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006997
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006998 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006999 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007000 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007001}
Mike Stump1eb44332009-09-09 15:08:12 +00007002
Douglas Gregorb98b1992009-08-11 05:31:07 +00007003template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007004ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007005TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00007006 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00007007 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007008
Douglas Gregor5557b252009-10-28 00:29:27 +00007009 // FIXME: Will we ever have proper type location here? Will we actually
7010 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00007011 QualType T = getDerived().TransformType(E->getType());
7012 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007013 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007014
Douglas Gregorb98b1992009-08-11 05:31:07 +00007015 if (!getDerived().AlwaysRebuild() &&
7016 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00007017 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007018
Douglas Gregorb98b1992009-08-11 05:31:07 +00007019 return getDerived().RebuildImplicitValueInitExpr(T);
7020}
Mike Stump1eb44332009-09-09 15:08:12 +00007021
Douglas Gregorb98b1992009-08-11 05:31:07 +00007022template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007023ExprResult
John McCall454feb92009-12-08 09:21:05 +00007024TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00007025 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7026 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007027 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007028
John McCall60d7b3a2010-08-24 06:29:42 +00007029 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007030 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007031 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007032
Douglas Gregorb98b1992009-08-11 05:31:07 +00007033 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007034 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007035 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007036 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007037
John McCall9ae2f072010-08-23 23:25:46 +00007038 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007039 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007040}
7041
7042template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007043ExprResult
John McCall454feb92009-12-08 09:21:05 +00007044TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007045 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007046 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00007047 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7048 &ArgumentChanged))
7049 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007050
Douglas Gregorb98b1992009-08-11 05:31:07 +00007051 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007052 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007053 E->getRParenLoc());
7054}
Mike Stump1eb44332009-09-09 15:08:12 +00007055
Douglas Gregorb98b1992009-08-11 05:31:07 +00007056/// \brief Transform an address-of-label expression.
7057///
7058/// By default, the transformation of an address-of-label expression always
7059/// rebuilds the expression, so that the label identifier can be resolved to
7060/// the corresponding label statement by semantic analysis.
7061template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007062ExprResult
John McCall454feb92009-12-08 09:21:05 +00007063TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00007064 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7065 E->getLabel());
7066 if (!LD)
7067 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007068
Douglas Gregorb98b1992009-08-11 05:31:07 +00007069 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00007070 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007071}
Mike Stump1eb44332009-09-09 15:08:12 +00007072
7073template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00007074ExprResult
John McCall454feb92009-12-08 09:21:05 +00007075TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00007076 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00007077 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00007078 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00007079 if (SubStmt.isInvalid()) {
7080 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00007081 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00007082 }
Mike Stump1eb44332009-09-09 15:08:12 +00007083
Douglas Gregorb98b1992009-08-11 05:31:07 +00007084 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00007085 SubStmt.get() == E->getSubStmt()) {
7086 // Calling this an 'error' is unintuitive, but it does the right thing.
7087 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00007088 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00007089 }
Mike Stump1eb44332009-09-09 15:08:12 +00007090
7091 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007092 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007093 E->getRParenLoc());
7094}
Mike Stump1eb44332009-09-09 15:08:12 +00007095
Douglas Gregorb98b1992009-08-11 05:31:07 +00007096template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007097ExprResult
John McCall454feb92009-12-08 09:21:05 +00007098TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007099 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007100 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007101 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007102
John McCall60d7b3a2010-08-24 06:29:42 +00007103 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007104 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007105 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007106
John McCall60d7b3a2010-08-24 06:29:42 +00007107 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007108 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007109 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007110
Douglas Gregorb98b1992009-08-11 05:31:07 +00007111 if (!getDerived().AlwaysRebuild() &&
7112 Cond.get() == E->getCond() &&
7113 LHS.get() == E->getLHS() &&
7114 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00007115 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007116
Douglas Gregorb98b1992009-08-11 05:31:07 +00007117 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007118 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007119 E->getRParenLoc());
7120}
Mike Stump1eb44332009-09-09 15:08:12 +00007121
Douglas Gregorb98b1992009-08-11 05:31:07 +00007122template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007123ExprResult
John McCall454feb92009-12-08 09:21:05 +00007124TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007125 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007126}
7127
7128template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007129ExprResult
John McCall454feb92009-12-08 09:21:05 +00007130TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00007131 switch (E->getOperator()) {
7132 case OO_New:
7133 case OO_Delete:
7134 case OO_Array_New:
7135 case OO_Array_Delete:
7136 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00007137
Douglas Gregor668d6d92009-12-13 20:44:55 +00007138 case OO_Call: {
7139 // This is a call to an object's operator().
7140 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7141
7142 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00007143 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00007144 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007145 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007146
7147 // FIXME: Poor location information
7148 SourceLocation FakeLParenLoc
7149 = SemaRef.PP.getLocForEndOfToken(
7150 static_cast<Expr *>(Object.get())->getLocEnd());
7151
7152 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007153 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007154 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007155 Args))
7156 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007157
John McCall9ae2f072010-08-23 23:25:46 +00007158 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007159 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00007160 E->getLocEnd());
7161 }
7162
7163#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7164 case OO_##Name:
7165#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7166#include "clang/Basic/OperatorKinds.def"
7167 case OO_Subscript:
7168 // Handled below.
7169 break;
7170
7171 case OO_Conditional:
7172 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007173
7174 case OO_None:
7175 case NUM_OVERLOADED_OPERATORS:
7176 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007177 }
7178
John McCall60d7b3a2010-08-24 06:29:42 +00007179 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007180 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007181 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007182
Richard Smithefeeccf2012-10-21 03:28:35 +00007183 ExprResult First;
7184 if (E->getOperator() == OO_Amp)
7185 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7186 else
7187 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007188 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007189 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007190
John McCall60d7b3a2010-08-24 06:29:42 +00007191 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007192 if (E->getNumArgs() == 2) {
7193 Second = getDerived().TransformExpr(E->getArg(1));
7194 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007195 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007196 }
Mike Stump1eb44332009-09-09 15:08:12 +00007197
Douglas Gregorb98b1992009-08-11 05:31:07 +00007198 if (!getDerived().AlwaysRebuild() &&
7199 Callee.get() == E->getCallee() &&
7200 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00007201 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00007202 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007203
Lang Hamesbe9af122012-10-02 04:45:10 +00007204 Sema::FPContractStateRAII FPContractState(getSema());
7205 getSema().FPFeatures.fp_contract = E->isFPContractable();
7206
Douglas Gregorb98b1992009-08-11 05:31:07 +00007207 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7208 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007209 Callee.get(),
7210 First.get(),
7211 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007212}
Mike Stump1eb44332009-09-09 15:08:12 +00007213
Douglas Gregorb98b1992009-08-11 05:31:07 +00007214template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007215ExprResult
John McCall454feb92009-12-08 09:21:05 +00007216TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7217 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007218}
Mike Stump1eb44332009-09-09 15:08:12 +00007219
Douglas Gregorb98b1992009-08-11 05:31:07 +00007220template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007221ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00007222TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7223 // Transform the callee.
7224 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7225 if (Callee.isInvalid())
7226 return ExprError();
7227
7228 // Transform exec config.
7229 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7230 if (EC.isInvalid())
7231 return ExprError();
7232
7233 // Transform arguments.
7234 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007235 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007236 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007237 &ArgChanged))
7238 return ExprError();
7239
7240 if (!getDerived().AlwaysRebuild() &&
7241 Callee.get() == E->getCallee() &&
7242 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007243 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00007244
7245 // FIXME: Wrong source location information for the '('.
7246 SourceLocation FakeLParenLoc
7247 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7248 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007249 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007250 E->getRParenLoc(), EC.get());
7251}
7252
7253template<typename Derived>
7254ExprResult
John McCall454feb92009-12-08 09:21:05 +00007255TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007256 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7257 if (!Type)
7258 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007259
John McCall60d7b3a2010-08-24 06:29:42 +00007260 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007261 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007262 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007263 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007264
Douglas Gregorb98b1992009-08-11 05:31:07 +00007265 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007266 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007267 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007268 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007269 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007270 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007271 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007272 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007273 E->getAngleBrackets().getEnd(),
7274 // FIXME. this should be '(' location
7275 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007276 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007277 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007278}
Mike Stump1eb44332009-09-09 15:08:12 +00007279
Douglas Gregorb98b1992009-08-11 05:31:07 +00007280template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007281ExprResult
John McCall454feb92009-12-08 09:21:05 +00007282TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7283 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007284}
Mike Stump1eb44332009-09-09 15:08:12 +00007285
7286template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007287ExprResult
John McCall454feb92009-12-08 09:21:05 +00007288TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7289 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007290}
7291
Douglas Gregorb98b1992009-08-11 05:31:07 +00007292template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007293ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007294TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007295 CXXReinterpretCastExpr *E) {
7296 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007297}
Mike Stump1eb44332009-09-09 15:08:12 +00007298
Douglas Gregorb98b1992009-08-11 05:31:07 +00007299template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007300ExprResult
John McCall454feb92009-12-08 09:21:05 +00007301TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7302 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007303}
Mike Stump1eb44332009-09-09 15:08:12 +00007304
Douglas Gregorb98b1992009-08-11 05:31:07 +00007305template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007306ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007307TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007308 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007309 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7310 if (!Type)
7311 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007312
John McCall60d7b3a2010-08-24 06:29:42 +00007313 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007314 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007315 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007316 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007317
Douglas Gregorb98b1992009-08-11 05:31:07 +00007318 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007319 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007320 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007321 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007322
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007323 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedmancdd4b782013-08-15 22:02:56 +00007324 E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007325 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007326 E->getRParenLoc());
7327}
Mike Stump1eb44332009-09-09 15:08:12 +00007328
Douglas Gregorb98b1992009-08-11 05:31:07 +00007329template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007330ExprResult
John McCall454feb92009-12-08 09:21:05 +00007331TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007332 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007333 TypeSourceInfo *TInfo
7334 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7335 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007336 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007337
Douglas Gregorb98b1992009-08-11 05:31:07 +00007338 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007339 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007340 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007341
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007342 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7343 E->getLocStart(),
7344 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007345 E->getLocEnd());
7346 }
Mike Stump1eb44332009-09-09 15:08:12 +00007347
Eli Friedmanef331b72012-01-20 01:26:23 +00007348 // We don't know whether the subexpression is potentially evaluated until
7349 // after we perform semantic analysis. We speculatively assume it is
7350 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007351 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007352 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7353 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007354
John McCall60d7b3a2010-08-24 06:29:42 +00007355 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007356 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007357 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007358
Douglas Gregorb98b1992009-08-11 05:31:07 +00007359 if (!getDerived().AlwaysRebuild() &&
7360 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007361 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007362
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007363 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7364 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007365 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007366 E->getLocEnd());
7367}
7368
7369template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007370ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007371TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7372 if (E->isTypeOperand()) {
7373 TypeSourceInfo *TInfo
7374 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7375 if (!TInfo)
7376 return ExprError();
7377
7378 if (!getDerived().AlwaysRebuild() &&
7379 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007380 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007381
Douglas Gregor3c52a212011-03-06 17:40:41 +00007382 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007383 E->getLocStart(),
7384 TInfo,
7385 E->getLocEnd());
7386 }
7387
Francois Pichet01b7c302010-09-08 12:20:18 +00007388 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7389
7390 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7391 if (SubExpr.isInvalid())
7392 return ExprError();
7393
7394 if (!getDerived().AlwaysRebuild() &&
7395 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007396 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007397
7398 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7399 E->getLocStart(),
7400 SubExpr.get(),
7401 E->getLocEnd());
7402}
7403
7404template<typename Derived>
7405ExprResult
John McCall454feb92009-12-08 09:21:05 +00007406TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007407 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007408}
Mike Stump1eb44332009-09-09 15:08:12 +00007409
Douglas Gregorb98b1992009-08-11 05:31:07 +00007410template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007411ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007412TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007413 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007414 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007415}
Mike Stump1eb44332009-09-09 15:08:12 +00007416
Douglas Gregorb98b1992009-08-11 05:31:07 +00007417template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007418ExprResult
John McCall454feb92009-12-08 09:21:05 +00007419TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithcafeb942013-06-07 02:33:37 +00007420 QualType T = getSema().getCurrentThisType();
Mike Stump1eb44332009-09-09 15:08:12 +00007421
Douglas Gregorec79d872012-02-24 17:41:38 +00007422 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7423 // Make sure that we capture 'this'.
7424 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007425 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007426 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007427
Douglas Gregor828a1972010-01-07 23:12:05 +00007428 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007429}
Mike Stump1eb44332009-09-09 15:08:12 +00007430
Douglas Gregorb98b1992009-08-11 05:31:07 +00007431template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007432ExprResult
John McCall454feb92009-12-08 09:21:05 +00007433TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007434 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007435 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007436 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007437
Douglas Gregorb98b1992009-08-11 05:31:07 +00007438 if (!getDerived().AlwaysRebuild() &&
7439 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007440 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007441
Douglas Gregorbca01b42011-07-06 22:04:06 +00007442 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7443 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007444}
Mike Stump1eb44332009-09-09 15:08:12 +00007445
Douglas Gregorb98b1992009-08-11 05:31:07 +00007446template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007447ExprResult
John McCall454feb92009-12-08 09:21:05 +00007448TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007449 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007450 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7451 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007452 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007453 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007454
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007455 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007456 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007457 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007458
Douglas Gregor036aed12009-12-23 23:03:06 +00007459 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007460}
Mike Stump1eb44332009-09-09 15:08:12 +00007461
Douglas Gregorb98b1992009-08-11 05:31:07 +00007462template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007463ExprResult
Richard Smithc3bf52c2013-04-20 22:23:05 +00007464TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7465 FieldDecl *Field
7466 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7467 E->getField()));
7468 if (!Field)
7469 return ExprError();
7470
7471 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7472 return SemaRef.Owned(E);
7473
7474 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7475}
7476
7477template<typename Derived>
7478ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007479TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7480 CXXScalarValueInitExpr *E) {
7481 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7482 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007483 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007484
Douglas Gregorb98b1992009-08-11 05:31:07 +00007485 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007486 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007487 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007488
Chad Rosier4a9d7952012-08-08 18:46:20 +00007489 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007490 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007491 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007492}
Mike Stump1eb44332009-09-09 15:08:12 +00007493
Douglas Gregorb98b1992009-08-11 05:31:07 +00007494template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007495ExprResult
John McCall454feb92009-12-08 09:21:05 +00007496TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007497 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007498 TypeSourceInfo *AllocTypeInfo
7499 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7500 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007501 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007502
Douglas Gregorb98b1992009-08-11 05:31:07 +00007503 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007504 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007505 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007506 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007507
Douglas Gregorb98b1992009-08-11 05:31:07 +00007508 // Transform the placement arguments (if any).
7509 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007510 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007511 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007512 E->getNumPlacementArgs(), true,
7513 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007514 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007515
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007516 // Transform the initializer (if any).
7517 Expr *OldInit = E->getInitializer();
7518 ExprResult NewInit;
7519 if (OldInit)
7520 NewInit = getDerived().TransformExpr(OldInit);
7521 if (NewInit.isInvalid())
7522 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007523
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007524 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007525 FunctionDecl *OperatorNew = 0;
7526 if (E->getOperatorNew()) {
7527 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007528 getDerived().TransformDecl(E->getLocStart(),
7529 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007530 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007531 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007532 }
7533
7534 FunctionDecl *OperatorDelete = 0;
7535 if (E->getOperatorDelete()) {
7536 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007537 getDerived().TransformDecl(E->getLocStart(),
7538 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007539 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007540 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007541 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007542
Douglas Gregorb98b1992009-08-11 05:31:07 +00007543 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007544 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007545 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007546 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007547 OperatorNew == E->getOperatorNew() &&
7548 OperatorDelete == E->getOperatorDelete() &&
7549 !ArgumentChanged) {
7550 // Mark any declarations we need as referenced.
7551 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007552 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007553 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007554 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007555 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007556
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007557 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007558 QualType ElementType
7559 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7560 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7561 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7562 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007563 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007564 }
7565 }
7566 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007567
John McCall3fa5cae2010-10-26 07:05:15 +00007568 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007569 }
Mike Stump1eb44332009-09-09 15:08:12 +00007570
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007571 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007572 if (!ArraySize.get()) {
7573 // If no array size was specified, but the new expression was
7574 // instantiated with an array type (e.g., "new T" where T is
7575 // instantiated with "int[4]"), extract the outer bound from the
7576 // array type as our array size. We do this with constant and
7577 // dependently-sized array types.
7578 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7579 if (!ArrayT) {
7580 // Do nothing
7581 } else if (const ConstantArrayType *ConsArrayT
7582 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007583 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007584 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007585 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007586 SemaRef.Context.getSizeType(),
7587 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007588 AllocType = ConsArrayT->getElementType();
7589 } else if (const DependentSizedArrayType *DepArrayT
7590 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7591 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007592 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007593 AllocType = DepArrayT->getElementType();
7594 }
7595 }
7596 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007597
Douglas Gregorb98b1992009-08-11 05:31:07 +00007598 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7599 E->isGlobalNew(),
7600 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007601 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007602 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007603 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007604 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007605 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007606 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007607 E->getDirectInitRange(),
7608 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007609}
Mike Stump1eb44332009-09-09 15:08:12 +00007610
Douglas Gregorb98b1992009-08-11 05:31:07 +00007611template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007612ExprResult
John McCall454feb92009-12-08 09:21:05 +00007613TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007614 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007615 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007616 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007617
Douglas Gregor1af74512010-02-26 00:38:10 +00007618 // Transform the delete operator, if known.
7619 FunctionDecl *OperatorDelete = 0;
7620 if (E->getOperatorDelete()) {
7621 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007622 getDerived().TransformDecl(E->getLocStart(),
7623 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007624 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007625 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007626 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007627
Douglas Gregorb98b1992009-08-11 05:31:07 +00007628 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007629 Operand.get() == E->getArgument() &&
7630 OperatorDelete == E->getOperatorDelete()) {
7631 // Mark any declarations we need as referenced.
7632 // FIXME: instantiation-specific.
7633 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007634 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007635
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007636 if (!E->getArgument()->isTypeDependent()) {
7637 QualType Destroyed = SemaRef.Context.getBaseElementType(
7638 E->getDestroyedType());
7639 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7640 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007641 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007642 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007643 }
7644 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007645
John McCall3fa5cae2010-10-26 07:05:15 +00007646 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007647 }
Mike Stump1eb44332009-09-09 15:08:12 +00007648
Douglas Gregorb98b1992009-08-11 05:31:07 +00007649 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7650 E->isGlobalDelete(),
7651 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007652 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007653}
Mike Stump1eb44332009-09-09 15:08:12 +00007654
Douglas Gregorb98b1992009-08-11 05:31:07 +00007655template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007656ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007657TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007658 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007659 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007660 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007661 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007662
John McCallb3d87482010-08-24 05:47:05 +00007663 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007664 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007665 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007666 E->getOperatorLoc(),
7667 E->isArrow()? tok::arrow : tok::period,
7668 ObjectTypePtr,
7669 MayBePseudoDestructor);
7670 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007671 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007672
John McCallb3d87482010-08-24 05:47:05 +00007673 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007674 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7675 if (QualifierLoc) {
7676 QualifierLoc
7677 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7678 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007679 return ExprError();
7680 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007681 CXXScopeSpec SS;
7682 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007683
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007684 PseudoDestructorTypeStorage Destroyed;
7685 if (E->getDestroyedTypeInfo()) {
7686 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007687 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007688 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007689 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007690 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007691 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007692 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007693 // We aren't likely to be able to resolve the identifier down to a type
7694 // now anyway, so just retain the identifier.
7695 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7696 E->getDestroyedTypeLoc());
7697 } else {
7698 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007699 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007700 *E->getDestroyedTypeIdentifier(),
7701 E->getDestroyedTypeLoc(),
7702 /*Scope=*/0,
7703 SS, ObjectTypePtr,
7704 false);
7705 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007706 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007707
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007708 Destroyed
7709 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7710 E->getDestroyedTypeLoc());
7711 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007712
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007713 TypeSourceInfo *ScopeTypeInfo = 0;
7714 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007715 CXXScopeSpec EmptySS;
7716 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7717 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007718 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007719 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007720 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007721
John McCall9ae2f072010-08-23 23:25:46 +00007722 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007723 E->getOperatorLoc(),
7724 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007725 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007726 ScopeTypeInfo,
7727 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007728 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007729 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007730}
Mike Stump1eb44332009-09-09 15:08:12 +00007731
Douglas Gregora71d8192009-09-04 17:36:40 +00007732template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007733ExprResult
John McCallba135432009-11-21 08:51:07 +00007734TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007735 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007736 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7737 Sema::LookupOrdinaryName);
7738
7739 // Transform all the decls.
7740 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7741 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007742 NamedDecl *InstD = static_cast<NamedDecl*>(
7743 getDerived().TransformDecl(Old->getNameLoc(),
7744 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007745 if (!InstD) {
7746 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7747 // This can happen because of dependent hiding.
7748 if (isa<UsingShadowDecl>(*I))
7749 continue;
7750 else
John McCallf312b1e2010-08-26 23:41:50 +00007751 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007752 }
John McCallf7a1a742009-11-24 19:00:30 +00007753
7754 // Expand using declarations.
7755 if (isa<UsingDecl>(InstD)) {
7756 UsingDecl *UD = cast<UsingDecl>(InstD);
7757 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7758 E = UD->shadow_end(); I != E; ++I)
7759 R.addDecl(*I);
7760 continue;
7761 }
7762
7763 R.addDecl(InstD);
7764 }
7765
7766 // Resolve a kind, but don't do any further analysis. If it's
7767 // ambiguous, the callee needs to deal with it.
7768 R.resolveKind();
7769
7770 // Rebuild the nested-name qualifier, if present.
7771 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007772 if (Old->getQualifierLoc()) {
7773 NestedNameSpecifierLoc QualifierLoc
7774 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7775 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007776 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007777
Douglas Gregor4c9be892011-02-28 20:01:57 +00007778 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007779 }
7780
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007781 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007782 CXXRecordDecl *NamingClass
7783 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7784 Old->getNameLoc(),
7785 Old->getNamingClass()));
7786 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007787 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007788
Douglas Gregor66c45152010-04-27 16:10:10 +00007789 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007790 }
7791
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007792 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7793
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007794 // If we have neither explicit template arguments, nor the template keyword,
7795 // it's a normal declaration name.
7796 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007797 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7798
7799 // If we have template arguments, rebuild them, then rebuild the
7800 // templateid expression.
7801 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007802 if (Old->hasExplicitTemplateArgs() &&
7803 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007804 Old->getNumTemplateArgs(),
7805 TransArgs))
7806 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007807
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007808 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007809 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007810}
Mike Stump1eb44332009-09-09 15:08:12 +00007811
Douglas Gregorb98b1992009-08-11 05:31:07 +00007812template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007813ExprResult
John McCall454feb92009-12-08 09:21:05 +00007814TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007815 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7816 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007817 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007818
Douglas Gregorb98b1992009-08-11 05:31:07 +00007819 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007820 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007821 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007822
Mike Stump1eb44332009-09-09 15:08:12 +00007823 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007824 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007825 T,
7826 E->getLocEnd());
7827}
Mike Stump1eb44332009-09-09 15:08:12 +00007828
Douglas Gregorb98b1992009-08-11 05:31:07 +00007829template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007830ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007831TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7832 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7833 if (!LhsT)
7834 return ExprError();
7835
7836 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7837 if (!RhsT)
7838 return ExprError();
7839
7840 if (!getDerived().AlwaysRebuild() &&
7841 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7842 return SemaRef.Owned(E);
7843
7844 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7845 E->getLocStart(),
7846 LhsT, RhsT,
7847 E->getLocEnd());
7848}
7849
7850template<typename Derived>
7851ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007852TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7853 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007854 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007855 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7856 TypeSourceInfo *From = E->getArg(I);
7857 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007858 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007859 TypeLocBuilder TLB;
7860 TLB.reserve(FromTL.getFullDataSize());
7861 QualType To = getDerived().TransformType(TLB, FromTL);
7862 if (To.isNull())
7863 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007864
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007865 if (To == From->getType())
7866 Args.push_back(From);
7867 else {
7868 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7869 ArgChanged = true;
7870 }
7871 continue;
7872 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007873
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007874 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007875
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007876 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007877 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007878 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7879 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7880 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007881
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007882 // Determine whether the set of unexpanded parameter packs can and should
7883 // be expanded.
7884 bool Expand = true;
7885 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007886 Optional<unsigned> OrigNumExpansions =
7887 ExpansionTL.getTypePtr()->getNumExpansions();
7888 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007889 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7890 PatternTL.getSourceRange(),
7891 Unexpanded,
7892 Expand, RetainExpansion,
7893 NumExpansions))
7894 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007895
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007896 if (!Expand) {
7897 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007898 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007899 // expansion.
7900 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007901
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007902 TypeLocBuilder TLB;
7903 TLB.reserve(From->getTypeLoc().getFullDataSize());
7904
7905 QualType To = getDerived().TransformType(TLB, PatternTL);
7906 if (To.isNull())
7907 return ExprError();
7908
Chad Rosier4a9d7952012-08-08 18:46:20 +00007909 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007910 PatternTL.getSourceRange(),
7911 ExpansionTL.getEllipsisLoc(),
7912 NumExpansions);
7913 if (To.isNull())
7914 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007915
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007916 PackExpansionTypeLoc ToExpansionTL
7917 = TLB.push<PackExpansionTypeLoc>(To);
7918 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7919 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7920 continue;
7921 }
7922
7923 // Expand the pack expansion by substituting for each argument in the
7924 // pack(s).
7925 for (unsigned I = 0; I != *NumExpansions; ++I) {
7926 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7927 TypeLocBuilder TLB;
7928 TLB.reserve(PatternTL.getFullDataSize());
7929 QualType To = getDerived().TransformType(TLB, PatternTL);
7930 if (To.isNull())
7931 return ExprError();
7932
Eli Friedman20cfeca2013-07-19 21:49:32 +00007933 if (To->containsUnexpandedParameterPack()) {
7934 To = getDerived().RebuildPackExpansionType(To,
7935 PatternTL.getSourceRange(),
7936 ExpansionTL.getEllipsisLoc(),
7937 NumExpansions);
7938 if (To.isNull())
7939 return ExprError();
7940
7941 PackExpansionTypeLoc ToExpansionTL
7942 = TLB.push<PackExpansionTypeLoc>(To);
7943 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7944 }
7945
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007946 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7947 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007948
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007949 if (!RetainExpansion)
7950 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007951
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007952 // If we're supposed to retain a pack expansion, do so by temporarily
7953 // forgetting the partially-substituted parameter pack.
7954 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7955
7956 TypeLocBuilder TLB;
7957 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007958
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007959 QualType To = getDerived().TransformType(TLB, PatternTL);
7960 if (To.isNull())
7961 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007962
7963 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 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007975
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007976 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7977 return SemaRef.Owned(E);
7978
7979 return getDerived().RebuildTypeTrait(E->getTrait(),
7980 E->getLocStart(),
7981 Args,
7982 E->getLocEnd());
7983}
7984
7985template<typename Derived>
7986ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007987TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7988 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7989 if (!T)
7990 return ExprError();
7991
7992 if (!getDerived().AlwaysRebuild() &&
7993 T == E->getQueriedTypeSourceInfo())
7994 return SemaRef.Owned(E);
7995
7996 ExprResult SubExpr;
7997 {
7998 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7999 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8000 if (SubExpr.isInvalid())
8001 return ExprError();
8002
8003 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8004 return SemaRef.Owned(E);
8005 }
8006
8007 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8008 E->getLocStart(),
8009 T,
8010 SubExpr.get(),
8011 E->getLocEnd());
8012}
8013
8014template<typename Derived>
8015ExprResult
John Wiegley55262202011-04-25 06:54:41 +00008016TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8017 ExprResult SubExpr;
8018 {
8019 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8020 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8021 if (SubExpr.isInvalid())
8022 return ExprError();
8023
8024 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8025 return SemaRef.Owned(E);
8026 }
8027
8028 return getDerived().RebuildExpressionTrait(
8029 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8030}
8031
8032template<typename Derived>
8033ExprResult
John McCall865d4472009-11-19 22:55:06 +00008034TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008035 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00008036 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8037}
8038
8039template<typename Derived>
8040ExprResult
8041TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8042 DependentScopeDeclRefExpr *E,
8043 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008044 NestedNameSpecifierLoc QualifierLoc
8045 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8046 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008047 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008048 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00008049
John McCall43fed0d2010-11-12 08:19:04 +00008050 // TODO: If this is a conversion-function-id, verify that the
8051 // destination type name (if present) resolves the same way after
8052 // instantiation as it did in the local scope.
8053
Abramo Bagnara25777432010-08-11 22:01:17 +00008054 DeclarationNameInfo NameInfo
8055 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8056 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008057 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008058
John McCallf7a1a742009-11-24 19:00:30 +00008059 if (!E->hasExplicitTemplateArgs()) {
8060 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008061 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008062 // Note: it is sufficient to compare the Name component of NameInfo:
8063 // if name has not changed, DNLoc has not changed either.
8064 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00008065 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008066
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008067 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008068 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008069 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008070 /*TemplateArgs*/ 0,
8071 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00008072 }
John McCalld5532b62009-11-23 01:53:49 +00008073
8074 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008075 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8076 E->getNumTemplateArgs(),
8077 TransArgs))
8078 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008079
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008080 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008081 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008082 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008083 &TransArgs,
8084 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008085}
8086
8087template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008088ExprResult
John McCall454feb92009-12-08 09:21:05 +00008089TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00008090 // CXXConstructExprs other than for list-initialization and
8091 // CXXTemporaryObjectExpr are always implicit, so when we have
8092 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00008093 if ((E->getNumArgs() == 1 ||
8094 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00008095 (!getDerived().DropCallArgument(E->getArg(0))) &&
8096 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00008097 return getDerived().TransformExpr(E->getArg(0));
8098
Douglas Gregorb98b1992009-08-11 05:31:07 +00008099 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8100
8101 QualType T = getDerived().TransformType(E->getType());
8102 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00008103 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008104
8105 CXXConstructorDecl *Constructor
8106 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008107 getDerived().TransformDecl(E->getLocStart(),
8108 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008109 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008110 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008111
Douglas Gregorb98b1992009-08-11 05:31:07 +00008112 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008113 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008114 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008115 &ArgumentChanged))
8116 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008117
Douglas Gregorb98b1992009-08-11 05:31:07 +00008118 if (!getDerived().AlwaysRebuild() &&
8119 T == E->getType() &&
8120 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00008121 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00008122 // Mark the constructor as referenced.
8123 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008124 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008125 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00008126 }
Mike Stump1eb44332009-09-09 15:08:12 +00008127
Douglas Gregor4411d2e2009-12-14 16:27:04 +00008128 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8129 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008130 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00008131 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00008132 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00008133 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00008134 E->getConstructionKind(),
8135 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008136}
Mike Stump1eb44332009-09-09 15:08:12 +00008137
Douglas Gregorb98b1992009-08-11 05:31:07 +00008138/// \brief Transform a C++ temporary-binding expression.
8139///
Douglas Gregor51326552009-12-24 18:51:59 +00008140/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8141/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008142template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008143ExprResult
John McCall454feb92009-12-08 09:21:05 +00008144TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008145 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008146}
Mike Stump1eb44332009-09-09 15:08:12 +00008147
John McCall4765fa02010-12-06 08:20:24 +00008148/// \brief Transform a C++ expression that contains cleanups that should
8149/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008150///
John McCall4765fa02010-12-06 08:20:24 +00008151/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00008152/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008153template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008154ExprResult
John McCall4765fa02010-12-06 08:20:24 +00008155TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008156 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008157}
Mike Stump1eb44332009-09-09 15:08:12 +00008158
Douglas Gregorb98b1992009-08-11 05:31:07 +00008159template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008160ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008161TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00008162 CXXTemporaryObjectExpr *E) {
8163 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8164 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008165 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008166
Douglas Gregorb98b1992009-08-11 05:31:07 +00008167 CXXConstructorDecl *Constructor
8168 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008169 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008170 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008171 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008172 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008173
Douglas Gregorb98b1992009-08-11 05:31:07 +00008174 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008175 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00008176 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008177 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008178 &ArgumentChanged))
8179 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008180
Douglas Gregorb98b1992009-08-11 05:31:07 +00008181 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008182 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008183 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00008184 !ArgumentChanged) {
8185 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008186 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008187 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00008188 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008189
Richard Smithc83c2302012-12-19 01:39:02 +00008190 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00008191 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8192 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008193 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008194 E->getLocEnd());
8195}
Mike Stump1eb44332009-09-09 15:08:12 +00008196
Douglas Gregorb98b1992009-08-11 05:31:07 +00008197template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008198ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00008199TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Valiecb58192013-08-22 01:49:11 +00008200
8201 // FIXME: Implement nested generic lambda transformations.
8202 if (E->isGenericLambda()) {
8203 getSema().Diag(E->getIntroducerRange().getBegin(),
8204 diag::err_glambda_not_fully_implemented)
8205 << " nested lambdas not implemented yet";
8206 return ExprError();
8207 }
Douglas Gregordfca6f52012-02-13 22:00:16 +00008208 // Transform the type of the lambda parameters and start the definition of
8209 // the lambda itself.
8210 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00008211 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00008212 if (!MethodTy)
8213 return ExprError();
8214
Eli Friedman8da8a662012-09-19 01:18:11 +00008215 // Create the local class that will describe the lambda.
8216 CXXRecordDecl *Class
8217 = getSema().createLambdaClosureType(E->getIntroducerRange(),
8218 MethodTy,
8219 /*KnownDependent=*/false);
8220 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8221
Douglas Gregorc6889e72012-02-14 22:28:59 +00008222 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008223 SmallVector<QualType, 4> ParamTypes;
8224 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00008225 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
8226 E->getCallOperator()->param_begin(),
8227 E->getCallOperator()->param_size(),
8228 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00008229 return ExprError();
Faisal Valiecb58192013-08-22 01:49:11 +00008230 getSema().PushLambdaScope();
8231 LambdaScopeInfo *LSI = getSema().getCurLambda();
8232 // TODO: Fix for nested lambdas
8233 LSI->GLTemplateParameterList = 0;
Douglas Gregordfca6f52012-02-13 22:00:16 +00008234 // Build the call operator.
8235 CXXMethodDecl *CallOperator
8236 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008237 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00008238 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008239 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008240 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00008241
Richard Smith612409e2012-07-25 03:56:55 +00008242 return getDerived().TransformLambdaScope(E, CallOperator);
8243}
8244
8245template<typename Derived>
8246ExprResult
8247TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8248 CXXMethodDecl *CallOperator) {
Richard Smith0d8e9642013-05-16 06:20:58 +00008249 bool Invalid = false;
8250
8251 // Transform any init-capture expressions before entering the scope of the
8252 // lambda.
Robert Wilhelme7205c02013-08-10 12:33:24 +00008253 SmallVector<ExprResult, 8> InitCaptureExprs;
Richard Smith0d8e9642013-05-16 06:20:58 +00008254 InitCaptureExprs.resize(E->explicit_capture_end() -
8255 E->explicit_capture_begin());
8256 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8257 CEnd = E->capture_end();
8258 C != CEnd; ++C) {
8259 if (!C->isInitCapture())
8260 continue;
8261 InitCaptureExprs[C - E->capture_begin()] =
8262 getDerived().TransformExpr(E->getInitCaptureInit(C));
8263 }
8264
Douglas Gregord5387e82012-02-14 00:00:48 +00008265 // Introduce the context of the call operator.
8266 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8267
Faisal Valiecb58192013-08-22 01:49:11 +00008268 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregordfca6f52012-02-13 22:00:16 +00008269 // Enter the scope of the lambda.
Faisal Valiecb58192013-08-22 01:49:11 +00008270 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008271 E->getCaptureDefault(),
James Dennettf68af642013-08-09 23:08:25 +00008272 E->getCaptureDefaultLoc(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008273 E->hasExplicitParameters(),
8274 E->hasExplicitResultType(),
8275 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008276
Douglas Gregordfca6f52012-02-13 22:00:16 +00008277 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00008278 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008279 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008280 CEnd = E->capture_end();
8281 C != CEnd; ++C) {
8282 // When we hit the first implicit capture, tell Sema that we've finished
8283 // the list of explicit captures.
8284 if (!FinishedExplicitCaptures && C->isImplicit()) {
8285 getSema().finishLambdaExplicitCaptures(LSI);
8286 FinishedExplicitCaptures = true;
8287 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008288
Douglas Gregordfca6f52012-02-13 22:00:16 +00008289 // Capturing 'this' is trivial.
8290 if (C->capturesThis()) {
8291 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8292 continue;
8293 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008294
Richard Smith0d8e9642013-05-16 06:20:58 +00008295 // Rebuild init-captures, including the implied field declaration.
8296 if (C->isInitCapture()) {
8297 ExprResult Init = InitCaptureExprs[C - E->capture_begin()];
8298 if (Init.isInvalid()) {
8299 Invalid = true;
8300 continue;
8301 }
8302 FieldDecl *OldFD = C->getInitCaptureField();
8303 FieldDecl *NewFD = getSema().checkInitCapture(
8304 C->getLocation(), OldFD->getType()->isReferenceType(),
8305 OldFD->getIdentifier(), Init.take());
8306 if (!NewFD)
8307 Invalid = true;
8308 else
8309 getDerived().transformedLocalDecl(OldFD, NewFD);
8310 continue;
8311 }
8312
8313 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8314
Douglas Gregora7365242012-02-14 19:27:52 +00008315 // Determine the capture kind for Sema.
8316 Sema::TryCaptureKind Kind
8317 = C->isImplicit()? Sema::TryCapture_Implicit
8318 : C->getCaptureKind() == LCK_ByCopy
8319 ? Sema::TryCapture_ExplicitByVal
8320 : Sema::TryCapture_ExplicitByRef;
8321 SourceLocation EllipsisLoc;
8322 if (C->isPackExpansion()) {
8323 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8324 bool ShouldExpand = false;
8325 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008326 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008327 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8328 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008329 Unexpanded,
8330 ShouldExpand, RetainExpansion,
Richard Smith0d8e9642013-05-16 06:20:58 +00008331 NumExpansions)) {
8332 Invalid = true;
8333 continue;
8334 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008335
Douglas Gregora7365242012-02-14 19:27:52 +00008336 if (ShouldExpand) {
8337 // The transform has determined that we should perform an expansion;
8338 // transform and capture each of the arguments.
8339 // expansion of the pattern. Do so.
8340 VarDecl *Pack = C->getCapturedVar();
8341 for (unsigned I = 0; I != *NumExpansions; ++I) {
8342 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8343 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008344 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008345 Pack));
8346 if (!CapturedVar) {
8347 Invalid = true;
8348 continue;
8349 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008350
Douglas Gregora7365242012-02-14 19:27:52 +00008351 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008352 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8353 }
Douglas Gregora7365242012-02-14 19:27:52 +00008354 continue;
8355 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008356
Douglas Gregora7365242012-02-14 19:27:52 +00008357 EllipsisLoc = C->getEllipsisLoc();
8358 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008359
Douglas Gregordfca6f52012-02-13 22:00:16 +00008360 // Transform the captured variable.
8361 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008362 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008363 C->getCapturedVar()));
8364 if (!CapturedVar) {
8365 Invalid = true;
8366 continue;
8367 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008368
Douglas Gregordfca6f52012-02-13 22:00:16 +00008369 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008370 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008371 }
8372 if (!FinishedExplicitCaptures)
8373 getSema().finishLambdaExplicitCaptures(LSI);
8374
Douglas Gregordfca6f52012-02-13 22:00:16 +00008375
8376 // Enter a new evaluation context to insulate the lambda from any
8377 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008378 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008379
8380 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008381 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008382 /*IsInstantiation=*/true);
8383 return ExprError();
8384 }
8385
8386 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008387 StmtResult Body = getDerived().TransformStmt(E->getBody());
8388 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008389 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008390 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008391 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008392 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008393
Chad Rosier4a9d7952012-08-08 18:46:20 +00008394 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008395 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008396}
8397
8398template<typename Derived>
8399ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008400TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008401 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008402 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8403 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008404 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008405
Douglas Gregorb98b1992009-08-11 05:31:07 +00008406 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008407 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008408 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008409 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008410 &ArgumentChanged))
8411 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008412
Douglas Gregorb98b1992009-08-11 05:31:07 +00008413 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008414 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008415 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008416 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008417
Douglas Gregorb98b1992009-08-11 05:31:07 +00008418 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008419 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008420 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008421 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008422 E->getRParenLoc());
8423}
Mike Stump1eb44332009-09-09 15:08:12 +00008424
Douglas Gregorb98b1992009-08-11 05:31:07 +00008425template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008426ExprResult
John McCall865d4472009-11-19 22:55:06 +00008427TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008428 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008429 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008430 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008431 Expr *OldBase;
8432 QualType BaseType;
8433 QualType ObjectType;
8434 if (!E->isImplicitAccess()) {
8435 OldBase = E->getBase();
8436 Base = getDerived().TransformExpr(OldBase);
8437 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008438 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008439
John McCallaa81e162009-12-01 22:10:20 +00008440 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008441 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008442 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008443 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008444 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008445 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008446 ObjectTy,
8447 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008448 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008449 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008450
John McCallb3d87482010-08-24 05:47:05 +00008451 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008452 BaseType = ((Expr*) Base.get())->getType();
8453 } else {
8454 OldBase = 0;
8455 BaseType = getDerived().TransformType(E->getBaseType());
8456 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8457 }
Mike Stump1eb44332009-09-09 15:08:12 +00008458
Douglas Gregor6cd21982009-10-20 05:58:46 +00008459 // Transform the first part of the nested-name-specifier that qualifies
8460 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008461 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008462 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008463 E->getFirstQualifierFoundInScope(),
8464 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008465
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008466 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008467 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008468 QualifierLoc
8469 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8470 ObjectType,
8471 FirstQualifierInScope);
8472 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008473 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008474 }
Mike Stump1eb44332009-09-09 15:08:12 +00008475
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008476 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8477
John McCall43fed0d2010-11-12 08:19:04 +00008478 // TODO: If this is a conversion-function-id, verify that the
8479 // destination type name (if present) resolves the same way after
8480 // instantiation as it did in the local scope.
8481
Abramo Bagnara25777432010-08-11 22:01:17 +00008482 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008483 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008484 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008485 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008486
John McCallaa81e162009-12-01 22:10:20 +00008487 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008488 // This is a reference to a member without an explicitly-specified
8489 // template argument list. Optimize for this common case.
8490 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008491 Base.get() == OldBase &&
8492 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008493 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008494 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008495 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008496 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008497
John McCall9ae2f072010-08-23 23:25:46 +00008498 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008499 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008500 E->isArrow(),
8501 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008502 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008503 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008504 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008505 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008506 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008507 }
8508
John McCalld5532b62009-11-23 01:53:49 +00008509 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008510 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8511 E->getNumTemplateArgs(),
8512 TransArgs))
8513 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008514
John McCall9ae2f072010-08-23 23:25:46 +00008515 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008516 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008517 E->isArrow(),
8518 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008519 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008520 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008521 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008522 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008523 &TransArgs);
8524}
8525
8526template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008527ExprResult
John McCall454feb92009-12-08 09:21:05 +00008528TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008529 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008530 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008531 QualType BaseType;
8532 if (!Old->isImplicitAccess()) {
8533 Base = getDerived().TransformExpr(Old->getBase());
8534 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008535 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008536 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8537 Old->isArrow());
8538 if (Base.isInvalid())
8539 return ExprError();
8540 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008541 } else {
8542 BaseType = getDerived().TransformType(Old->getBaseType());
8543 }
John McCall129e2df2009-11-30 22:42:35 +00008544
Douglas Gregor4c9be892011-02-28 20:01:57 +00008545 NestedNameSpecifierLoc QualifierLoc;
8546 if (Old->getQualifierLoc()) {
8547 QualifierLoc
8548 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8549 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008550 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008551 }
8552
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008553 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8554
Abramo Bagnara25777432010-08-11 22:01:17 +00008555 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008556 Sema::LookupOrdinaryName);
8557
8558 // Transform all the decls.
8559 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8560 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008561 NamedDecl *InstD = static_cast<NamedDecl*>(
8562 getDerived().TransformDecl(Old->getMemberLoc(),
8563 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008564 if (!InstD) {
8565 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8566 // This can happen because of dependent hiding.
8567 if (isa<UsingShadowDecl>(*I))
8568 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008569 else {
8570 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008571 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008572 }
John McCall9f54ad42009-12-10 09:41:52 +00008573 }
John McCall129e2df2009-11-30 22:42:35 +00008574
8575 // Expand using declarations.
8576 if (isa<UsingDecl>(InstD)) {
8577 UsingDecl *UD = cast<UsingDecl>(InstD);
8578 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8579 E = UD->shadow_end(); I != E; ++I)
8580 R.addDecl(*I);
8581 continue;
8582 }
8583
8584 R.addDecl(InstD);
8585 }
8586
8587 R.resolveKind();
8588
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008589 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008590 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008591 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008592 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008593 Old->getMemberLoc(),
8594 Old->getNamingClass()));
8595 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008596 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008597
Douglas Gregor66c45152010-04-27 16:10:10 +00008598 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008599 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008600
John McCall129e2df2009-11-30 22:42:35 +00008601 TemplateArgumentListInfo TransArgs;
8602 if (Old->hasExplicitTemplateArgs()) {
8603 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8604 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008605 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8606 Old->getNumTemplateArgs(),
8607 TransArgs))
8608 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008609 }
John McCallc2233c52010-01-15 08:34:02 +00008610
8611 // FIXME: to do this check properly, we will need to preserve the
8612 // first-qualifier-in-scope here, just in case we had a dependent
8613 // base (and therefore couldn't do the check) and a
8614 // nested-name-qualifier (and therefore could do the lookup).
8615 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008616
John McCall9ae2f072010-08-23 23:25:46 +00008617 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008618 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008619 Old->getOperatorLoc(),
8620 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008621 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008622 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008623 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008624 R,
8625 (Old->hasExplicitTemplateArgs()
8626 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008627}
8628
8629template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008630ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008631TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008632 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008633 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8634 if (SubExpr.isInvalid())
8635 return ExprError();
8636
8637 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008638 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008639
8640 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8641}
8642
8643template<typename Derived>
8644ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008645TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008646 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8647 if (Pattern.isInvalid())
8648 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008649
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008650 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8651 return SemaRef.Owned(E);
8652
Douglas Gregor67fd1252011-01-14 21:20:45 +00008653 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8654 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008655}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008656
8657template<typename Derived>
8658ExprResult
8659TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8660 // If E is not value-dependent, then nothing will change when we transform it.
8661 // Note: This is an instantiation-centric view.
8662 if (!E->isValueDependent())
8663 return SemaRef.Owned(E);
8664
8665 // Note: None of the implementations of TryExpandParameterPacks can ever
8666 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008667 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008668 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8669 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008670 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008671 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008672 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008673 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008674 ShouldExpand, RetainExpansion,
8675 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008676 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008677
Douglas Gregor089e8932011-10-10 18:59:29 +00008678 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008679 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008680
Douglas Gregor089e8932011-10-10 18:59:29 +00008681 NamedDecl *Pack = E->getPack();
8682 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008683 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008684 Pack));
8685 if (!Pack)
8686 return ExprError();
8687 }
8688
Chad Rosier4a9d7952012-08-08 18:46:20 +00008689
Douglas Gregoree8aff02011-01-04 17:33:58 +00008690 // We now know the length of the parameter pack, so build a new expression
8691 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008692 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8693 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008694 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008695}
8696
Douglas Gregorbe230c32011-01-03 17:17:50 +00008697template<typename Derived>
8698ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008699TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8700 SubstNonTypeTemplateParmPackExpr *E) {
8701 // Default behavior is to do nothing with this transformation.
8702 return SemaRef.Owned(E);
8703}
8704
8705template<typename Derived>
8706ExprResult
John McCall91a57552011-07-15 05:09:51 +00008707TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8708 SubstNonTypeTemplateParmExpr *E) {
8709 // Default behavior is to do nothing with this transformation.
8710 return SemaRef.Owned(E);
8711}
8712
8713template<typename Derived>
8714ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008715TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8716 // Default behavior is to do nothing with this transformation.
8717 return SemaRef.Owned(E);
8718}
8719
8720template<typename Derived>
8721ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008722TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8723 MaterializeTemporaryExpr *E) {
8724 return getDerived().TransformExpr(E->GetTemporaryExpr());
8725}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008726
Douglas Gregor03e80032011-06-21 17:03:29 +00008727template<typename Derived>
8728ExprResult
Richard Smith7c3e6152013-06-12 22:31:48 +00008729TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8730 CXXStdInitializerListExpr *E) {
8731 return getDerived().TransformExpr(E->getSubExpr());
8732}
8733
8734template<typename Derived>
8735ExprResult
John McCall454feb92009-12-08 09:21:05 +00008736TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008737 return SemaRef.MaybeBindToTemporary(E);
8738}
8739
8740template<typename Derived>
8741ExprResult
8742TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008743 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008744}
8745
8746template<typename Derived>
8747ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008748TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8749 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8750 if (SubExpr.isInvalid())
8751 return ExprError();
8752
8753 if (!getDerived().AlwaysRebuild() &&
8754 SubExpr.get() == E->getSubExpr())
8755 return SemaRef.Owned(E);
8756
8757 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008758}
8759
8760template<typename Derived>
8761ExprResult
8762TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8763 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008764 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008765 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008766 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008767 /*IsCall=*/false, Elements, &ArgChanged))
8768 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008769
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008770 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8771 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008772
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008773 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8774 Elements.data(),
8775 Elements.size());
8776}
8777
8778template<typename Derived>
8779ExprResult
8780TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008781 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008782 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008783 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008784 bool ArgChanged = false;
8785 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8786 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008787
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008788 if (OrigElement.isPackExpansion()) {
8789 // This key/value element is a pack expansion.
8790 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8791 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8792 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8793 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8794
8795 // Determine whether the set of unexpanded parameter packs can
8796 // and should be expanded.
8797 bool Expand = true;
8798 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008799 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8800 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008801 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8802 OrigElement.Value->getLocEnd());
8803 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8804 PatternRange,
8805 Unexpanded,
8806 Expand, RetainExpansion,
8807 NumExpansions))
8808 return ExprError();
8809
8810 if (!Expand) {
8811 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008812 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008813 // expansion.
8814 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8815 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8816 if (Key.isInvalid())
8817 return ExprError();
8818
8819 if (Key.get() != OrigElement.Key)
8820 ArgChanged = true;
8821
8822 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8823 if (Value.isInvalid())
8824 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008825
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008826 if (Value.get() != OrigElement.Value)
8827 ArgChanged = true;
8828
Chad Rosier4a9d7952012-08-08 18:46:20 +00008829 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008830 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8831 };
8832 Elements.push_back(Expansion);
8833 continue;
8834 }
8835
8836 // Record right away that the argument was changed. This needs
8837 // to happen even if the array expands to nothing.
8838 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008839
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008840 // The transform has determined that we should perform an elementwise
8841 // expansion of the pattern. Do so.
8842 for (unsigned I = 0; I != *NumExpansions; ++I) {
8843 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8844 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8845 if (Key.isInvalid())
8846 return ExprError();
8847
8848 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8849 if (Value.isInvalid())
8850 return ExprError();
8851
Chad Rosier4a9d7952012-08-08 18:46:20 +00008852 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008853 Key.get(), Value.get(), SourceLocation(), NumExpansions
8854 };
8855
8856 // If any unexpanded parameter packs remain, we still have a
8857 // pack expansion.
8858 if (Key.get()->containsUnexpandedParameterPack() ||
8859 Value.get()->containsUnexpandedParameterPack())
8860 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008861
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008862 Elements.push_back(Element);
8863 }
8864
8865 // We've finished with this pack expansion.
8866 continue;
8867 }
8868
8869 // Transform and check key.
8870 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8871 if (Key.isInvalid())
8872 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008873
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008874 if (Key.get() != OrigElement.Key)
8875 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008876
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008877 // Transform and check value.
8878 ExprResult Value
8879 = getDerived().TransformExpr(OrigElement.Value);
8880 if (Value.isInvalid())
8881 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008882
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008883 if (Value.get() != OrigElement.Value)
8884 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008885
8886 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00008887 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008888 };
8889 Elements.push_back(Element);
8890 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008891
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008892 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8893 return SemaRef.MaybeBindToTemporary(E);
8894
8895 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8896 Elements.data(),
8897 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008898}
8899
Mike Stump1eb44332009-09-09 15:08:12 +00008900template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008901ExprResult
John McCall454feb92009-12-08 09:21:05 +00008902TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008903 TypeSourceInfo *EncodedTypeInfo
8904 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8905 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008906 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008907
Douglas Gregorb98b1992009-08-11 05:31:07 +00008908 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008909 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008910 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008911
8912 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008913 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008914 E->getRParenLoc());
8915}
Mike Stump1eb44332009-09-09 15:08:12 +00008916
Douglas Gregorb98b1992009-08-11 05:31:07 +00008917template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008918ExprResult TreeTransform<Derived>::
8919TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCall93b64572013-04-11 02:14:26 +00008920 // This is a kind of implicit conversion, and it needs to get dropped
8921 // and recomputed for the same general reasons that ImplicitCastExprs
8922 // do, as well a more specific one: this expression is only valid when
8923 // it appears *immediately* as an argument expression.
8924 return getDerived().TransformExpr(E->getSubExpr());
John McCallf85e1932011-06-15 23:02:42 +00008925}
8926
8927template<typename Derived>
8928ExprResult TreeTransform<Derived>::
8929TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008930 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008931 = getDerived().TransformType(E->getTypeInfoAsWritten());
8932 if (!TSInfo)
8933 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008934
John McCallf85e1932011-06-15 23:02:42 +00008935 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008936 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008937 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008938
John McCallf85e1932011-06-15 23:02:42 +00008939 if (!getDerived().AlwaysRebuild() &&
8940 TSInfo == E->getTypeInfoAsWritten() &&
8941 Result.get() == E->getSubExpr())
8942 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008943
John McCallf85e1932011-06-15 23:02:42 +00008944 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008945 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008946 Result.get());
8947}
8948
8949template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008950ExprResult
John McCall454feb92009-12-08 09:21:05 +00008951TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008952 // Transform arguments.
8953 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008954 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008955 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008956 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008957 &ArgChanged))
8958 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008959
Douglas Gregor92e986e2010-04-22 16:44:27 +00008960 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8961 // Class message: transform the receiver type.
8962 TypeSourceInfo *ReceiverTypeInfo
8963 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8964 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008965 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008966
Douglas Gregor92e986e2010-04-22 16:44:27 +00008967 // If nothing changed, just retain the existing message send.
8968 if (!getDerived().AlwaysRebuild() &&
8969 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008970 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008971
8972 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008973 SmallVector<SourceLocation, 16> SelLocs;
8974 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008975 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8976 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008977 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008978 E->getMethodDecl(),
8979 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008980 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008981 E->getRightLoc());
8982 }
8983
8984 // Instance message: transform the receiver
8985 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8986 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008987 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008988 = getDerived().TransformExpr(E->getInstanceReceiver());
8989 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008990 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008991
8992 // If nothing changed, just retain the existing message send.
8993 if (!getDerived().AlwaysRebuild() &&
8994 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008995 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008996
Douglas Gregor92e986e2010-04-22 16:44:27 +00008997 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008998 SmallVector<SourceLocation, 16> SelLocs;
8999 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00009000 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00009001 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009002 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009003 E->getMethodDecl(),
9004 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009005 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009006 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009007}
9008
Mike Stump1eb44332009-09-09 15:08:12 +00009009template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009010ExprResult
John McCall454feb92009-12-08 09:21:05 +00009011TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00009012 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009013}
9014
Mike Stump1eb44332009-09-09 15:08:12 +00009015template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009016ExprResult
John McCall454feb92009-12-08 09:21:05 +00009017TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00009018 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009019}
9020
Mike Stump1eb44332009-09-09 15:08:12 +00009021template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009022ExprResult
John McCall454feb92009-12-08 09:21:05 +00009023TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009024 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009025 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009026 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009027 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009028
9029 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009030
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009031 // If nothing changed, just retain the existing expression.
9032 if (!getDerived().AlwaysRebuild() &&
9033 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009034 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009035
John McCall9ae2f072010-08-23 23:25:46 +00009036 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009037 E->getLocation(),
9038 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009039}
9040
Mike Stump1eb44332009-09-09 15:08:12 +00009041template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009042ExprResult
John McCall454feb92009-12-08 09:21:05 +00009043TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00009044 // 'super' and types never change. Property never changes. Just
9045 // retain the existing expression.
9046 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00009047 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009048
Douglas Gregore3303542010-04-26 20:47:02 +00009049 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009050 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00009051 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009052 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009053
Douglas Gregore3303542010-04-26 20:47:02 +00009054 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009055
Douglas Gregore3303542010-04-26 20:47:02 +00009056 // If nothing changed, just retain the existing expression.
9057 if (!getDerived().AlwaysRebuild() &&
9058 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009059 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009060
John McCall12f78a62010-12-02 01:19:52 +00009061 if (E->isExplicitProperty())
9062 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9063 E->getExplicitProperty(),
9064 E->getLocation());
9065
9066 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00009067 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00009068 E->getImplicitPropertyGetter(),
9069 E->getImplicitPropertySetter(),
9070 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009071}
9072
Mike Stump1eb44332009-09-09 15:08:12 +00009073template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009074ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009075TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9076 // Transform the base expression.
9077 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9078 if (Base.isInvalid())
9079 return ExprError();
9080
9081 // Transform the key expression.
9082 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9083 if (Key.isInvalid())
9084 return ExprError();
9085
9086 // If nothing changed, just retain the existing expression.
9087 if (!getDerived().AlwaysRebuild() &&
9088 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9089 return SemaRef.Owned(E);
9090
Chad Rosier4a9d7952012-08-08 18:46:20 +00009091 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009092 Base.get(), Key.get(),
9093 E->getAtIndexMethodDecl(),
9094 E->setAtIndexMethodDecl());
9095}
9096
9097template<typename Derived>
9098ExprResult
John McCall454feb92009-12-08 09:21:05 +00009099TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009100 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009101 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009102 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009103 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009104
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009105 // If nothing changed, just retain the existing expression.
9106 if (!getDerived().AlwaysRebuild() &&
9107 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009108 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009109
John McCall9ae2f072010-08-23 23:25:46 +00009110 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00009111 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009112 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009113}
9114
Mike Stump1eb44332009-09-09 15:08:12 +00009115template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009116ExprResult
John McCall454feb92009-12-08 09:21:05 +00009117TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009118 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009119 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00009120 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009121 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00009122 SubExprs, &ArgumentChanged))
9123 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009124
Douglas Gregorb98b1992009-08-11 05:31:07 +00009125 if (!getDerived().AlwaysRebuild() &&
9126 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00009127 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00009128
Douglas Gregorb98b1992009-08-11 05:31:07 +00009129 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009130 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00009131 E->getRParenLoc());
9132}
9133
Mike Stump1eb44332009-09-09 15:08:12 +00009134template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009135ExprResult
John McCall454feb92009-12-08 09:21:05 +00009136TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00009137 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009138
John McCallc6ac9c32011-02-04 18:33:18 +00009139 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9140 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9141
9142 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00009143 blockScope->TheDecl->setBlockMissingReturnType(
9144 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009145
Chris Lattner686775d2011-07-20 06:58:45 +00009146 SmallVector<ParmVarDecl*, 4> params;
9147 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00009148
Fariborz Jahaniana729da22010-07-09 18:44:02 +00009149 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00009150 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9151 oldBlock->param_begin(),
9152 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009153 0, paramTypes, &params)) {
9154 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00009155 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009156 }
John McCallc6ac9c32011-02-04 18:33:18 +00009157
Jordan Rose09189892013-03-08 22:25:36 +00009158 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00009159 QualType exprResultType =
9160 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00009161
Jordan Rosebea522f2013-03-08 21:51:21 +00009162 QualType functionType =
9163 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009164 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00009165 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00009166
9167 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00009168 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00009169 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00009170
9171 if (!oldBlock->blockMissingReturnType()) {
9172 blockScope->HasImplicitReturnType = false;
9173 blockScope->ReturnType = exprResultType;
9174 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00009175
John McCall711c52b2011-01-05 12:14:39 +00009176 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00009177 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009178 if (body.isInvalid()) {
9179 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00009180 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009181 }
John McCall711c52b2011-01-05 12:14:39 +00009182
John McCallc6ac9c32011-02-04 18:33:18 +00009183#ifndef NDEBUG
9184 // In builds with assertions, make sure that we captured everything we
9185 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00009186 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9187 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9188 e = oldBlock->capture_end(); i != e; ++i) {
9189 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00009190
Douglas Gregorfc921372011-05-20 15:32:55 +00009191 // Ignore parameter packs.
9192 if (isa<ParmVarDecl>(oldCapture) &&
9193 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9194 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00009195
Douglas Gregorfc921372011-05-20 15:32:55 +00009196 VarDecl *newCapture =
9197 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9198 oldCapture));
9199 assert(blockScope->CaptureMap.count(newCapture));
9200 }
Douglas Gregorec79d872012-02-24 17:41:38 +00009201 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00009202 }
9203#endif
9204
9205 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9206 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009207}
9208
Mike Stump1eb44332009-09-09 15:08:12 +00009209template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009210ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009211TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00009212 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009213}
Eli Friedman276b0612011-10-11 02:20:01 +00009214
9215template<typename Derived>
9216ExprResult
9217TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009218 QualType RetTy = getDerived().TransformType(E->getType());
9219 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009220 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009221 SubExprs.reserve(E->getNumSubExprs());
9222 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9223 SubExprs, &ArgumentChanged))
9224 return ExprError();
9225
9226 if (!getDerived().AlwaysRebuild() &&
9227 !ArgumentChanged)
9228 return SemaRef.Owned(E);
9229
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009230 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009231 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00009232}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009233
Douglas Gregorb98b1992009-08-11 05:31:07 +00009234//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00009235// Type reconstruction
9236//===----------------------------------------------------------------------===//
9237
Mike Stump1eb44332009-09-09 15:08:12 +00009238template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009239QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9240 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009241 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009242 getDerived().getBaseEntity());
9243}
9244
Mike Stump1eb44332009-09-09 15:08:12 +00009245template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009246QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9247 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009248 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009249 getDerived().getBaseEntity());
9250}
9251
Mike Stump1eb44332009-09-09 15:08:12 +00009252template<typename Derived>
9253QualType
John McCall85737a72009-10-30 00:06:24 +00009254TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9255 bool WrittenAsLValue,
9256 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009257 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00009258 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009259}
9260
9261template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009262QualType
John McCall85737a72009-10-30 00:06:24 +00009263TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9264 QualType ClassType,
9265 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009266 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00009267 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009268}
9269
9270template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009271QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00009272TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9273 ArrayType::ArraySizeModifier SizeMod,
9274 const llvm::APInt *Size,
9275 Expr *SizeExpr,
9276 unsigned IndexTypeQuals,
9277 SourceRange BracketsRange) {
9278 if (SizeExpr || !Size)
9279 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9280 IndexTypeQuals, BracketsRange,
9281 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00009282
9283 QualType Types[] = {
9284 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9285 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9286 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00009287 };
Craig Topperb9602322013-07-15 03:38:40 +00009288 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009289 QualType SizeType;
9290 for (unsigned I = 0; I != NumTypes; ++I)
9291 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9292 SizeType = Types[I];
9293 break;
9294 }
Mike Stump1eb44332009-09-09 15:08:12 +00009295
Eli Friedman01f276d2012-01-25 23:20:27 +00009296 // Note that we can return a VariableArrayType here in the case where
9297 // the element type was a dependent VariableArrayType.
9298 IntegerLiteral *ArraySize
9299 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9300 /*FIXME*/BracketsRange.getBegin());
9301 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009302 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00009303 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009304}
Mike Stump1eb44332009-09-09 15:08:12 +00009305
Douglas Gregor577f75a2009-08-04 16:50:30 +00009306template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009307QualType
9308TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009309 ArrayType::ArraySizeModifier SizeMod,
9310 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009311 unsigned IndexTypeQuals,
9312 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009313 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009314 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009315}
9316
9317template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009318QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009319TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009320 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009321 unsigned IndexTypeQuals,
9322 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009323 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009324 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009325}
Mike Stump1eb44332009-09-09 15:08:12 +00009326
Douglas Gregor577f75a2009-08-04 16:50:30 +00009327template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009328QualType
9329TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009330 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009331 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009332 unsigned IndexTypeQuals,
9333 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009334 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009335 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009336 IndexTypeQuals, BracketsRange);
9337}
9338
9339template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009340QualType
9341TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009342 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009343 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009344 unsigned IndexTypeQuals,
9345 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009346 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009347 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009348 IndexTypeQuals, BracketsRange);
9349}
9350
9351template<typename Derived>
9352QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009353 unsigned NumElements,
9354 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009355 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009356 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009357}
Mike Stump1eb44332009-09-09 15:08:12 +00009358
Douglas Gregor577f75a2009-08-04 16:50:30 +00009359template<typename Derived>
9360QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9361 unsigned NumElements,
9362 SourceLocation AttributeLoc) {
9363 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9364 NumElements, true);
9365 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009366 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9367 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009368 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009369}
Mike Stump1eb44332009-09-09 15:08:12 +00009370
Douglas Gregor577f75a2009-08-04 16:50:30 +00009371template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009372QualType
9373TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009374 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009375 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009376 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009377}
Mike Stump1eb44332009-09-09 15:08:12 +00009378
Douglas Gregor577f75a2009-08-04 16:50:30 +00009379template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009380QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9381 QualType T,
9382 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009383 const FunctionProtoType::ExtProtoInfo &EPI) {
9384 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009385 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009386 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009387 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009388}
Mike Stump1eb44332009-09-09 15:08:12 +00009389
Douglas Gregor577f75a2009-08-04 16:50:30 +00009390template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009391QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9392 return SemaRef.Context.getFunctionNoProtoType(T);
9393}
9394
9395template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009396QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9397 assert(D && "no decl found");
9398 if (D->isInvalidDecl()) return QualType();
9399
Douglas Gregor92e986e2010-04-22 16:44:27 +00009400 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009401 TypeDecl *Ty;
9402 if (isa<UsingDecl>(D)) {
9403 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanella8d030c72013-07-22 10:54:09 +00009404 assert(Using->hasTypename() &&
John McCalled976492009-12-04 22:46:56 +00009405 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9406
9407 // A valid resolved using typename decl points to exactly one type decl.
9408 assert(++Using->shadow_begin() == Using->shadow_end());
9409 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009410
John McCalled976492009-12-04 22:46:56 +00009411 } else {
9412 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9413 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9414 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9415 }
9416
9417 return SemaRef.Context.getTypeDeclType(Ty);
9418}
9419
9420template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009421QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9422 SourceLocation Loc) {
9423 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009424}
9425
9426template<typename Derived>
9427QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9428 return SemaRef.Context.getTypeOfType(Underlying);
9429}
9430
9431template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009432QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9433 SourceLocation Loc) {
9434 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009435}
9436
9437template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009438QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9439 UnaryTransformType::UTTKind UKind,
9440 SourceLocation Loc) {
9441 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9442}
9443
9444template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009445QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009446 TemplateName Template,
9447 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009448 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009449 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009450}
Mike Stump1eb44332009-09-09 15:08:12 +00009451
Douglas Gregordcee1a12009-08-06 05:28:30 +00009452template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009453QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9454 SourceLocation KWLoc) {
9455 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9456}
9457
9458template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009459TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009460TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009461 bool TemplateKW,
9462 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009463 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009464 Template);
9465}
9466
9467template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009468TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009469TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9470 const IdentifierInfo &Name,
9471 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009472 QualType ObjectType,
9473 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009474 UnqualifiedId TemplateName;
9475 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009476 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009477 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009478 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009479 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009480 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009481 /*EnteringContext=*/false,
9482 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009483 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009484}
Mike Stump1eb44332009-09-09 15:08:12 +00009485
Douglas Gregorb98b1992009-08-11 05:31:07 +00009486template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009487TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009488TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009489 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009490 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009491 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009492 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009493 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009494 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009495 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009496 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009497 Sema::TemplateTy Template;
9498 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009499 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009500 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009501 /*EnteringContext=*/false,
9502 Template);
9503 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009504}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009505
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009506template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009507ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009508TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9509 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009510 Expr *OrigCallee,
9511 Expr *First,
9512 Expr *Second) {
9513 Expr *Callee = OrigCallee->IgnoreParenCasts();
9514 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009515
Douglas Gregorb98b1992009-08-11 05:31:07 +00009516 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009517 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009518 if (!First->getType()->isOverloadableType() &&
9519 !Second->getType()->isOverloadableType())
9520 return getSema().CreateBuiltinArraySubscriptExpr(First,
9521 Callee->getLocStart(),
9522 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009523 } else if (Op == OO_Arrow) {
9524 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009525 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9526 } else if (Second == 0 || isPostIncDec) {
9527 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009528 // The argument is not of overloadable type, so try to create a
9529 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009530 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009531 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009532
John McCall9ae2f072010-08-23 23:25:46 +00009533 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009534 }
9535 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009536 if (!First->getType()->isOverloadableType() &&
9537 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009538 // Neither of the arguments is an overloadable type, so try to
9539 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009540 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009541 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009542 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009543 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009544 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009545
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009546 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009547 }
9548 }
Mike Stump1eb44332009-09-09 15:08:12 +00009549
9550 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009551 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009552 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009553
John McCall9ae2f072010-08-23 23:25:46 +00009554 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009555 assert(ULE->requiresADL());
9556
9557 // FIXME: Do we have to check
9558 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009559 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009560 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009561 // If we've resolved this to a particular non-member function, just call
9562 // that function. If we resolved it to a member function,
9563 // CreateOverloaded* will find that function for us.
9564 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9565 if (!isa<CXXMethodDecl>(ND))
9566 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009567 }
Mike Stump1eb44332009-09-09 15:08:12 +00009568
Douglas Gregorb98b1992009-08-11 05:31:07 +00009569 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009570 Expr *Args[2] = { First, Second };
9571 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009572
Douglas Gregorb98b1992009-08-11 05:31:07 +00009573 // Create the overloaded operator invocation for unary operators.
9574 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009575 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009576 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009577 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009578 }
Mike Stump1eb44332009-09-09 15:08:12 +00009579
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009580 if (Op == OO_Subscript) {
9581 SourceLocation LBrace;
9582 SourceLocation RBrace;
9583
9584 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9585 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9586 LBrace = SourceLocation::getFromRawEncoding(
9587 NameLoc.CXXOperatorName.BeginOpNameLoc);
9588 RBrace = SourceLocation::getFromRawEncoding(
9589 NameLoc.CXXOperatorName.EndOpNameLoc);
9590 } else {
9591 LBrace = Callee->getLocStart();
9592 RBrace = OpLoc;
9593 }
9594
9595 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9596 First, Second);
9597 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009598
Douglas Gregorb98b1992009-08-11 05:31:07 +00009599 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009600 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009601 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009602 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9603 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009604 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009605
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009606 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009607}
Mike Stump1eb44332009-09-09 15:08:12 +00009608
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009609template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009610ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009611TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009612 SourceLocation OperatorLoc,
9613 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009614 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009615 TypeSourceInfo *ScopeType,
9616 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009617 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009618 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009619 QualType BaseType = Base->getType();
9620 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009621 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009622 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009623 !BaseType->getAs<PointerType>()->getPointeeType()
9624 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009625 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009626 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009627 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009628 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009629 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009630 /*FIXME?*/true);
9631 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009632
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009633 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009634 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9635 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9636 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9637 NameInfo.setNamedTypeInfo(DestroyedType);
9638
Richard Smith6314db92012-05-15 06:15:11 +00009639 // The scope type is now known to be a valid nested name specifier
9640 // component. Tack it on to the end of the nested name specifier.
9641 if (ScopeType)
9642 SS.Extend(SemaRef.Context, SourceLocation(),
9643 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009644
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009645 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009646 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009647 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009648 SS, TemplateKWLoc,
9649 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009650 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009651 /*TemplateArgs*/ 0);
9652}
9653
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009654template<typename Derived>
9655StmtResult
9656TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan9fd6b8f2013-05-04 03:59:06 +00009657 SourceLocation Loc = S->getLocStart();
9658 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9659 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9660 S->getCapturedRegionKind(), NumParams);
9661 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9662
9663 if (Body.isInvalid()) {
9664 getSema().ActOnCapturedRegionError();
9665 return StmtError();
9666 }
9667
9668 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009669}
9670
Douglas Gregor577f75a2009-08-04 16:50:30 +00009671} // end namespace clang
9672
9673#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H