blob: bec956b6d72356be52f5a423d66530d3c1be6fdb [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
Faisal Valiaecbb9d2013-10-03 05:32:48 +0000597 TemplateParameterList *TransformTemplateParameterList(
598 TemplateParameterList *TPL) {
599 return TPL;
600 }
601
Richard Smithefeeccf2012-10-21 03:28:35 +0000602 ExprResult TransformAddressOfOperand(Expr *E);
603 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
604 bool IsAddressOfOperand);
605
Eli Friedman1ac6c932013-09-06 01:13:30 +0000606// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
607// amount of stack usage with clang.
Douglas Gregor43959a92009-08-20 07:17:43 +0000608#define STMT(Node, Parent) \
Eli Friedman1ac6c932013-09-06 01:13:30 +0000609 LLVM_ATTRIBUTE_NOINLINE \
John McCall60d7b3a2010-08-24 06:29:42 +0000610 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000611#define EXPR(Node, Parent) \
Eli Friedman1ac6c932013-09-06 01:13:30 +0000612 LLVM_ATTRIBUTE_NOINLINE \
John McCall60d7b3a2010-08-24 06:29:42 +0000613 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000614#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000615#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000616
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000617#define OPENMP_CLAUSE(Name, Class) \
Eli Friedman1ac6c932013-09-06 01:13:30 +0000618 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000619 OMPClause *Transform ## Class(Class *S);
620#include "clang/Basic/OpenMPKinds.def"
621
Douglas Gregor577f75a2009-08-04 16:50:30 +0000622 /// \brief Build a new pointer type given its pointee type.
623 ///
624 /// By default, performs semantic analysis when building the pointer type.
625 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000626 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000627
628 /// \brief Build a new block pointer type given its pointee type.
629 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000630 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000631 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000632 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000633
John McCall85737a72009-10-30 00:06:24 +0000634 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000635 ///
John McCall85737a72009-10-30 00:06:24 +0000636 /// By default, performs semantic analysis when building the
637 /// reference type. Subclasses may override this routine to provide
638 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000639 ///
John McCall85737a72009-10-30 00:06:24 +0000640 /// \param LValue whether the type was written with an lvalue sigil
641 /// or an rvalue sigil.
642 QualType RebuildReferenceType(QualType ReferentType,
643 bool LValue,
644 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000645
Douglas Gregor577f75a2009-08-04 16:50:30 +0000646 /// \brief Build a new member pointer type given the pointee type and the
647 /// class type it refers into.
648 ///
649 /// By default, performs semantic analysis when building the member pointer
650 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000651 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
652 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000653
Douglas Gregor577f75a2009-08-04 16:50:30 +0000654 /// \brief Build a new array type given the element type, size
655 /// modifier, size of the array (if known), size expression, and index type
656 /// qualifiers.
657 ///
658 /// By default, performs semantic analysis when building the array type.
659 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000660 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000661 QualType RebuildArrayType(QualType ElementType,
662 ArrayType::ArraySizeModifier SizeMod,
663 const llvm::APInt *Size,
664 Expr *SizeExpr,
665 unsigned IndexTypeQuals,
666 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000667
Douglas Gregor577f75a2009-08-04 16:50:30 +0000668 /// \brief Build a new constant array type given the element type, size
669 /// modifier, (known) size of the array, and index type qualifiers.
670 ///
671 /// By default, performs semantic analysis when building the array type.
672 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000673 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000674 ArrayType::ArraySizeModifier SizeMod,
675 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000676 unsigned IndexTypeQuals,
677 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000678
Douglas Gregor577f75a2009-08-04 16:50:30 +0000679 /// \brief Build a new incomplete array type given the element type, size
680 /// modifier, 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 RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000685 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000686 unsigned IndexTypeQuals,
687 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000688
Mike Stump1eb44332009-09-09 15:08:12 +0000689 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000690 /// size modifier, size expression, and index type qualifiers.
691 ///
692 /// By default, performs semantic analysis when building the array type.
693 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000694 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000695 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000696 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000697 unsigned IndexTypeQuals,
698 SourceRange BracketsRange);
699
Mike Stump1eb44332009-09-09 15:08:12 +0000700 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000701 /// size modifier, size expression, and index type qualifiers.
702 ///
703 /// By default, performs semantic analysis when building the array type.
704 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000705 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000706 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000707 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000708 unsigned IndexTypeQuals,
709 SourceRange BracketsRange);
710
711 /// \brief Build a new vector type given the element type and
712 /// number of elements.
713 ///
714 /// By default, performs semantic analysis when building the vector type.
715 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000716 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000717 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000718
Douglas Gregor577f75a2009-08-04 16:50:30 +0000719 /// \brief Build a new extended vector type given the element type and
720 /// number of elements.
721 ///
722 /// By default, performs semantic analysis when building the vector type.
723 /// Subclasses may override this routine to provide different behavior.
724 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
725 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000726
727 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000728 /// given the element type and number of elements.
729 ///
730 /// By default, performs semantic analysis when building the vector type.
731 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000732 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000733 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000734 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000735
Douglas Gregor577f75a2009-08-04 16:50:30 +0000736 /// \brief Build a new function type.
737 ///
738 /// By default, performs semantic analysis when building the function type.
739 /// Subclasses may override this routine to provide different behavior.
740 QualType RebuildFunctionProtoType(QualType T,
Jordan Rosebea522f2013-03-08 21:51:21 +0000741 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +0000742 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump1eb44332009-09-09 15:08:12 +0000743
John McCalla2becad2009-10-21 00:40:46 +0000744 /// \brief Build a new unprototyped function type.
745 QualType RebuildFunctionNoProtoType(QualType ResultType);
746
John McCalled976492009-12-04 22:46:56 +0000747 /// \brief Rebuild an unresolved typename type, given the decl that
748 /// the UnresolvedUsingTypenameDecl was transformed to.
749 QualType RebuildUnresolvedUsingType(Decl *D);
750
Douglas Gregor577f75a2009-08-04 16:50:30 +0000751 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000752 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000753 return SemaRef.Context.getTypeDeclType(Typedef);
754 }
755
756 /// \brief Build a new class/struct/union type.
757 QualType RebuildRecordType(RecordDecl *Record) {
758 return SemaRef.Context.getTypeDeclType(Record);
759 }
760
761 /// \brief Build a new Enum type.
762 QualType RebuildEnumType(EnumDecl *Enum) {
763 return SemaRef.Context.getTypeDeclType(Enum);
764 }
John McCall7da24312009-09-05 00:15:47 +0000765
Mike Stump1eb44332009-09-09 15:08:12 +0000766 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000767 ///
768 /// By default, performs semantic analysis when building the typeof type.
769 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000770 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000771
Mike Stump1eb44332009-09-09 15:08:12 +0000772 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000773 ///
774 /// By default, builds a new TypeOfType with the given underlying type.
775 QualType RebuildTypeOfType(QualType Underlying);
776
Sean Huntca63c202011-05-24 22:41:36 +0000777 /// \brief Build a new unary transform type.
778 QualType RebuildUnaryTransformType(QualType BaseType,
779 UnaryTransformType::UTTKind UKind,
780 SourceLocation Loc);
781
Richard Smitha2c36462013-04-26 16:15:35 +0000782 /// \brief Build a new C++11 decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000783 ///
784 /// By default, performs semantic analysis when building the decltype type.
785 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000786 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000787
Richard Smitha2c36462013-04-26 16:15:35 +0000788 /// \brief Build a new C++11 auto type.
Richard Smith34b41d92011-02-20 03:19:35 +0000789 ///
790 /// By default, builds a new AutoType with the given deduced type.
Richard Smitha2c36462013-04-26 16:15:35 +0000791 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smithdc7a4f52013-04-30 13:56:41 +0000792 // Note, IsDependent is always false here: we implicitly convert an 'auto'
793 // which has been deduced to a dependent type into an undeduced 'auto', so
794 // that we'll retry deduction after the transformation.
Faisal Valifad9e132013-09-26 19:54:12 +0000795 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
796 /*IsDependent*/ false);
Richard Smith34b41d92011-02-20 03:19:35 +0000797 }
798
Douglas Gregor577f75a2009-08-04 16:50:30 +0000799 /// \brief Build a new template specialization type.
800 ///
801 /// By default, performs semantic analysis when building the template
802 /// specialization type. Subclasses may override this routine to provide
803 /// different behavior.
804 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000805 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000806 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000807
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000808 /// \brief Build a new parenthesized type.
809 ///
810 /// By default, builds a new ParenType type from the inner type.
811 /// Subclasses may override this routine to provide different behavior.
812 QualType RebuildParenType(QualType InnerType) {
813 return SemaRef.Context.getParenType(InnerType);
814 }
815
Douglas Gregor577f75a2009-08-04 16:50:30 +0000816 /// \brief Build a new qualified name type.
817 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000818 /// By default, builds a new ElaboratedType type from the keyword,
819 /// the nested-name-specifier and the named type.
820 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000821 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
822 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000823 NestedNameSpecifierLoc QualifierLoc,
824 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000825 return SemaRef.Context.getElaboratedType(Keyword,
826 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000827 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000828 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000829
830 /// \brief Build a new typename type that refers to a template-id.
831 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000832 /// By default, builds a new DependentNameType type from the
833 /// nested-name-specifier and the given type. Subclasses may override
834 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000835 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000836 ElaboratedTypeKeyword Keyword,
837 NestedNameSpecifierLoc QualifierLoc,
838 const IdentifierInfo *Name,
839 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000840 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000841 // Rebuild the template name.
842 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000843 CXXScopeSpec SS;
844 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000845 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000846 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000847
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000848 if (InstName.isNull())
849 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000850
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000851 // If it's still dependent, make a dependent specialization.
852 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000853 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
854 QualifierLoc.getNestedNameSpecifier(),
855 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000856 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000857
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000858 // Otherwise, make an elaborated type wrapping a non-dependent
859 // specialization.
860 QualType T =
861 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
862 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000863
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000864 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
865 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000866
867 return SemaRef.Context.getElaboratedType(Keyword,
868 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000869 T);
870 }
871
Douglas Gregor577f75a2009-08-04 16:50:30 +0000872 /// \brief Build a new typename type that refers to an identifier.
873 ///
874 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000875 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000876 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000877 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000878 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000879 NestedNameSpecifierLoc QualifierLoc,
880 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000881 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000882 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000883 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000884
Douglas Gregor2494dd02011-03-01 01:34:45 +0000885 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000886 // If the name is still dependent, just build a new dependent name type.
887 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000888 return SemaRef.Context.getDependentNameType(Keyword,
889 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000890 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000891 }
892
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000893 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000894 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000895 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000896
897 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
898
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000899 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000900 // into a non-dependent elaborated-type-specifier. Find the tag we're
901 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000902 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000903 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
904 if (!DC)
905 return QualType();
906
John McCall56138762010-05-27 06:40:31 +0000907 if (SemaRef.RequireCompleteDeclContext(SS, DC))
908 return QualType();
909
Douglas Gregor40336422010-03-31 22:19:08 +0000910 TagDecl *Tag = 0;
911 SemaRef.LookupQualifiedName(Result, DC);
912 switch (Result.getResultKind()) {
913 case LookupResult::NotFound:
914 case LookupResult::NotFoundInCurrentInstantiation:
915 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000916
Douglas Gregor40336422010-03-31 22:19:08 +0000917 case LookupResult::Found:
918 Tag = Result.getAsSingle<TagDecl>();
919 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000920
Douglas Gregor40336422010-03-31 22:19:08 +0000921 case LookupResult::FoundOverloaded:
922 case LookupResult::FoundUnresolvedValue:
923 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000924
Douglas Gregor40336422010-03-31 22:19:08 +0000925 case LookupResult::Ambiguous:
926 // Let the LookupResult structure handle ambiguities.
927 return QualType();
928 }
929
930 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000931 // Check where the name exists but isn't a tag type and use that to emit
932 // better diagnostics.
933 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
934 SemaRef.LookupQualifiedName(Result, DC);
935 switch (Result.getResultKind()) {
936 case LookupResult::Found:
937 case LookupResult::FoundOverloaded:
938 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000939 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000940 unsigned Kind = 0;
941 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000942 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
943 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000944 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
945 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
946 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000947 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000948 default:
949 // FIXME: Would be nice to highlight just the source range.
950 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
951 << Kind << Id << DC;
952 break;
953 }
Douglas Gregor40336422010-03-31 22:19:08 +0000954 return QualType();
955 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000956
Richard Trieubbf34c02011-06-10 03:11:26 +0000957 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
958 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000959 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000960 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
961 return QualType();
962 }
963
964 // Build the elaborated-type-specifier type.
965 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000966 return SemaRef.Context.getElaboratedType(Keyword,
967 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000968 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000969 }
Mike Stump1eb44332009-09-09 15:08:12 +0000970
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000971 /// \brief Build a new pack expansion type.
972 ///
973 /// By default, builds a new PackExpansionType type from the given pattern.
974 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000975 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000976 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000977 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +0000978 Optional<unsigned> NumExpansions) {
Douglas Gregorcded4f62011-01-14 17:04:44 +0000979 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
980 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000981 }
982
Eli Friedmanb001de72011-10-06 23:00:33 +0000983 /// \brief Build a new atomic type given its value type.
984 ///
985 /// By default, performs semantic analysis when building the atomic type.
986 /// Subclasses may override this routine to provide different behavior.
987 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
988
Douglas Gregord1067e52009-08-06 06:41:21 +0000989 /// \brief Build a new template name given a nested name specifier, a flag
990 /// indicating whether the "template" keyword was provided, and the template
991 /// that the template name refers to.
992 ///
993 /// By default, builds the new template name directly. Subclasses may override
994 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000995 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000996 bool TemplateKW,
997 TemplateDecl *Template);
998
Douglas Gregord1067e52009-08-06 06:41:21 +0000999 /// \brief Build a new template name given a nested name specifier and the
1000 /// name that is referred to as a template.
1001 ///
1002 /// By default, performs semantic analysis to determine whether the name can
1003 /// be resolved to a specific template, then builds the appropriate kind of
1004 /// template name. Subclasses may override this routine to provide different
1005 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001006 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1007 const IdentifierInfo &Name,
1008 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00001009 QualType ObjectType,
1010 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00001011
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001012 /// \brief Build a new template name given a nested name specifier and the
1013 /// overloaded operator name that is referred to as a template.
1014 ///
1015 /// By default, performs semantic analysis to determine whether the name can
1016 /// be resolved to a specific template, then builds the appropriate kind of
1017 /// template name. Subclasses may override this routine to provide different
1018 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001019 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001020 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001021 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001022 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001023
1024 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +00001025 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001026 ///
1027 /// By default, performs semantic analysis to determine whether the name can
1028 /// be resolved to a specific template, then builds the appropriate kind of
1029 /// template name. Subclasses may override this routine to provide different
1030 /// behavior.
1031 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1032 const TemplateArgument &ArgPack) {
1033 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1034 }
1035
Douglas Gregor43959a92009-08-20 07:17:43 +00001036 /// \brief Build a new compound statement.
1037 ///
1038 /// By default, performs semantic analysis to build the new statement.
1039 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001040 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001041 MultiStmtArg Statements,
1042 SourceLocation RBraceLoc,
1043 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001044 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001045 IsStmtExpr);
1046 }
1047
1048 /// \brief Build a new case statement.
1049 ///
1050 /// By default, performs semantic analysis to build the new statement.
1051 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001052 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001053 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001054 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001055 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001056 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001057 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001058 ColonLoc);
1059 }
Mike Stump1eb44332009-09-09 15:08:12 +00001060
Douglas Gregor43959a92009-08-20 07:17:43 +00001061 /// \brief Attach the body to a new case statement.
1062 ///
1063 /// By default, performs semantic analysis to build the new statement.
1064 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001065 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001066 getSema().ActOnCaseStmtBody(S, Body);
1067 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001068 }
Mike Stump1eb44332009-09-09 15:08:12 +00001069
Douglas Gregor43959a92009-08-20 07:17:43 +00001070 /// \brief Build a new default statement.
1071 ///
1072 /// By default, performs semantic analysis to build the new statement.
1073 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001074 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001075 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001076 Stmt *SubStmt) {
1077 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001078 /*CurScope=*/0);
1079 }
Mike Stump1eb44332009-09-09 15:08:12 +00001080
Douglas Gregor43959a92009-08-20 07:17:43 +00001081 /// \brief Build a new label statement.
1082 ///
1083 /// By default, performs semantic analysis to build the new statement.
1084 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001085 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1086 SourceLocation ColonLoc, Stmt *SubStmt) {
1087 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001088 }
Mike Stump1eb44332009-09-09 15:08:12 +00001089
Richard Smith534986f2012-04-14 00:33:13 +00001090 /// \brief Build a new label statement.
1091 ///
1092 /// By default, performs semantic analysis to build the new statement.
1093 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001094 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1095 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001096 Stmt *SubStmt) {
1097 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1098 }
1099
Douglas Gregor43959a92009-08-20 07:17:43 +00001100 /// \brief Build a new "if" statement.
1101 ///
1102 /// By default, performs semantic analysis to build the new statement.
1103 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001104 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001105 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001106 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001107 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001108 }
Mike Stump1eb44332009-09-09 15:08:12 +00001109
Douglas Gregor43959a92009-08-20 07:17:43 +00001110 /// \brief Start building a new switch statement.
1111 ///
1112 /// By default, performs semantic analysis to build the new statement.
1113 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001114 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001115 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001116 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001117 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001118 }
Mike Stump1eb44332009-09-09 15:08:12 +00001119
Douglas Gregor43959a92009-08-20 07:17:43 +00001120 /// \brief Attach the body to the switch statement.
1121 ///
1122 /// By default, performs semantic analysis to build the new statement.
1123 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001124 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001125 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001126 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001127 }
1128
1129 /// \brief Build a new while statement.
1130 ///
1131 /// By default, performs semantic analysis to build the new statement.
1132 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001133 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1134 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001135 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001136 }
Mike Stump1eb44332009-09-09 15:08:12 +00001137
Douglas Gregor43959a92009-08-20 07:17:43 +00001138 /// \brief Build a new do-while statement.
1139 ///
1140 /// By default, performs semantic analysis to build the new statement.
1141 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001142 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001143 SourceLocation WhileLoc, SourceLocation LParenLoc,
1144 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001145 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1146 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001147 }
1148
1149 /// \brief Build a new for statement.
1150 ///
1151 /// By default, performs semantic analysis to build the new statement.
1152 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001153 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001154 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001155 VarDecl *CondVar, Sema::FullExprArg Inc,
1156 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001157 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001158 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001159 }
Mike Stump1eb44332009-09-09 15:08:12 +00001160
Douglas Gregor43959a92009-08-20 07:17:43 +00001161 /// \brief Build a new goto statement.
1162 ///
1163 /// By default, performs semantic analysis to build the new statement.
1164 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001165 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1166 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001167 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001168 }
1169
1170 /// \brief Build a new indirect goto statement.
1171 ///
1172 /// By default, performs semantic analysis to build the new statement.
1173 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001174 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001175 SourceLocation StarLoc,
1176 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001177 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
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 return statement.
1181 ///
1182 /// By default, performs semantic analysis to build the new statement.
1183 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001184 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001185 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001186 }
Mike Stump1eb44332009-09-09 15:08:12 +00001187
Douglas Gregor43959a92009-08-20 07:17:43 +00001188 /// \brief Build a new declaration statement.
1189 ///
1190 /// By default, performs semantic analysis to build the new statement.
1191 /// Subclasses may override this routine to provide different behavior.
Rafael Espindola4549d7f2013-07-09 12:05:01 +00001192 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1193 SourceLocation StartLoc, SourceLocation EndLoc) {
1194 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith406c38e2011-02-23 00:37:57 +00001195 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001196 }
Mike Stump1eb44332009-09-09 15:08:12 +00001197
Anders Carlsson703e3942010-01-24 05:50:09 +00001198 /// \brief Build a new inline asm statement.
1199 ///
1200 /// By default, performs semantic analysis to build the new statement.
1201 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001202 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1203 bool IsVolatile, unsigned NumOutputs,
1204 unsigned NumInputs, IdentifierInfo **Names,
1205 MultiExprArg Constraints, MultiExprArg Exprs,
1206 Expr *AsmString, MultiExprArg Clobbers,
1207 SourceLocation RParenLoc) {
1208 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1209 NumInputs, Names, Constraints, Exprs,
1210 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001211 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001212
Chad Rosier8cd64b42012-06-11 20:47:18 +00001213 /// \brief Build a new MS style inline asm statement.
1214 ///
1215 /// By default, performs semantic analysis to build the new statement.
1216 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001217 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallaeeacf72013-05-03 00:10:13 +00001218 ArrayRef<Token> AsmToks,
1219 StringRef AsmString,
1220 unsigned NumOutputs, unsigned NumInputs,
1221 ArrayRef<StringRef> Constraints,
1222 ArrayRef<StringRef> Clobbers,
1223 ArrayRef<Expr*> Exprs,
1224 SourceLocation EndLoc) {
1225 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1226 NumOutputs, NumInputs,
1227 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001228 }
1229
James Dennett699c9042012-06-15 07:13:21 +00001230 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001231 ///
1232 /// By default, performs semantic analysis to build the new statement.
1233 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001234 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001235 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001236 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001237 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001238 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001239 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001240 }
1241
Douglas Gregorbe270a02010-04-26 17:57:08 +00001242 /// \brief Rebuild an Objective-C exception declaration.
1243 ///
1244 /// By default, performs semantic analysis to build the new declaration.
1245 /// Subclasses may override this routine to provide different behavior.
1246 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1247 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001248 return getSema().BuildObjCExceptionDecl(TInfo, T,
1249 ExceptionDecl->getInnerLocStart(),
1250 ExceptionDecl->getLocation(),
1251 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001252 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001253
James Dennett699c9042012-06-15 07:13:21 +00001254 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001255 ///
1256 /// By default, performs semantic analysis to build the new statement.
1257 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001258 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001259 SourceLocation RParenLoc,
1260 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001261 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001262 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001263 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001264 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001265
James Dennett699c9042012-06-15 07:13:21 +00001266 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001267 ///
1268 /// By default, performs semantic analysis to build the new statement.
1269 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001270 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001271 Stmt *Body) {
1272 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001273 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001274
James Dennett699c9042012-06-15 07:13:21 +00001275 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001276 ///
1277 /// By default, performs semantic analysis to build the new statement.
1278 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001279 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001280 Expr *Operand) {
1281 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001282 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001283
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00001284 /// \brief Build a new OpenMP parallel directive.
1285 ///
1286 /// By default, performs semantic analysis to build the new statement.
1287 /// Subclasses may override this routine to provide different behavior.
1288 StmtResult RebuildOMPParallelDirective(ArrayRef<OMPClause *> Clauses,
1289 Stmt *AStmt,
1290 SourceLocation StartLoc,
1291 SourceLocation EndLoc) {
1292 return getSema().ActOnOpenMPParallelDirective(Clauses, AStmt,
1293 StartLoc, EndLoc);
1294 }
1295
1296 /// \brief Build a new OpenMP 'default' clause.
1297 ///
1298 /// By default, performs semantic analysis to build the new statement.
1299 /// Subclasses may override this routine to provide different behavior.
1300 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1301 SourceLocation KindKwLoc,
1302 SourceLocation StartLoc,
1303 SourceLocation LParenLoc,
1304 SourceLocation EndLoc) {
1305 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1306 StartLoc, LParenLoc, EndLoc);
1307 }
1308
1309 /// \brief Build a new OpenMP 'private' clause.
1310 ///
1311 /// By default, performs semantic analysis to build the new statement.
1312 /// Subclasses may override this routine to provide different behavior.
1313 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1314 SourceLocation StartLoc,
1315 SourceLocation LParenLoc,
1316 SourceLocation EndLoc) {
1317 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1318 EndLoc);
1319 }
1320
Alexey Bataevd195bc32013-10-01 05:32:34 +00001321 /// \brief Build a new OpenMP 'firstprivate' clause.
1322 ///
1323 /// By default, performs semantic analysis to build the new statement.
1324 /// Subclasses may override this routine to provide different behavior.
1325 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1326 SourceLocation StartLoc,
1327 SourceLocation LParenLoc,
1328 SourceLocation EndLoc) {
1329 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1330 EndLoc);
1331 }
1332
Alexey Bataev0c018352013-09-06 18:03:48 +00001333 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1334 SourceLocation StartLoc,
1335 SourceLocation LParenLoc,
1336 SourceLocation EndLoc) {
1337 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1338 EndLoc);
1339 }
1340
James Dennett699c9042012-06-15 07:13:21 +00001341 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001342 ///
1343 /// By default, performs semantic analysis to build the new statement.
1344 /// Subclasses may override this routine to provide different behavior.
1345 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1346 Expr *object) {
1347 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1348 }
1349
James Dennett699c9042012-06-15 07:13:21 +00001350 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001351 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001352 /// By default, performs semantic analysis to build the new statement.
1353 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001354 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001355 Expr *Object, Stmt *Body) {
1356 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001357 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001358
James Dennett699c9042012-06-15 07:13:21 +00001359 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001360 ///
1361 /// By default, performs semantic analysis to build the new statement.
1362 /// Subclasses may override this routine to provide different behavior.
1363 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1364 Stmt *Body) {
1365 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1366 }
John McCall990567c2011-07-27 01:07:15 +00001367
Douglas Gregorc3203e72010-04-22 23:10:45 +00001368 /// \brief Build a new Objective-C fast enumeration statement.
1369 ///
1370 /// By default, performs semantic analysis to build the new statement.
1371 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001372 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001373 Stmt *Element,
1374 Expr *Collection,
1375 SourceLocation RParenLoc,
1376 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001377 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001378 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001379 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001380 RParenLoc);
1381 if (ForEachStmt.isInvalid())
1382 return StmtError();
1383
1384 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001385 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001386
Douglas Gregor43959a92009-08-20 07:17:43 +00001387 /// \brief Build a new C++ exception declaration.
1388 ///
1389 /// By default, performs semantic analysis to build the new decaration.
1390 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001391 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001392 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001393 SourceLocation StartLoc,
1394 SourceLocation IdLoc,
1395 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001396 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1397 StartLoc, IdLoc, Id);
1398 if (Var)
1399 getSema().CurContext->addDecl(Var);
1400 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001401 }
1402
1403 /// \brief Build a new C++ catch statement.
1404 ///
1405 /// By default, performs semantic analysis to build the new statement.
1406 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001407 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001408 VarDecl *ExceptionDecl,
1409 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001410 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1411 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001412 }
Mike Stump1eb44332009-09-09 15:08:12 +00001413
Douglas Gregor43959a92009-08-20 07:17:43 +00001414 /// \brief Build a new C++ try statement.
1415 ///
1416 /// By default, performs semantic analysis to build the new statement.
1417 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelm21adb0c2013-08-22 09:20:03 +00001418 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1419 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001420 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001421 }
Mike Stump1eb44332009-09-09 15:08:12 +00001422
Richard Smithad762fc2011-04-14 22:09:26 +00001423 /// \brief Build a new C++0x range-based for statement.
1424 ///
1425 /// By default, performs semantic analysis to build the new statement.
1426 /// Subclasses may override this routine to provide different behavior.
1427 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1428 SourceLocation ColonLoc,
1429 Stmt *Range, Stmt *BeginEnd,
1430 Expr *Cond, Expr *Inc,
1431 Stmt *LoopVar,
1432 SourceLocation RParenLoc) {
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001433 // If we've just learned that the range is actually an Objective-C
1434 // collection, treat this as an Objective-C fast enumeration loop.
1435 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1436 if (RangeStmt->isSingleDecl()) {
1437 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39b60dc2013-05-02 18:35:56 +00001438 if (RangeVar->isInvalidDecl())
1439 return StmtError();
1440
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001441 Expr *RangeExpr = RangeVar->getInit();
1442 if (!RangeExpr->isTypeDependent() &&
1443 RangeExpr->getType()->isObjCObjectPointerType())
1444 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1445 RParenLoc);
1446 }
1447 }
1448 }
1449
Richard Smithad762fc2011-04-14 22:09:26 +00001450 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001451 Cond, Inc, LoopVar, RParenLoc,
1452 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001453 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001454
1455 /// \brief Build a new C++0x range-based for statement.
1456 ///
1457 /// By default, performs semantic analysis to build the new statement.
1458 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001459 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001460 bool IsIfExists,
1461 NestedNameSpecifierLoc QualifierLoc,
1462 DeclarationNameInfo NameInfo,
1463 Stmt *Nested) {
1464 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1465 QualifierLoc, NameInfo, Nested);
1466 }
1467
Richard Smithad762fc2011-04-14 22:09:26 +00001468 /// \brief Attach body to a C++0x range-based for statement.
1469 ///
1470 /// By default, performs semantic analysis to finish the new statement.
1471 /// Subclasses may override this routine to provide different behavior.
1472 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1473 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1474 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001475
John Wiegley28bbe4b2011-04-28 01:08:34 +00001476 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1477 SourceLocation TryLoc,
1478 Stmt *TryBlock,
1479 Stmt *Handler) {
1480 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1481 }
1482
1483 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1484 Expr *FilterExpr,
1485 Stmt *Block) {
1486 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1487 }
1488
1489 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1490 Stmt *Block) {
1491 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1492 }
1493
Douglas Gregorb98b1992009-08-11 05:31:07 +00001494 /// \brief Build a new expression that references a declaration.
1495 ///
1496 /// By default, performs semantic analysis to build the new expression.
1497 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001498 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001499 LookupResult &R,
1500 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001501 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1502 }
1503
1504
1505 /// \brief Build a new expression that references a declaration.
1506 ///
1507 /// By default, performs semantic analysis to build the new expression.
1508 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001509 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001510 ValueDecl *VD,
1511 const DeclarationNameInfo &NameInfo,
1512 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001513 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001514 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001515
1516 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001517
1518 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001519 }
Mike Stump1eb44332009-09-09 15:08:12 +00001520
Douglas Gregorb98b1992009-08-11 05:31:07 +00001521 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001522 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001523 /// By default, performs semantic analysis to build the new expression.
1524 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001525 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001526 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001527 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001528 }
1529
Douglas Gregora71d8192009-09-04 17:36:40 +00001530 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001531 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001532 /// By default, performs semantic analysis to build the new expression.
1533 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001534 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001535 SourceLocation OperatorLoc,
1536 bool isArrow,
1537 CXXScopeSpec &SS,
1538 TypeSourceInfo *ScopeType,
1539 SourceLocation CCLoc,
1540 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001541 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001542
Douglas Gregorb98b1992009-08-11 05:31:07 +00001543 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001544 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001545 /// By default, performs semantic analysis to build the new expression.
1546 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001547 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001548 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001549 Expr *SubExpr) {
1550 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001551 }
Mike Stump1eb44332009-09-09 15:08:12 +00001552
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001553 /// \brief Build a new builtin offsetof expression.
1554 ///
1555 /// By default, performs semantic analysis to build the new expression.
1556 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001557 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001558 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001559 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001560 unsigned NumComponents,
1561 SourceLocation RParenLoc) {
1562 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1563 NumComponents, RParenLoc);
1564 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001565
1566 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001567 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001568 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001569 /// By default, performs semantic analysis to build the new expression.
1570 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001571 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1572 SourceLocation OpLoc,
1573 UnaryExprOrTypeTrait ExprKind,
1574 SourceRange R) {
1575 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001576 }
1577
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001578 /// \brief Build a new sizeof, alignof or vec step expression with an
1579 /// expression argument.
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.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001583 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1584 UnaryExprOrTypeTrait ExprKind,
1585 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001586 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001587 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001588 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001589 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001590
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001591 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001592 }
Mike Stump1eb44332009-09-09 15:08:12 +00001593
Douglas Gregorb98b1992009-08-11 05:31:07 +00001594 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001595 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001596 /// By default, performs semantic analysis to build the new expression.
1597 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001598 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001599 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001600 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001601 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001602 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1603 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001604 RBracketLoc);
1605 }
1606
1607 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001608 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001609 /// By default, performs semantic analysis to build the new expression.
1610 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001611 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001612 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001613 SourceLocation RParenLoc,
1614 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001615 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001616 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001617 }
1618
1619 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001620 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001621 /// By default, performs semantic analysis to build the new expression.
1622 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001623 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001624 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001625 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001626 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001627 const DeclarationNameInfo &MemberNameInfo,
1628 ValueDecl *Member,
1629 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001630 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001631 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001632 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1633 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001634 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001635 // We have a reference to an unnamed field. This is always the
1636 // base of an anonymous struct/union member access, i.e. the
1637 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001638 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001639 assert(Member->getType()->isRecordType() &&
1640 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001641
Richard Smith9138b4e2011-10-26 19:06:56 +00001642 BaseResult =
1643 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001644 QualifierLoc.getNestedNameSpecifier(),
1645 FoundDecl, Member);
1646 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001647 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001648 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001649 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001650 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001651 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001652 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001653 cast<FieldDecl>(Member)->getType(),
1654 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001655 return getSema().Owned(ME);
1656 }
Mike Stump1eb44332009-09-09 15:08:12 +00001657
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001658 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001659 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001660
John Wiegley429bb272011-04-08 18:41:53 +00001661 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001662 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001663
John McCall6bb80172010-03-30 21:47:33 +00001664 // FIXME: this involves duplicating earlier analysis in a lot of
1665 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001666 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001667 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001668 R.resolveKind();
1669
John McCall9ae2f072010-08-23 23:25:46 +00001670 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001671 SS, TemplateKWLoc,
1672 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001673 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001674 }
Mike Stump1eb44332009-09-09 15:08:12 +00001675
Douglas Gregorb98b1992009-08-11 05:31:07 +00001676 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001677 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001678 /// By default, performs semantic analysis to build the new expression.
1679 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001680 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001681 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001682 Expr *LHS, Expr *RHS) {
1683 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001684 }
1685
1686 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001687 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001688 /// By default, performs semantic analysis to build the new expression.
1689 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001690 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001691 SourceLocation QuestionLoc,
1692 Expr *LHS,
1693 SourceLocation ColonLoc,
1694 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001695 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1696 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001697 }
1698
Douglas Gregorb98b1992009-08-11 05:31:07 +00001699 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001700 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001701 /// By default, performs semantic analysis to build the new expression.
1702 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001703 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001704 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001705 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001706 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001707 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001708 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001709 }
Mike Stump1eb44332009-09-09 15:08:12 +00001710
Douglas Gregorb98b1992009-08-11 05:31:07 +00001711 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001712 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001713 /// By default, performs semantic analysis to build the new expression.
1714 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001715 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001716 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001717 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001718 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001719 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001720 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001721 }
Mike Stump1eb44332009-09-09 15:08:12 +00001722
Douglas Gregorb98b1992009-08-11 05:31:07 +00001723 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001724 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001725 /// By default, performs semantic analysis to build the new expression.
1726 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001727 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001728 SourceLocation OpLoc,
1729 SourceLocation AccessorLoc,
1730 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001731
John McCall129e2df2009-11-30 22:42:35 +00001732 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001733 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001734 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001735 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001736 SS, SourceLocation(),
1737 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001738 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001739 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001740 }
Mike Stump1eb44332009-09-09 15:08:12 +00001741
Douglas Gregorb98b1992009-08-11 05:31:07 +00001742 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001743 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001744 /// By default, performs semantic analysis to build the new expression.
1745 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001746 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001747 MultiExprArg Inits,
1748 SourceLocation RBraceLoc,
1749 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001750 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001751 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001752 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001753 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001754
Douglas Gregore48319a2009-11-09 17:16:50 +00001755 // Patch in the result type we were given, which may have been computed
1756 // when the initial InitListExpr was built.
1757 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1758 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001759 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001760 }
Mike Stump1eb44332009-09-09 15:08:12 +00001761
Douglas Gregorb98b1992009-08-11 05:31:07 +00001762 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001763 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001764 /// By default, performs semantic analysis to build the new expression.
1765 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001766 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001767 MultiExprArg ArrayExprs,
1768 SourceLocation EqualOrColonLoc,
1769 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001770 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001771 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001772 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001773 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001774 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001775 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001776
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001777 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001778 }
Mike Stump1eb44332009-09-09 15:08:12 +00001779
Douglas Gregorb98b1992009-08-11 05:31:07 +00001780 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001781 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001782 /// By default, builds the implicit value initialization without performing
1783 /// any semantic analysis. Subclasses may override this routine to provide
1784 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001785 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001786 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1787 }
Mike Stump1eb44332009-09-09 15:08:12 +00001788
Douglas Gregorb98b1992009-08-11 05:31:07 +00001789 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001790 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791 /// By default, performs semantic analysis to build the new expression.
1792 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001793 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001794 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001795 SourceLocation RParenLoc) {
1796 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001797 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001798 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001799 }
1800
1801 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001802 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001803 /// By default, performs semantic analysis to build the new expression.
1804 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001805 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001806 MultiExprArg SubExprs,
1807 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001808 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001809 }
Mike Stump1eb44332009-09-09 15:08:12 +00001810
Douglas Gregorb98b1992009-08-11 05:31:07 +00001811 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001812 ///
1813 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001814 /// rather than attempting to map the label statement itself.
1815 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001816 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001817 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001818 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001819 }
Mike Stump1eb44332009-09-09 15:08:12 +00001820
Douglas Gregorb98b1992009-08-11 05:31:07 +00001821 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001822 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001823 /// By default, performs semantic analysis to build the new expression.
1824 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001825 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001826 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001827 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001828 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001829 }
Mike Stump1eb44332009-09-09 15:08:12 +00001830
Douglas Gregorb98b1992009-08-11 05:31:07 +00001831 /// \brief Build a new __builtin_choose_expr expression.
1832 ///
1833 /// By default, performs semantic analysis to build the new expression.
1834 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001835 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001836 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001837 SourceLocation RParenLoc) {
1838 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001839 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001840 RParenLoc);
1841 }
Mike Stump1eb44332009-09-09 15:08:12 +00001842
Peter Collingbournef111d932011-04-15 00:35:48 +00001843 /// \brief Build a new generic selection expression.
1844 ///
1845 /// By default, performs semantic analysis to build the new expression.
1846 /// Subclasses may override this routine to provide different behavior.
1847 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1848 SourceLocation DefaultLoc,
1849 SourceLocation RParenLoc,
1850 Expr *ControllingExpr,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001851 ArrayRef<TypeSourceInfo *> Types,
1852 ArrayRef<Expr *> Exprs) {
Peter Collingbournef111d932011-04-15 00:35:48 +00001853 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001854 ControllingExpr, Types, Exprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00001855 }
1856
Douglas Gregorb98b1992009-08-11 05:31:07 +00001857 /// \brief Build a new overloaded operator call expression.
1858 ///
1859 /// By default, performs semantic analysis to build the new expression.
1860 /// The semantic analysis provides the behavior of template instantiation,
1861 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001862 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001863 /// argument-dependent lookup, etc. Subclasses may override this routine to
1864 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001865 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001866 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001867 Expr *Callee,
1868 Expr *First,
1869 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001870
1871 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001872 /// reinterpret_cast.
1873 ///
1874 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001875 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001876 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001877 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001878 Stmt::StmtClass Class,
1879 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001880 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001881 SourceLocation RAngleLoc,
1882 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001883 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001884 SourceLocation RParenLoc) {
1885 switch (Class) {
1886 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001887 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001888 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001889 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001890
1891 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001892 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001893 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001894 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001895
Douglas Gregorb98b1992009-08-11 05:31:07 +00001896 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001897 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001898 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001899 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001900 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001901
Douglas Gregorb98b1992009-08-11 05:31:07 +00001902 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001903 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001904 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001905 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001906
Douglas Gregorb98b1992009-08-11 05:31:07 +00001907 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001908 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001909 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001910 }
Mike Stump1eb44332009-09-09 15:08:12 +00001911
Douglas Gregorb98b1992009-08-11 05:31:07 +00001912 /// \brief Build a new C++ static_cast expression.
1913 ///
1914 /// By default, performs semantic analysis to build the new expression.
1915 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001916 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001917 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001918 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001919 SourceLocation RAngleLoc,
1920 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001921 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001922 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001923 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001924 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001925 SourceRange(LAngleLoc, RAngleLoc),
1926 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001927 }
1928
1929 /// \brief Build a new C++ dynamic_cast expression.
1930 ///
1931 /// By default, performs semantic analysis to build the new expression.
1932 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001933 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001934 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001935 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001936 SourceLocation RAngleLoc,
1937 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001938 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001939 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001940 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001941 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001942 SourceRange(LAngleLoc, RAngleLoc),
1943 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001944 }
1945
1946 /// \brief Build a new C++ reinterpret_cast expression.
1947 ///
1948 /// By default, performs semantic analysis to build the new expression.
1949 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001950 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001951 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001952 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001953 SourceLocation RAngleLoc,
1954 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001955 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001956 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001957 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001958 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001959 SourceRange(LAngleLoc, RAngleLoc),
1960 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001961 }
1962
1963 /// \brief Build a new C++ const_cast expression.
1964 ///
1965 /// By default, performs semantic analysis to build the new expression.
1966 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001967 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001968 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001969 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001970 SourceLocation RAngleLoc,
1971 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001972 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001973 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001974 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001975 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001976 SourceRange(LAngleLoc, RAngleLoc),
1977 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001978 }
Mike Stump1eb44332009-09-09 15:08:12 +00001979
Douglas Gregorb98b1992009-08-11 05:31:07 +00001980 /// \brief Build a new C++ functional-style cast expression.
1981 ///
1982 /// By default, performs semantic analysis to build the new expression.
1983 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001984 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1985 SourceLocation LParenLoc,
1986 Expr *Sub,
1987 SourceLocation RParenLoc) {
1988 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001989 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001990 RParenLoc);
1991 }
Mike Stump1eb44332009-09-09 15:08:12 +00001992
Douglas Gregorb98b1992009-08-11 05:31:07 +00001993 /// \brief Build a new C++ typeid(type) expression.
1994 ///
1995 /// By default, performs semantic analysis to build the new expression.
1996 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001997 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001998 SourceLocation TypeidLoc,
1999 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002000 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002001 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00002002 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002003 }
Mike Stump1eb44332009-09-09 15:08:12 +00002004
Francois Pichet01b7c302010-09-08 12:20:18 +00002005
Douglas Gregorb98b1992009-08-11 05:31:07 +00002006 /// \brief Build a new C++ typeid(expr) expression.
2007 ///
2008 /// By default, performs semantic analysis to build the new expression.
2009 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002010 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00002011 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00002012 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002013 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002014 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00002015 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002016 }
2017
Francois Pichet01b7c302010-09-08 12:20:18 +00002018 /// \brief Build a new C++ __uuidof(type) expression.
2019 ///
2020 /// By default, performs semantic analysis to build the new expression.
2021 /// Subclasses may override this routine to provide different behavior.
2022 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2023 SourceLocation TypeidLoc,
2024 TypeSourceInfo *Operand,
2025 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002026 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00002027 RParenLoc);
2028 }
2029
2030 /// \brief Build a new C++ __uuidof(expr) expression.
2031 ///
2032 /// By default, performs semantic analysis to build the new expression.
2033 /// Subclasses may override this routine to provide different behavior.
2034 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2035 SourceLocation TypeidLoc,
2036 Expr *Operand,
2037 SourceLocation RParenLoc) {
2038 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2039 RParenLoc);
2040 }
2041
Douglas Gregorb98b1992009-08-11 05:31:07 +00002042 /// \brief Build a new C++ "this" expression.
2043 ///
2044 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00002045 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00002046 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002047 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00002048 QualType ThisType,
2049 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00002050 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002051 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00002052 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2053 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002054 }
2055
2056 /// \brief Build a new C++ throw expression.
2057 ///
2058 /// By default, performs semantic analysis to build the new expression.
2059 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00002060 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2061 bool IsThrownVariableInScope) {
2062 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002063 }
2064
2065 /// \brief Build a new C++ default-argument expression.
2066 ///
2067 /// By default, builds a new default-argument expression, which does not
2068 /// require any semantic analysis. Subclasses may override this routine to
2069 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002070 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00002071 ParmVarDecl *Param) {
2072 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2073 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002074 }
2075
Richard Smithc3bf52c2013-04-20 22:23:05 +00002076 /// \brief Build a new C++11 default-initialization expression.
2077 ///
2078 /// By default, builds a new default field initialization expression, which
2079 /// does not require any semantic analysis. Subclasses may override this
2080 /// routine to provide different behavior.
2081 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2082 FieldDecl *Field) {
2083 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2084 Field));
2085 }
2086
Douglas Gregorb98b1992009-08-11 05:31:07 +00002087 /// \brief Build a new C++ zero-initialization expression.
2088 ///
2089 /// By default, performs semantic analysis to build the new expression.
2090 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002091 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2092 SourceLocation LParenLoc,
2093 SourceLocation RParenLoc) {
2094 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002095 None, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002096 }
Mike Stump1eb44332009-09-09 15:08:12 +00002097
Douglas Gregorb98b1992009-08-11 05:31:07 +00002098 /// \brief Build a new C++ "new" expression.
2099 ///
2100 /// By default, performs semantic analysis to build the new expression.
2101 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002102 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002103 bool UseGlobal,
2104 SourceLocation PlacementLParen,
2105 MultiExprArg PlacementArgs,
2106 SourceLocation PlacementRParen,
2107 SourceRange TypeIdParens,
2108 QualType AllocatedType,
2109 TypeSourceInfo *AllocatedTypeInfo,
2110 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002111 SourceRange DirectInitRange,
2112 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00002113 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002114 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002115 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002116 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002117 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002118 AllocatedType,
2119 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002120 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002121 DirectInitRange,
2122 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002123 }
Mike Stump1eb44332009-09-09 15:08:12 +00002124
Douglas Gregorb98b1992009-08-11 05:31:07 +00002125 /// \brief Build a new C++ "delete" expression.
2126 ///
2127 /// By default, performs semantic analysis to build the new expression.
2128 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002129 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002130 bool IsGlobalDelete,
2131 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002132 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002133 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002134 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002135 }
Mike Stump1eb44332009-09-09 15:08:12 +00002136
Douglas Gregorb98b1992009-08-11 05:31:07 +00002137 /// \brief Build a new unary type trait expression.
2138 ///
2139 /// By default, performs semantic analysis to build the new expression.
2140 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002141 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002142 SourceLocation StartLoc,
2143 TypeSourceInfo *T,
2144 SourceLocation RParenLoc) {
2145 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002146 }
2147
Francois Pichet6ad6f282010-12-07 00:08:36 +00002148 /// \brief Build a new binary type trait expression.
2149 ///
2150 /// By default, performs semantic analysis to build the new expression.
2151 /// Subclasses may override this routine to provide different behavior.
2152 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2153 SourceLocation StartLoc,
2154 TypeSourceInfo *LhsT,
2155 TypeSourceInfo *RhsT,
2156 SourceLocation RParenLoc) {
2157 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2158 }
2159
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002160 /// \brief Build a new type trait expression.
2161 ///
2162 /// By default, performs semantic analysis to build the new expression.
2163 /// Subclasses may override this routine to provide different behavior.
2164 ExprResult RebuildTypeTrait(TypeTrait Trait,
2165 SourceLocation StartLoc,
2166 ArrayRef<TypeSourceInfo *> Args,
2167 SourceLocation RParenLoc) {
2168 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2169 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002170
John Wiegley21ff2e52011-04-28 00:16:57 +00002171 /// \brief Build a new array type trait expression.
2172 ///
2173 /// By default, performs semantic analysis to build the new expression.
2174 /// Subclasses may override this routine to provide different behavior.
2175 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2176 SourceLocation StartLoc,
2177 TypeSourceInfo *TSInfo,
2178 Expr *DimExpr,
2179 SourceLocation RParenLoc) {
2180 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2181 }
2182
John Wiegley55262202011-04-25 06:54:41 +00002183 /// \brief Build a new expression trait expression.
2184 ///
2185 /// By default, performs semantic analysis to build the new expression.
2186 /// Subclasses may override this routine to provide different behavior.
2187 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2188 SourceLocation StartLoc,
2189 Expr *Queried,
2190 SourceLocation RParenLoc) {
2191 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2192 }
2193
Mike Stump1eb44332009-09-09 15:08:12 +00002194 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002195 /// expression.
2196 ///
2197 /// By default, performs semantic analysis to build the new expression.
2198 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002199 ExprResult RebuildDependentScopeDeclRefExpr(
2200 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002201 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002202 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002203 const TemplateArgumentListInfo *TemplateArgs,
2204 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002205 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002206 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002207
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002208 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002209 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002210 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002211
Richard Smithefeeccf2012-10-21 03:28:35 +00002212 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2213 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002214 }
2215
2216 /// \brief Build a new template-id expression.
2217 ///
2218 /// By default, performs semantic analysis to build the new expression.
2219 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002220 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002221 SourceLocation TemplateKWLoc,
2222 LookupResult &R,
2223 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002224 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002225 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2226 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002227 }
2228
2229 /// \brief Build a new object-construction expression.
2230 ///
2231 /// By default, performs semantic analysis to build the new expression.
2232 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002233 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002234 SourceLocation Loc,
2235 CXXConstructorDecl *Constructor,
2236 bool IsElidable,
2237 MultiExprArg Args,
2238 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002239 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002240 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002241 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002242 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002243 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002244 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002245 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002246 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002247
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002248 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002249 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002250 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002251 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002252 RequiresZeroInit, ConstructKind,
2253 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002254 }
2255
2256 /// \brief Build a new object-construction expression.
2257 ///
2258 /// By default, performs semantic analysis to build the new expression.
2259 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002260 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2261 SourceLocation LParenLoc,
2262 MultiExprArg Args,
2263 SourceLocation RParenLoc) {
2264 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002265 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002266 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002267 RParenLoc);
2268 }
2269
2270 /// \brief Build a new object-construction expression.
2271 ///
2272 /// By default, performs semantic analysis to build the new expression.
2273 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002274 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2275 SourceLocation LParenLoc,
2276 MultiExprArg Args,
2277 SourceLocation RParenLoc) {
2278 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002279 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002280 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002281 RParenLoc);
2282 }
Mike Stump1eb44332009-09-09 15:08:12 +00002283
Douglas Gregorb98b1992009-08-11 05:31:07 +00002284 /// \brief Build a new member reference expression.
2285 ///
2286 /// By default, performs semantic analysis to build the new expression.
2287 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002288 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002289 QualType BaseType,
2290 bool IsArrow,
2291 SourceLocation OperatorLoc,
2292 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002293 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002294 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002295 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002296 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002297 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002298 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002299
John McCall9ae2f072010-08-23 23:25:46 +00002300 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002301 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002302 SS, TemplateKWLoc,
2303 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002304 MemberNameInfo,
2305 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002306 }
2307
John McCall129e2df2009-11-30 22:42:35 +00002308 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002309 ///
2310 /// By default, performs semantic analysis to build the new expression.
2311 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002312 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2313 SourceLocation OperatorLoc,
2314 bool IsArrow,
2315 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002316 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002317 NamedDecl *FirstQualifierInScope,
2318 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002319 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002320 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002321 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002322
John McCall9ae2f072010-08-23 23:25:46 +00002323 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002324 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002325 SS, TemplateKWLoc,
2326 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002327 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002328 }
Mike Stump1eb44332009-09-09 15:08:12 +00002329
Sebastian Redl2e156222010-09-10 20:55:43 +00002330 /// \brief Build a new noexcept expression.
2331 ///
2332 /// By default, performs semantic analysis to build the new expression.
2333 /// Subclasses may override this routine to provide different behavior.
2334 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2335 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2336 }
2337
Douglas Gregoree8aff02011-01-04 17:33:58 +00002338 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002339 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2340 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002341 SourceLocation RParenLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002342 Optional<unsigned> Length) {
Douglas Gregor089e8932011-10-10 18:59:29 +00002343 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002344 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2345 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002346 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002347
2348 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2349 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002350 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002351 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002352
Patrick Beardeb382ec2012-04-19 00:25:12 +00002353 /// \brief Build a new Objective-C boxed expression.
2354 ///
2355 /// By default, performs semantic analysis to build the new expression.
2356 /// Subclasses may override this routine to provide different behavior.
2357 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2358 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2359 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002360
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002361 /// \brief Build a new Objective-C array literal.
2362 ///
2363 /// By default, performs semantic analysis to build the new expression.
2364 /// Subclasses may override this routine to provide different behavior.
2365 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2366 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002367 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002368 MultiExprArg(Elements, NumElements));
2369 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002370
2371 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002372 Expr *Base, Expr *Key,
2373 ObjCMethodDecl *getterMethod,
2374 ObjCMethodDecl *setterMethod) {
2375 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2376 getterMethod, setterMethod);
2377 }
2378
2379 /// \brief Build a new Objective-C dictionary literal.
2380 ///
2381 /// By default, performs semantic analysis to build the new expression.
2382 /// Subclasses may override this routine to provide different behavior.
2383 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2384 ObjCDictionaryElement *Elements,
2385 unsigned NumElements) {
2386 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2387 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002388
James Dennett699c9042012-06-15 07:13:21 +00002389 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002390 ///
2391 /// By default, performs semantic analysis to build the new expression.
2392 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002393 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002394 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002395 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002396 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002397 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002398 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002399
Douglas Gregor92e986e2010-04-22 16:44:27 +00002400 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002401 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002402 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002403 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002404 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002405 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002406 MultiExprArg Args,
2407 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002408 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2409 ReceiverTypeInfo->getType(),
2410 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002411 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002412 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002413 }
2414
2415 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002416 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002417 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002418 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002419 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002420 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002421 MultiExprArg Args,
2422 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002423 return SemaRef.BuildInstanceMessage(Receiver,
2424 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002425 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002426 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002427 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002428 }
2429
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002430 /// \brief Build a new Objective-C ivar reference expression.
2431 ///
2432 /// By default, performs semantic analysis to build the new expression.
2433 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002434 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002435 SourceLocation IvarLoc,
2436 bool IsArrow, bool IsFreeIvar) {
2437 // FIXME: We lose track of the IsFreeIvar bit.
2438 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002439 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002440 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2441 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002442 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002443 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002444 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002445 false);
John Wiegley429bb272011-04-08 18:41:53 +00002446 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002447 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002448
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002449 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002450 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002451
John Wiegley429bb272011-04-08 18:41:53 +00002452 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002453 /*FIXME:*/IvarLoc, IsArrow,
2454 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002455 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002456 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002457 /*TemplateArgs=*/0);
2458 }
Douglas Gregore3303542010-04-26 20:47:02 +00002459
2460 /// \brief Build a new Objective-C property reference expression.
2461 ///
2462 /// By default, performs semantic analysis to build the new expression.
2463 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002464 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002465 ObjCPropertyDecl *Property,
2466 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002467 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002468 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002469 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2470 Sema::LookupMemberName);
2471 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002472 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002473 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002474 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002475 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002476 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002477
Douglas Gregore3303542010-04-26 20:47:02 +00002478 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002479 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002480
John Wiegley429bb272011-04-08 18:41:53 +00002481 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002482 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002483 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002484 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002485 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002486 /*TemplateArgs=*/0);
2487 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002488
John McCall12f78a62010-12-02 01:19:52 +00002489 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002490 ///
2491 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002492 /// Subclasses may override this routine to provide different behavior.
2493 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2494 ObjCMethodDecl *Getter,
2495 ObjCMethodDecl *Setter,
2496 SourceLocation PropertyLoc) {
2497 // Since these expressions can only be value-dependent, we do not
2498 // need to perform semantic analysis again.
2499 return Owned(
2500 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2501 VK_LValue, OK_ObjCProperty,
2502 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002503 }
2504
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002505 /// \brief Build a new Objective-C "isa" 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 RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002510 SourceLocation OpLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002511 bool IsArrow) {
2512 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002513 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002514 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2515 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002516 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002517 OpLoc,
John McCalld226f652010-08-21 09:40:31 +00002518 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002519 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002520 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002521
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002522 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002523 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002524
John Wiegley429bb272011-04-08 18:41:53 +00002525 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002526 OpLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002527 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002528 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002529 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002530 /*TemplateArgs=*/0);
2531 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002532
Douglas Gregorb98b1992009-08-11 05:31:07 +00002533 /// \brief Build a new shuffle vector expression.
2534 ///
2535 /// By default, performs semantic analysis to build the new expression.
2536 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002537 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002538 MultiExprArg SubExprs,
2539 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002540 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002541 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002542 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2543 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2544 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002545 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002546
Douglas Gregorb98b1992009-08-11 05:31:07 +00002547 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002548 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002549 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2550 SemaRef.Context.BuiltinFnTy,
2551 VK_RValue, BuiltinLoc);
2552 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2553 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2554 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002555
2556 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002557 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002558 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002559 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002560 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002561 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002562
Douglas Gregorb98b1992009-08-11 05:31:07 +00002563 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002564 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002565 }
John McCall43fed0d2010-11-12 08:19:04 +00002566
Hal Finkel414a1bd2013-09-18 03:29:45 +00002567 /// \brief Build a new convert vector expression.
2568 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2569 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2570 SourceLocation RParenLoc) {
2571 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2572 BuiltinLoc, RParenLoc);
2573 }
2574
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002575 /// \brief Build a new template argument pack expansion.
2576 ///
2577 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002578 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002579 /// different behavior.
2580 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002581 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002582 Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002583 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002584 case TemplateArgument::Expression: {
2585 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002586 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2587 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002588 if (Result.isInvalid())
2589 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002590
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002591 return TemplateArgumentLoc(Result.get(), Result.get());
2592 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002593
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002594 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002595 return TemplateArgumentLoc(TemplateArgument(
2596 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002597 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002598 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002599 Pattern.getTemplateNameLoc(),
2600 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002601
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002602 case TemplateArgument::Null:
2603 case TemplateArgument::Integral:
2604 case TemplateArgument::Declaration:
2605 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002606 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002607 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002608 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002609
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002610 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002611 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002612 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002613 EllipsisLoc,
2614 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002615 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2616 Expansion);
2617 break;
2618 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002619
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002620 return TemplateArgumentLoc();
2621 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002622
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002623 /// \brief Build a new expression pack expansion.
2624 ///
2625 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002626 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002627 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002628 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002629 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002630 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002631 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002632
2633 /// \brief Build a new atomic operation expression.
2634 ///
2635 /// By default, performs semantic analysis to build the new expression.
2636 /// Subclasses may override this routine to provide different behavior.
2637 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2638 MultiExprArg SubExprs,
2639 QualType RetTy,
2640 AtomicExpr::AtomicOp Op,
2641 SourceLocation RParenLoc) {
2642 // Just create the expression; there is not any interesting semantic
2643 // analysis here because we can't actually build an AtomicExpr until
2644 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002645 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002646 RParenLoc);
2647 }
2648
John McCall43fed0d2010-11-12 08:19:04 +00002649private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002650 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2651 QualType ObjectType,
2652 NamedDecl *FirstQualifierInScope,
2653 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002654
2655 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2656 QualType ObjectType,
2657 NamedDecl *FirstQualifierInScope,
2658 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002659};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002660
Douglas Gregor43959a92009-08-20 07:17:43 +00002661template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002662StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002663 if (!S)
2664 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002665
Douglas Gregor43959a92009-08-20 07:17:43 +00002666 switch (S->getStmtClass()) {
2667 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002668
Douglas Gregor43959a92009-08-20 07:17:43 +00002669 // Transform individual statement nodes
2670#define STMT(Node, Parent) \
2671 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002672#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002673#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002674#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002675
Douglas Gregor43959a92009-08-20 07:17:43 +00002676 // Transform expressions by calling TransformExpr.
2677#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002678#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002679#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002680#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002681 {
John McCall60d7b3a2010-08-24 06:29:42 +00002682 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002683 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002684 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002685
Richard Smith41956372013-01-14 22:39:08 +00002686 return getSema().ActOnExprStmt(E);
Douglas Gregor43959a92009-08-20 07:17:43 +00002687 }
Mike Stump1eb44332009-09-09 15:08:12 +00002688 }
2689
John McCall3fa5cae2010-10-26 07:05:15 +00002690 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002691}
Mike Stump1eb44332009-09-09 15:08:12 +00002692
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002693template<typename Derived>
2694OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2695 if (!S)
2696 return S;
2697
2698 switch (S->getClauseKind()) {
2699 default: break;
2700 // Transform individual clause nodes
2701#define OPENMP_CLAUSE(Name, Class) \
2702 case OMPC_ ## Name : \
2703 return getDerived().Transform ## Class(cast<Class>(S));
2704#include "clang/Basic/OpenMPKinds.def"
2705 }
2706
2707 return S;
2708}
2709
Mike Stump1eb44332009-09-09 15:08:12 +00002710
Douglas Gregor670444e2009-08-04 22:27:00 +00002711template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002712ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002713 if (!E)
2714 return SemaRef.Owned(E);
2715
2716 switch (E->getStmtClass()) {
2717 case Stmt::NoStmtClass: break;
2718#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002719#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002720#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002721 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002722#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002723 }
2724
John McCall3fa5cae2010-10-26 07:05:15 +00002725 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002726}
2727
2728template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002729ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2730 bool CXXDirectInit) {
2731 // Initializers are instantiated like expressions, except that various outer
2732 // layers are stripped.
2733 if (!Init)
2734 return SemaRef.Owned(Init);
2735
2736 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2737 Init = ExprTemp->getSubExpr();
2738
Richard Smith858c2c32013-05-30 22:40:16 +00002739 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2740 Init = MTE->GetTemporaryExpr();
2741
Richard Smithc83c2302012-12-19 01:39:02 +00002742 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2743 Init = Binder->getSubExpr();
2744
2745 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2746 Init = ICE->getSubExprAsWritten();
2747
Richard Smith7c3e6152013-06-12 22:31:48 +00002748 if (CXXStdInitializerListExpr *ILE =
2749 dyn_cast<CXXStdInitializerListExpr>(Init))
2750 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2751
Richard Smith5cf15892012-12-21 08:13:35 +00002752 // If this is not a direct-initializer, we only need to reconstruct
2753 // InitListExprs. Other forms of copy-initialization will be a no-op if
2754 // the initializer is already the right type.
2755 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2756 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2757 return getDerived().TransformExpr(Init);
2758
2759 // Revert value-initialization back to empty parens.
2760 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2761 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002762 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002763 Parens.getEnd());
2764 }
2765
2766 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2767 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002768 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002769 SourceLocation());
2770
2771 // Revert initialization by constructor back to a parenthesized or braced list
2772 // of expressions. Any other form of initializer can just be reused directly.
2773 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002774 return getDerived().TransformExpr(Init);
2775
2776 SmallVector<Expr*, 8> NewArgs;
2777 bool ArgChanged = false;
2778 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2779 /*IsCall*/true, NewArgs, &ArgChanged))
2780 return ExprError();
2781
2782 // If this was list initialization, revert to list form.
2783 if (Construct->isListInitialization())
2784 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2785 Construct->getLocEnd(),
2786 Construct->getType());
2787
Richard Smithc83c2302012-12-19 01:39:02 +00002788 // Build a ParenListExpr to represent anything else.
Enea Zaffanella1245a542013-09-07 05:49:53 +00002789 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithc83c2302012-12-19 01:39:02 +00002790 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2791 Parens.getEnd());
2792}
2793
2794template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002795bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2796 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002797 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002798 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002799 bool *ArgChanged) {
2800 for (unsigned I = 0; I != NumInputs; ++I) {
2801 // If requested, drop call arguments that need to be dropped.
2802 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2803 if (ArgChanged)
2804 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002805
Douglas Gregoraa165f82011-01-03 19:04:46 +00002806 break;
2807 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002808
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002809 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2810 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002811
Chris Lattner686775d2011-07-20 06:58:45 +00002812 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002813 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2814 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002815
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002816 // Determine whether the set of unexpanded parameter packs can and should
2817 // be expanded.
2818 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002819 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00002820 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2821 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002822 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2823 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002824 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002825 Expand, RetainExpansion,
2826 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002827 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002828
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002829 if (!Expand) {
2830 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002831 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002832 // expansion.
2833 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2834 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2835 if (OutPattern.isInvalid())
2836 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002837
2838 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002839 Expansion->getEllipsisLoc(),
2840 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002841 if (Out.isInvalid())
2842 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002843
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002844 if (ArgChanged)
2845 *ArgChanged = true;
2846 Outputs.push_back(Out.get());
2847 continue;
2848 }
John McCallc8fc90a2011-07-06 07:30:07 +00002849
2850 // Record right away that the argument was changed. This needs
2851 // to happen even if the array expands to nothing.
2852 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002853
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002854 // The transform has determined that we should perform an elementwise
2855 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002856 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002857 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2858 ExprResult Out = getDerived().TransformExpr(Pattern);
2859 if (Out.isInvalid())
2860 return true;
2861
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002862 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002863 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2864 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002865 if (Out.isInvalid())
2866 return true;
2867 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002868
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002869 Outputs.push_back(Out.get());
2870 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002871
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002872 continue;
2873 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002874
Richard Smithc83c2302012-12-19 01:39:02 +00002875 ExprResult Result =
2876 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2877 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002878 if (Result.isInvalid())
2879 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002880
Douglas Gregoraa165f82011-01-03 19:04:46 +00002881 if (Result.get() != Inputs[I] && ArgChanged)
2882 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002883
2884 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002885 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002886
Douglas Gregoraa165f82011-01-03 19:04:46 +00002887 return false;
2888}
2889
2890template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002891NestedNameSpecifierLoc
2892TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2893 NestedNameSpecifierLoc NNS,
2894 QualType ObjectType,
2895 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002896 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002897 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002898 Qualifier = Qualifier.getPrefix())
2899 Qualifiers.push_back(Qualifier);
2900
2901 CXXScopeSpec SS;
2902 while (!Qualifiers.empty()) {
2903 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2904 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002905
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002906 switch (QNNS->getKind()) {
2907 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002908 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002909 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002910 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002911 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002912 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002913 FirstQualifierInScope, false))
2914 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002915
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002916 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002917
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002918 case NestedNameSpecifier::Namespace: {
2919 NamespaceDecl *NS
2920 = cast_or_null<NamespaceDecl>(
2921 getDerived().TransformDecl(
2922 Q.getLocalBeginLoc(),
2923 QNNS->getAsNamespace()));
2924 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2925 break;
2926 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002927
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002928 case NestedNameSpecifier::NamespaceAlias: {
2929 NamespaceAliasDecl *Alias
2930 = cast_or_null<NamespaceAliasDecl>(
2931 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2932 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002933 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002934 Q.getLocalEndLoc());
2935 break;
2936 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002937
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002938 case NestedNameSpecifier::Global:
2939 // There is no meaningful transformation that one could perform on the
2940 // global scope.
2941 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2942 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002943
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002944 case NestedNameSpecifier::TypeSpecWithTemplate:
2945 case NestedNameSpecifier::TypeSpec: {
2946 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2947 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002948
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002949 if (!TL)
2950 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002951
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002952 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002953 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002954 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002955 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002956 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002957 if (TL.getType()->isEnumeralType())
2958 SemaRef.Diag(TL.getBeginLoc(),
2959 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002960 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2961 Q.getLocalEndLoc());
2962 break;
2963 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002964 // If the nested-name-specifier is an invalid type def, don't emit an
2965 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002966 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2967 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002968 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002969 << TL.getType() << SS.getRange();
2970 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002971 return NestedNameSpecifierLoc();
2972 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002973 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002974
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002975 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002976 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002977 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002978 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002979
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002980 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002981 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002982 !getDerived().AlwaysRebuild())
2983 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002984
2985 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002986 // nested-name-specifier, do so.
2987 if (SS.location_size() == NNS.getDataLength() &&
2988 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2989 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2990
2991 // Allocate new nested-name-specifier location information.
2992 return SS.getWithLocInContext(SemaRef.Context);
2993}
2994
2995template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002996DeclarationNameInfo
2997TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002998::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002999 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00003000 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00003001 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00003002
3003 switch (Name.getNameKind()) {
3004 case DeclarationName::Identifier:
3005 case DeclarationName::ObjCZeroArgSelector:
3006 case DeclarationName::ObjCOneArgSelector:
3007 case DeclarationName::ObjCMultiArgSelector:
3008 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00003009 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00003010 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00003011 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00003012
Douglas Gregor81499bb2009-09-03 22:13:48 +00003013 case DeclarationName::CXXConstructorName:
3014 case DeclarationName::CXXDestructorName:
3015 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00003016 TypeSourceInfo *NewTInfo;
3017 CanQualType NewCanTy;
3018 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00003019 NewTInfo = getDerived().TransformType(OldTInfo);
3020 if (!NewTInfo)
3021 return DeclarationNameInfo();
3022 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00003023 }
3024 else {
3025 NewTInfo = 0;
3026 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00003027 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00003028 if (NewT.isNull())
3029 return DeclarationNameInfo();
3030 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3031 }
Mike Stump1eb44332009-09-09 15:08:12 +00003032
Abramo Bagnara25777432010-08-11 22:01:17 +00003033 DeclarationName NewName
3034 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3035 NewCanTy);
3036 DeclarationNameInfo NewNameInfo(NameInfo);
3037 NewNameInfo.setName(NewName);
3038 NewNameInfo.setNamedTypeInfo(NewTInfo);
3039 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00003040 }
Mike Stump1eb44332009-09-09 15:08:12 +00003041 }
3042
David Blaikieb219cfc2011-09-23 05:06:16 +00003043 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00003044}
3045
3046template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003047TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003048TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3049 TemplateName Name,
3050 SourceLocation NameLoc,
3051 QualType ObjectType,
3052 NamedDecl *FirstQualifierInScope) {
3053 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3054 TemplateDecl *Template = QTN->getTemplateDecl();
3055 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003056
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003057 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003058 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003059 Template));
3060 if (!TransTemplate)
3061 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003062
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003063 if (!getDerived().AlwaysRebuild() &&
3064 SS.getScopeRep() == QTN->getQualifier() &&
3065 TransTemplate == Template)
3066 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003067
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003068 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3069 TransTemplate);
3070 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003071
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003072 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3073 if (SS.getScopeRep()) {
3074 // These apply to the scope specifier, not the template.
3075 ObjectType = QualType();
3076 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003077 }
3078
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003079 if (!getDerived().AlwaysRebuild() &&
3080 SS.getScopeRep() == DTN->getQualifier() &&
3081 ObjectType.isNull())
3082 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003083
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003084 if (DTN->isIdentifier()) {
3085 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003086 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003087 NameLoc,
3088 ObjectType,
3089 FirstQualifierInScope);
3090 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003091
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003092 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3093 ObjectType);
3094 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003095
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003096 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3097 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003098 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003099 Template));
3100 if (!TransTemplate)
3101 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003102
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003103 if (!getDerived().AlwaysRebuild() &&
3104 TransTemplate == Template)
3105 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003106
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003107 return TemplateName(TransTemplate);
3108 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003109
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003110 if (SubstTemplateTemplateParmPackStorage *SubstPack
3111 = Name.getAsSubstTemplateTemplateParmPack()) {
3112 TemplateTemplateParmDecl *TransParam
3113 = cast_or_null<TemplateTemplateParmDecl>(
3114 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3115 if (!TransParam)
3116 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003117
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003118 if (!getDerived().AlwaysRebuild() &&
3119 TransParam == SubstPack->getParameterPack())
3120 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003121
3122 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003123 SubstPack->getArgumentPack());
3124 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003125
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003126 // These should be getting filtered out before they reach the AST.
3127 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003128}
3129
3130template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003131void TreeTransform<Derived>::InventTemplateArgumentLoc(
3132 const TemplateArgument &Arg,
3133 TemplateArgumentLoc &Output) {
3134 SourceLocation Loc = getDerived().getBaseLocation();
3135 switch (Arg.getKind()) {
3136 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003137 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00003138 break;
3139
3140 case TemplateArgument::Type:
3141 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00003142 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00003143
John McCall833ca992009-10-29 08:12:44 +00003144 break;
3145
Douglas Gregor788cd062009-11-11 01:00:40 +00003146 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003147 case TemplateArgument::TemplateExpansion: {
3148 NestedNameSpecifierLocBuilder Builder;
3149 TemplateName Template = Arg.getAsTemplate();
3150 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3151 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3152 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3153 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003154
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003155 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003156 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003157 Builder.getWithLocInContext(SemaRef.Context),
3158 Loc);
3159 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003160 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003161 Builder.getWithLocInContext(SemaRef.Context),
3162 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003163
Douglas Gregor788cd062009-11-11 01:00:40 +00003164 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003165 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003166
John McCall833ca992009-10-29 08:12:44 +00003167 case TemplateArgument::Expression:
3168 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3169 break;
3170
3171 case TemplateArgument::Declaration:
3172 case TemplateArgument::Integral:
3173 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003174 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003175 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003176 break;
3177 }
3178}
3179
3180template<typename Derived>
3181bool TreeTransform<Derived>::TransformTemplateArgument(
3182 const TemplateArgumentLoc &Input,
3183 TemplateArgumentLoc &Output) {
3184 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003185 switch (Arg.getKind()) {
3186 case TemplateArgument::Null:
3187 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003188 case TemplateArgument::Pack:
3189 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003190 case TemplateArgument::NullPtr:
3191 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003192
Douglas Gregor670444e2009-08-04 22:27:00 +00003193 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003194 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003195 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003196 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003197
3198 DI = getDerived().TransformType(DI);
3199 if (!DI) return true;
3200
3201 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3202 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003203 }
Mike Stump1eb44332009-09-09 15:08:12 +00003204
Douglas Gregor788cd062009-11-11 01:00:40 +00003205 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003206 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3207 if (QualifierLoc) {
3208 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3209 if (!QualifierLoc)
3210 return true;
3211 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003212
Douglas Gregor1d752d72011-03-02 18:46:51 +00003213 CXXScopeSpec SS;
3214 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003215 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003216 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3217 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003218 if (Template.isNull())
3219 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003220
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003221 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003222 Input.getTemplateNameLoc());
3223 return false;
3224 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003225
3226 case TemplateArgument::TemplateExpansion:
3227 llvm_unreachable("Caller should expand pack expansions");
3228
Douglas Gregor670444e2009-08-04 22:27:00 +00003229 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003230 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003231 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003232 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003233
John McCall833ca992009-10-29 08:12:44 +00003234 Expr *InputExpr = Input.getSourceExpression();
3235 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3236
Chris Lattner223de242011-04-25 20:37:58 +00003237 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003238 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003239 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003240 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003241 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003242 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003243 }
Mike Stump1eb44332009-09-09 15:08:12 +00003244
Douglas Gregor670444e2009-08-04 22:27:00 +00003245 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003246 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003247}
3248
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003249/// \brief Iterator adaptor that invents template argument location information
3250/// for each of the template arguments in its underlying iterator.
3251template<typename Derived, typename InputIterator>
3252class TemplateArgumentLocInventIterator {
3253 TreeTransform<Derived> &Self;
3254 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003255
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003256public:
3257 typedef TemplateArgumentLoc value_type;
3258 typedef TemplateArgumentLoc reference;
3259 typedef typename std::iterator_traits<InputIterator>::difference_type
3260 difference_type;
3261 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003262
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003263 class pointer {
3264 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003265
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003266 public:
3267 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003268
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003269 const TemplateArgumentLoc *operator->() const { return &Arg; }
3270 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003271
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003272 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003273
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003274 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3275 InputIterator Iter)
3276 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003277
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003278 TemplateArgumentLocInventIterator &operator++() {
3279 ++Iter;
3280 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003281 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003282
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003283 TemplateArgumentLocInventIterator operator++(int) {
3284 TemplateArgumentLocInventIterator Old(*this);
3285 ++(*this);
3286 return Old;
3287 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003288
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003289 reference operator*() const {
3290 TemplateArgumentLoc Result;
3291 Self.InventTemplateArgumentLoc(*Iter, Result);
3292 return Result;
3293 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003294
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003295 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003296
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003297 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3298 const TemplateArgumentLocInventIterator &Y) {
3299 return X.Iter == Y.Iter;
3300 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003301
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003302 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3303 const TemplateArgumentLocInventIterator &Y) {
3304 return X.Iter != Y.Iter;
3305 }
3306};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003307
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003308template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003309template<typename InputIterator>
3310bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3311 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003312 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003313 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003314 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003315 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003316
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003317 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3318 // Unpack argument packs, which we translate them into separate
3319 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003320 // FIXME: We could do much better if we could guarantee that the
3321 // TemplateArgumentLocInfo for the pack expansion would be usable for
3322 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003323 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003324 TemplateArgument::pack_iterator>
3325 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003326 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003327 In.getArgument().pack_begin()),
3328 PackLocIterator(*this,
3329 In.getArgument().pack_end()),
3330 Outputs))
3331 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003332
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003333 continue;
3334 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003335
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003336 if (In.getArgument().isPackExpansion()) {
3337 // We have a pack expansion, for which we will be substituting into
3338 // the pattern.
3339 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003340 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003341 TemplateArgumentLoc Pattern
Eli Friedman850cf512013-06-20 04:11:21 +00003342 = getSema().getTemplateArgumentPackExpansionPattern(
3343 In, Ellipsis, OrigNumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003344
Chris Lattner686775d2011-07-20 06:58:45 +00003345 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003346 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3347 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003348
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003349 // Determine whether the set of unexpanded parameter packs can and should
3350 // be expanded.
3351 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003352 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003353 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003354 if (getDerived().TryExpandParameterPacks(Ellipsis,
3355 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003356 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003357 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003358 RetainExpansion,
3359 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003360 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003361
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003362 if (!Expand) {
3363 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003364 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003365 // expansion.
3366 TemplateArgumentLoc OutPattern;
3367 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3368 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3369 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003370
Douglas Gregorcded4f62011-01-14 17:04:44 +00003371 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3372 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003373 if (Out.getArgument().isNull())
3374 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003375
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003376 Outputs.addArgument(Out);
3377 continue;
3378 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003379
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003380 // The transform has determined that we should perform an elementwise
3381 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003382 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003383 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3384
3385 if (getDerived().TransformTemplateArgument(Pattern, Out))
3386 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003387
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003388 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003389 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3390 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003391 if (Out.getArgument().isNull())
3392 return true;
3393 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003394
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003395 Outputs.addArgument(Out);
3396 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003397
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003398 // If we're supposed to retain a pack expansion, do so by temporarily
3399 // forgetting the partially-substituted parameter pack.
3400 if (RetainExpansion) {
3401 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003402
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003403 if (getDerived().TransformTemplateArgument(Pattern, Out))
3404 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003405
Douglas Gregorcded4f62011-01-14 17:04:44 +00003406 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3407 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003408 if (Out.getArgument().isNull())
3409 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003410
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003411 Outputs.addArgument(Out);
3412 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003413
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003414 continue;
3415 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003416
3417 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003418 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003419 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003420
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003421 Outputs.addArgument(Out);
3422 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003423
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003424 return false;
3425
3426}
3427
Douglas Gregor577f75a2009-08-04 16:50:30 +00003428//===----------------------------------------------------------------------===//
3429// Type transformation
3430//===----------------------------------------------------------------------===//
3431
3432template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003433QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003434 if (getDerived().AlreadyTransformed(T))
3435 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003436
John McCalla2becad2009-10-21 00:40:46 +00003437 // Temporary workaround. All of these transformations should
3438 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003439 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3440 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003441
John McCall43fed0d2010-11-12 08:19:04 +00003442 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003443
John McCalla2becad2009-10-21 00:40:46 +00003444 if (!NewDI)
3445 return QualType();
3446
3447 return NewDI->getType();
3448}
3449
3450template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003451TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003452 // Refine the base location to the type's location.
3453 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3454 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003455 if (getDerived().AlreadyTransformed(DI->getType()))
3456 return DI;
3457
3458 TypeLocBuilder TLB;
3459
3460 TypeLoc TL = DI->getTypeLoc();
3461 TLB.reserve(TL.getFullDataSize());
3462
John McCall43fed0d2010-11-12 08:19:04 +00003463 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003464 if (Result.isNull())
3465 return 0;
3466
John McCalla93c9342009-12-07 02:54:59 +00003467 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003468}
3469
3470template<typename Derived>
3471QualType
John McCall43fed0d2010-11-12 08:19:04 +00003472TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003473 switch (T.getTypeLocClass()) {
3474#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003475#define TYPELOC(CLASS, PARENT) \
3476 case TypeLoc::CLASS: \
3477 return getDerived().Transform##CLASS##Type(TLB, \
3478 T.castAs<CLASS##TypeLoc>());
John McCalla2becad2009-10-21 00:40:46 +00003479#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003480 }
Mike Stump1eb44332009-09-09 15:08:12 +00003481
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003482 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003483}
3484
3485/// FIXME: By default, this routine adds type qualifiers only to types
3486/// that can have qualifiers, and silently suppresses those qualifiers
3487/// that are not permitted (e.g., qualifiers on reference or function
3488/// types). This is the right thing for template instantiation, but
3489/// probably not for other clients.
3490template<typename Derived>
3491QualType
3492TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003493 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003494 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003495
John McCall43fed0d2010-11-12 08:19:04 +00003496 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003497 if (Result.isNull())
3498 return QualType();
3499
3500 // Silently suppress qualifiers if the result type can't be qualified.
3501 // FIXME: this is the right thing for template instantiation, but
3502 // probably not for other clients.
3503 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003504 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003505
John McCallf85e1932011-06-15 23:02:42 +00003506 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003507 // resulting type.
3508 if (Quals.hasObjCLifetime()) {
3509 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3510 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003511 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003512 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003513 // A lifetime qualifier applied to a substituted template parameter
3514 // overrides the lifetime qualifier from the template argument.
Douglas Gregor92d13872013-01-17 23:59:28 +00003515 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003516 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003517 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3518 QualType Replacement = SubstTypeParam->getReplacementType();
3519 Qualifiers Qs = Replacement.getQualifiers();
3520 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003521 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003522 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3523 Qs);
3524 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003525 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003526 Replacement);
3527 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003528 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3529 // 'auto' types behave the same way as template parameters.
3530 QualType Deduced = AutoTy->getDeducedType();
3531 Qualifiers Qs = Deduced.getQualifiers();
3532 Qs.removeObjCLifetime();
3533 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3534 Qs);
Faisal Valifad9e132013-09-26 19:54:12 +00003535 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3536 AutoTy->isDependentType());
Douglas Gregor92d13872013-01-17 23:59:28 +00003537 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003538 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003539 // Otherwise, complain about the addition of a qualifier to an
3540 // already-qualified type.
Eli Friedman44ee0a72013-06-07 20:31:48 +00003541 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003542 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003543 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003544
Douglas Gregore559ca12011-06-17 22:11:49 +00003545 Quals.removeObjCLifetime();
3546 }
3547 }
3548 }
John McCall28654742010-06-05 06:41:15 +00003549 if (!Quals.empty()) {
3550 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smith9807a2e2013-03-27 23:36:39 +00003551 // BuildQualifiedType might not add qualifiers if they are invalid.
3552 if (Result.hasLocalQualifiers())
3553 TLB.push<QualifiedTypeLoc>(Result);
John McCall28654742010-06-05 06:41:15 +00003554 // No location information to preserve.
3555 }
John McCalla2becad2009-10-21 00:40:46 +00003556
3557 return Result;
3558}
3559
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003560template<typename Derived>
3561TypeLoc
3562TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3563 QualType ObjectType,
3564 NamedDecl *UnqualLookup,
3565 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003566 QualType T = TL.getType();
3567 if (getDerived().AlreadyTransformed(T))
3568 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003569
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003570 TypeLocBuilder TLB;
3571 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003572
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003573 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003574 TemplateSpecializationTypeLoc SpecTL =
3575 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003576
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003577 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003578 getDerived().TransformTemplateName(SS,
3579 SpecTL.getTypePtr()->getTemplateName(),
3580 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003581 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003582 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003583 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003584
3585 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003586 Template);
3587 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003588 DependentTemplateSpecializationTypeLoc SpecTL =
3589 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003590
Douglas Gregora88f09f2011-02-28 17:23:35 +00003591 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003592 = getDerived().RebuildTemplateName(SS,
3593 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003594 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003595 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003596 if (Template.isNull())
3597 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003598
3599 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003600 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003601 Template,
3602 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003603 } else {
3604 // Nothing special needs to be done for these.
3605 Result = getDerived().TransformType(TLB, TL);
3606 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003607
3608 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003609 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003610
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003611 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3612}
3613
Douglas Gregorb71d8212011-03-02 18:32:08 +00003614template<typename Derived>
3615TypeSourceInfo *
3616TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3617 QualType ObjectType,
3618 NamedDecl *UnqualLookup,
3619 CXXScopeSpec &SS) {
3620 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003621
Douglas Gregorb71d8212011-03-02 18:32:08 +00003622 QualType T = TSInfo->getType();
3623 if (getDerived().AlreadyTransformed(T))
3624 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003625
Douglas Gregorb71d8212011-03-02 18:32:08 +00003626 TypeLocBuilder TLB;
3627 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003628
Douglas Gregorb71d8212011-03-02 18:32:08 +00003629 TypeLoc TL = TSInfo->getTypeLoc();
3630 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003631 TemplateSpecializationTypeLoc SpecTL =
3632 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003633
Douglas Gregorb71d8212011-03-02 18:32:08 +00003634 TemplateName Template
3635 = getDerived().TransformTemplateName(SS,
3636 SpecTL.getTypePtr()->getTemplateName(),
3637 SpecTL.getTemplateNameLoc(),
3638 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003639 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003640 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003641
3642 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003643 Template);
3644 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003645 DependentTemplateSpecializationTypeLoc SpecTL =
3646 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003647
Douglas Gregorb71d8212011-03-02 18:32:08 +00003648 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003649 = getDerived().RebuildTemplateName(SS,
3650 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003651 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003652 ObjectType, UnqualLookup);
3653 if (Template.isNull())
3654 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003655
3656 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003657 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003658 Template,
3659 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003660 } else {
3661 // Nothing special needs to be done for these.
3662 Result = getDerived().TransformType(TLB, TL);
3663 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003664
3665 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003666 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003667
Douglas Gregorb71d8212011-03-02 18:32:08 +00003668 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3669}
3670
John McCalla2becad2009-10-21 00:40:46 +00003671template <class TyLoc> static inline
3672QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3673 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3674 NewT.setNameLoc(T.getNameLoc());
3675 return T.getType();
3676}
3677
John McCalla2becad2009-10-21 00:40:46 +00003678template<typename Derived>
3679QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003680 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003681 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3682 NewT.setBuiltinLoc(T.getBuiltinLoc());
3683 if (T.needsExtraLocalData())
3684 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3685 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003686}
Mike Stump1eb44332009-09-09 15:08:12 +00003687
Douglas Gregor577f75a2009-08-04 16:50:30 +00003688template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003689QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003690 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003691 // FIXME: recurse?
3692 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003693}
Mike Stump1eb44332009-09-09 15:08:12 +00003694
Douglas Gregor577f75a2009-08-04 16:50:30 +00003695template<typename Derived>
Reid Kleckner12df2462013-06-24 17:51:48 +00003696QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3697 DecayedTypeLoc TL) {
3698 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3699 if (OriginalType.isNull())
3700 return QualType();
3701
3702 QualType Result = TL.getType();
3703 if (getDerived().AlwaysRebuild() ||
3704 OriginalType != TL.getOriginalLoc().getType())
3705 Result = SemaRef.Context.getDecayedType(OriginalType);
3706 TLB.push<DecayedTypeLoc>(Result);
3707 // Nothing to set for DecayedTypeLoc.
3708 return Result;
3709}
3710
3711template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003712QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003713 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003714 QualType PointeeType
3715 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003716 if (PointeeType.isNull())
3717 return QualType();
3718
3719 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003720 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003721 // A dependent pointer type 'T *' has is being transformed such
3722 // that an Objective-C class type is being replaced for 'T'. The
3723 // resulting pointer type is an ObjCObjectPointerType, not a
3724 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003725 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003726
John McCallc12c5bb2010-05-15 11:32:37 +00003727 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3728 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003729 return Result;
3730 }
John McCall43fed0d2010-11-12 08:19:04 +00003731
Douglas Gregor92e986e2010-04-22 16:44:27 +00003732 if (getDerived().AlwaysRebuild() ||
3733 PointeeType != TL.getPointeeLoc().getType()) {
3734 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3735 if (Result.isNull())
3736 return QualType();
3737 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003738
John McCallf85e1932011-06-15 23:02:42 +00003739 // Objective-C ARC can add lifetime qualifiers to the type that we're
3740 // pointing to.
3741 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003742
Douglas Gregor92e986e2010-04-22 16:44:27 +00003743 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3744 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003745 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003746}
Mike Stump1eb44332009-09-09 15:08:12 +00003747
3748template<typename Derived>
3749QualType
John McCalla2becad2009-10-21 00:40:46 +00003750TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003751 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003752 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003753 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3754 if (PointeeType.isNull())
3755 return QualType();
3756
3757 QualType Result = TL.getType();
3758 if (getDerived().AlwaysRebuild() ||
3759 PointeeType != TL.getPointeeLoc().getType()) {
3760 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003761 TL.getSigilLoc());
3762 if (Result.isNull())
3763 return QualType();
3764 }
3765
Douglas Gregor39968ad2010-04-22 16:50:51 +00003766 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003767 NewT.setSigilLoc(TL.getSigilLoc());
3768 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003769}
3770
John McCall85737a72009-10-30 00:06:24 +00003771/// Transforms a reference type. Note that somewhat paradoxically we
3772/// don't care whether the type itself is an l-value type or an r-value
3773/// type; we only care if the type was *written* as an l-value type
3774/// or an r-value type.
3775template<typename Derived>
3776QualType
3777TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003778 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003779 const ReferenceType *T = TL.getTypePtr();
3780
3781 // Note that this works with the pointee-as-written.
3782 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3783 if (PointeeType.isNull())
3784 return QualType();
3785
3786 QualType Result = TL.getType();
3787 if (getDerived().AlwaysRebuild() ||
3788 PointeeType != T->getPointeeTypeAsWritten()) {
3789 Result = getDerived().RebuildReferenceType(PointeeType,
3790 T->isSpelledAsLValue(),
3791 TL.getSigilLoc());
3792 if (Result.isNull())
3793 return QualType();
3794 }
3795
John McCallf85e1932011-06-15 23:02:42 +00003796 // Objective-C ARC can add lifetime qualifiers to the type that we're
3797 // referring to.
3798 TLB.TypeWasModifiedSafely(
3799 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3800
John McCall85737a72009-10-30 00:06:24 +00003801 // r-value references can be rebuilt as l-value references.
3802 ReferenceTypeLoc NewTL;
3803 if (isa<LValueReferenceType>(Result))
3804 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3805 else
3806 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3807 NewTL.setSigilLoc(TL.getSigilLoc());
3808
3809 return Result;
3810}
3811
Mike Stump1eb44332009-09-09 15:08:12 +00003812template<typename Derived>
3813QualType
John McCalla2becad2009-10-21 00:40:46 +00003814TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003815 LValueReferenceTypeLoc TL) {
3816 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003817}
3818
Mike Stump1eb44332009-09-09 15:08:12 +00003819template<typename Derived>
3820QualType
John McCalla2becad2009-10-21 00:40:46 +00003821TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003822 RValueReferenceTypeLoc TL) {
3823 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003824}
Mike Stump1eb44332009-09-09 15:08:12 +00003825
Douglas Gregor577f75a2009-08-04 16:50:30 +00003826template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003827QualType
John McCalla2becad2009-10-21 00:40:46 +00003828TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003829 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003830 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003831 if (PointeeType.isNull())
3832 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003833
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003834 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3835 TypeSourceInfo* NewClsTInfo = 0;
3836 if (OldClsTInfo) {
3837 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3838 if (!NewClsTInfo)
3839 return QualType();
3840 }
3841
3842 const MemberPointerType *T = TL.getTypePtr();
3843 QualType OldClsType = QualType(T->getClass(), 0);
3844 QualType NewClsType;
3845 if (NewClsTInfo)
3846 NewClsType = NewClsTInfo->getType();
3847 else {
3848 NewClsType = getDerived().TransformType(OldClsType);
3849 if (NewClsType.isNull())
3850 return QualType();
3851 }
Mike Stump1eb44332009-09-09 15:08:12 +00003852
John McCalla2becad2009-10-21 00:40:46 +00003853 QualType Result = TL.getType();
3854 if (getDerived().AlwaysRebuild() ||
3855 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003856 NewClsType != OldClsType) {
3857 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003858 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003859 if (Result.isNull())
3860 return QualType();
3861 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003862
John McCalla2becad2009-10-21 00:40:46 +00003863 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3864 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003865 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003866
3867 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003868}
3869
Mike Stump1eb44332009-09-09 15:08:12 +00003870template<typename Derived>
3871QualType
John McCalla2becad2009-10-21 00:40:46 +00003872TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003873 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003874 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003875 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003876 if (ElementType.isNull())
3877 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003878
John McCalla2becad2009-10-21 00:40:46 +00003879 QualType Result = TL.getType();
3880 if (getDerived().AlwaysRebuild() ||
3881 ElementType != T->getElementType()) {
3882 Result = getDerived().RebuildConstantArrayType(ElementType,
3883 T->getSizeModifier(),
3884 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003885 T->getIndexTypeCVRQualifiers(),
3886 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003887 if (Result.isNull())
3888 return QualType();
3889 }
Eli Friedman457a3772012-01-25 22:19:07 +00003890
3891 // We might have either a ConstantArrayType or a VariableArrayType now:
3892 // a ConstantArrayType is allowed to have an element type which is a
3893 // VariableArrayType if the type is dependent. Fortunately, all array
3894 // types have the same location layout.
3895 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003896 NewTL.setLBracketLoc(TL.getLBracketLoc());
3897 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003898
John McCalla2becad2009-10-21 00:40:46 +00003899 Expr *Size = TL.getSizeExpr();
3900 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003901 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3902 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003903 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003904 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003905 }
3906 NewTL.setSizeExpr(Size);
3907
3908 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003909}
Mike Stump1eb44332009-09-09 15:08:12 +00003910
Douglas Gregor577f75a2009-08-04 16:50:30 +00003911template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003912QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003913 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003914 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003915 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003916 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003917 if (ElementType.isNull())
3918 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003919
John McCalla2becad2009-10-21 00:40:46 +00003920 QualType Result = TL.getType();
3921 if (getDerived().AlwaysRebuild() ||
3922 ElementType != T->getElementType()) {
3923 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003924 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003925 T->getIndexTypeCVRQualifiers(),
3926 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003927 if (Result.isNull())
3928 return QualType();
3929 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003930
John McCalla2becad2009-10-21 00:40:46 +00003931 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3932 NewTL.setLBracketLoc(TL.getLBracketLoc());
3933 NewTL.setRBracketLoc(TL.getRBracketLoc());
3934 NewTL.setSizeExpr(0);
3935
3936 return Result;
3937}
3938
3939template<typename Derived>
3940QualType
3941TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003942 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003943 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003944 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3945 if (ElementType.isNull())
3946 return QualType();
3947
John McCall60d7b3a2010-08-24 06:29:42 +00003948 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003949 = getDerived().TransformExpr(T->getSizeExpr());
3950 if (SizeResult.isInvalid())
3951 return QualType();
3952
John McCall9ae2f072010-08-23 23:25:46 +00003953 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003954
3955 QualType Result = TL.getType();
3956 if (getDerived().AlwaysRebuild() ||
3957 ElementType != T->getElementType() ||
3958 Size != T->getSizeExpr()) {
3959 Result = getDerived().RebuildVariableArrayType(ElementType,
3960 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003961 Size,
John McCalla2becad2009-10-21 00:40:46 +00003962 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003963 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003964 if (Result.isNull())
3965 return QualType();
3966 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003967
John McCalla2becad2009-10-21 00:40:46 +00003968 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3969 NewTL.setLBracketLoc(TL.getLBracketLoc());
3970 NewTL.setRBracketLoc(TL.getRBracketLoc());
3971 NewTL.setSizeExpr(Size);
3972
3973 return Result;
3974}
3975
3976template<typename Derived>
3977QualType
3978TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003979 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003980 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003981 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3982 if (ElementType.isNull())
3983 return QualType();
3984
Richard Smithf6702a32011-12-20 02:08:33 +00003985 // Array bounds are constant expressions.
3986 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3987 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003988
John McCall3b657512011-01-19 10:06:00 +00003989 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3990 Expr *origSize = TL.getSizeExpr();
3991 if (!origSize) origSize = T->getSizeExpr();
3992
3993 ExprResult sizeResult
3994 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003995 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003996 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003997 return QualType();
3998
John McCall3b657512011-01-19 10:06:00 +00003999 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00004000
4001 QualType Result = TL.getType();
4002 if (getDerived().AlwaysRebuild() ||
4003 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00004004 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00004005 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4006 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00004007 size,
John McCalla2becad2009-10-21 00:40:46 +00004008 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00004009 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00004010 if (Result.isNull())
4011 return QualType();
4012 }
John McCalla2becad2009-10-21 00:40:46 +00004013
4014 // We might have any sort of array type now, but fortunately they
4015 // all have the same location layout.
4016 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4017 NewTL.setLBracketLoc(TL.getLBracketLoc());
4018 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00004019 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00004020
4021 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004022}
Mike Stump1eb44332009-09-09 15:08:12 +00004023
4024template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00004025QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00004026 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004027 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004028 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004029
4030 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00004031 QualType ElementType = getDerived().TransformType(T->getElementType());
4032 if (ElementType.isNull())
4033 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004034
Richard Smithf6702a32011-12-20 02:08:33 +00004035 // Vector sizes are constant expressions.
4036 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4037 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00004038
John McCall60d7b3a2010-08-24 06:29:42 +00004039 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00004040 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004041 if (Size.isInvalid())
4042 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004043
John McCalla2becad2009-10-21 00:40:46 +00004044 QualType Result = TL.getType();
4045 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00004046 ElementType != T->getElementType() ||
4047 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00004048 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00004049 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00004050 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00004051 if (Result.isNull())
4052 return QualType();
4053 }
John McCalla2becad2009-10-21 00:40:46 +00004054
4055 // Result might be dependent or not.
4056 if (isa<DependentSizedExtVectorType>(Result)) {
4057 DependentSizedExtVectorTypeLoc NewTL
4058 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4059 NewTL.setNameLoc(TL.getNameLoc());
4060 } else {
4061 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4062 NewTL.setNameLoc(TL.getNameLoc());
4063 }
4064
4065 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004066}
Mike Stump1eb44332009-09-09 15:08:12 +00004067
4068template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004069QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004070 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004071 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004072 QualType ElementType = getDerived().TransformType(T->getElementType());
4073 if (ElementType.isNull())
4074 return QualType();
4075
John McCalla2becad2009-10-21 00:40:46 +00004076 QualType Result = TL.getType();
4077 if (getDerived().AlwaysRebuild() ||
4078 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00004079 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00004080 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00004081 if (Result.isNull())
4082 return QualType();
4083 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004084
John McCalla2becad2009-10-21 00:40:46 +00004085 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4086 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00004087
John McCalla2becad2009-10-21 00:40:46 +00004088 return Result;
4089}
4090
4091template<typename Derived>
4092QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004093 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004094 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004095 QualType ElementType = getDerived().TransformType(T->getElementType());
4096 if (ElementType.isNull())
4097 return QualType();
4098
4099 QualType Result = TL.getType();
4100 if (getDerived().AlwaysRebuild() ||
4101 ElementType != T->getElementType()) {
4102 Result = getDerived().RebuildExtVectorType(ElementType,
4103 T->getNumElements(),
4104 /*FIXME*/ SourceLocation());
4105 if (Result.isNull())
4106 return QualType();
4107 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004108
John McCalla2becad2009-10-21 00:40:46 +00004109 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4110 NewTL.setNameLoc(TL.getNameLoc());
4111
4112 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004113}
Mike Stump1eb44332009-09-09 15:08:12 +00004114
David Blaikiedc84cd52013-02-20 22:23:23 +00004115template <typename Derived>
4116ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4117 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4118 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00004119 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004120 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004121
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004122 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004123 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004124 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004125 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004126 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004127
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004128 TypeLocBuilder TLB;
4129 TypeLoc NewTL = OldDI->getTypeLoc();
4130 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004131
4132 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004133 OldExpansionTL.getPatternLoc());
4134 if (Result.isNull())
4135 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004136
4137 Result = RebuildPackExpansionType(Result,
4138 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004139 OldExpansionTL.getEllipsisLoc(),
4140 NumExpansions);
4141 if (Result.isNull())
4142 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004143
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004144 PackExpansionTypeLoc NewExpansionTL
4145 = TLB.push<PackExpansionTypeLoc>(Result);
4146 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4147 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4148 } else
4149 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00004150 if (!NewDI)
4151 return 0;
4152
John McCallfb44de92011-05-01 22:35:37 +00004153 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00004154 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00004155
4156 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4157 OldParm->getDeclContext(),
4158 OldParm->getInnerLocStart(),
4159 OldParm->getLocation(),
4160 OldParm->getIdentifier(),
4161 NewDI->getType(),
4162 NewDI,
4163 OldParm->getStorageClass(),
John McCallfb44de92011-05-01 22:35:37 +00004164 /* DefArg */ NULL);
4165 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4166 OldParm->getFunctionScopeIndex() + indexAdjustment);
4167 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004168}
4169
4170template<typename Derived>
4171bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004172 TransformFunctionTypeParams(SourceLocation Loc,
4173 ParmVarDecl **Params, unsigned NumParams,
4174 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004175 SmallVectorImpl<QualType> &OutParamTypes,
4176 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004177 int indexAdjustment = 0;
4178
Douglas Gregora009b592011-01-07 00:20:55 +00004179 for (unsigned i = 0; i != NumParams; ++i) {
4180 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004181 assert(OldParm->getFunctionScopeIndex() == i);
4182
David Blaikiedc84cd52013-02-20 22:23:23 +00004183 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004184 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004185 if (OldParm->isParameterPack()) {
4186 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004187 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004188
Douglas Gregor603cfb42011-01-05 23:12:31 +00004189 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004190 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004191 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004192 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4193 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004194 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4195
Douglas Gregor603cfb42011-01-05 23:12:31 +00004196 // Determine whether we should expand the parameter packs.
4197 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004198 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004199 Optional<unsigned> OrigNumExpansions =
4200 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004201 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004202 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4203 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004204 Unexpanded,
4205 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004206 RetainExpansion,
4207 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004208 return true;
4209 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004210
Douglas Gregor603cfb42011-01-05 23:12:31 +00004211 if (ShouldExpand) {
4212 // Expand the function parameter pack into multiple, separate
4213 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004214 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004215 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004216 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004217 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004218 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004219 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004220 OrigNumExpansions,
4221 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004222 if (!NewParm)
4223 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004224
Douglas Gregora009b592011-01-07 00:20:55 +00004225 OutParamTypes.push_back(NewParm->getType());
4226 if (PVars)
4227 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004228 }
Douglas Gregord3731192011-01-10 07:32:04 +00004229
4230 // If we're supposed to retain a pack expansion, do so by temporarily
4231 // forgetting the partially-substituted parameter pack.
4232 if (RetainExpansion) {
4233 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004234 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004235 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004236 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004237 OrigNumExpansions,
4238 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004239 if (!NewParm)
4240 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004241
Douglas Gregord3731192011-01-10 07:32:04 +00004242 OutParamTypes.push_back(NewParm->getType());
4243 if (PVars)
4244 PVars->push_back(NewParm);
4245 }
4246
John McCallfb44de92011-05-01 22:35:37 +00004247 // The next parameter should have the same adjustment as the
4248 // last thing we pushed, but we post-incremented indexAdjustment
4249 // on every push. Also, if we push nothing, the adjustment should
4250 // go down by one.
4251 indexAdjustment--;
4252
Douglas Gregor603cfb42011-01-05 23:12:31 +00004253 // We're done with the pack expansion.
4254 continue;
4255 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004256
4257 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004258 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004259 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4260 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004261 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004262 NumExpansions,
4263 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004264 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004265 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004266 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004267 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004268
John McCall21ef0fa2010-03-11 09:03:00 +00004269 if (!NewParm)
4270 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004271
Douglas Gregora009b592011-01-07 00:20:55 +00004272 OutParamTypes.push_back(NewParm->getType());
4273 if (PVars)
4274 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004275 continue;
4276 }
John McCall21ef0fa2010-03-11 09:03:00 +00004277
4278 // Deal with the possibility that we don't have a parameter
4279 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004280 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004281 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004282 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004283 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004284 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004285 = dyn_cast<PackExpansionType>(OldType)) {
4286 // We have a function parameter pack that may need to be expanded.
4287 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004288 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004289 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004290
Douglas Gregor603cfb42011-01-05 23:12:31 +00004291 // Determine whether we should expand the parameter packs.
4292 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004293 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004294 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004295 Unexpanded,
4296 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004297 RetainExpansion,
4298 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004299 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004300 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004301
Douglas Gregor603cfb42011-01-05 23:12:31 +00004302 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004303 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004304 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004305 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004306 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4307 QualType NewType = getDerived().TransformType(Pattern);
4308 if (NewType.isNull())
4309 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004310
Douglas Gregora009b592011-01-07 00:20:55 +00004311 OutParamTypes.push_back(NewType);
4312 if (PVars)
4313 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004314 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004315
Douglas Gregor603cfb42011-01-05 23:12:31 +00004316 // We're done with the pack expansion.
4317 continue;
4318 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004319
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004320 // If we're supposed to retain a pack expansion, do so by temporarily
4321 // forgetting the partially-substituted parameter pack.
4322 if (RetainExpansion) {
4323 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4324 QualType NewType = getDerived().TransformType(Pattern);
4325 if (NewType.isNull())
4326 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004327
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004328 OutParamTypes.push_back(NewType);
4329 if (PVars)
4330 PVars->push_back(0);
4331 }
Douglas Gregord3731192011-01-10 07:32:04 +00004332
Chad Rosier4a9d7952012-08-08 18:46:20 +00004333 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004334 // expansion.
4335 OldType = Expansion->getPattern();
4336 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004337 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4338 NewType = getDerived().TransformType(OldType);
4339 } else {
4340 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004341 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004342
Douglas Gregor603cfb42011-01-05 23:12:31 +00004343 if (NewType.isNull())
4344 return true;
4345
4346 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004347 NewType = getSema().Context.getPackExpansionType(NewType,
4348 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004349
Douglas Gregora009b592011-01-07 00:20:55 +00004350 OutParamTypes.push_back(NewType);
4351 if (PVars)
4352 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004353 }
4354
John McCallfb44de92011-05-01 22:35:37 +00004355#ifndef NDEBUG
4356 if (PVars) {
4357 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4358 if (ParmVarDecl *parm = (*PVars)[i])
4359 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004360 }
John McCallfb44de92011-05-01 22:35:37 +00004361#endif
4362
4363 return false;
4364}
John McCall21ef0fa2010-03-11 09:03:00 +00004365
4366template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004367QualType
John McCalla2becad2009-10-21 00:40:46 +00004368TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004369 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004370 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4371}
4372
4373template<typename Derived>
4374QualType
4375TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4376 FunctionProtoTypeLoc TL,
4377 CXXRecordDecl *ThisContext,
4378 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004379 // Transform the parameters and return type.
4380 //
Richard Smithe6975e92012-04-17 00:58:00 +00004381 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004382 // When the function has a trailing return type, we instantiate the
4383 // parameters before the return type, since the return type can then refer
4384 // to the parameters themselves (via decltype, sizeof, etc.).
4385 //
Chris Lattner686775d2011-07-20 06:58:45 +00004386 SmallVector<QualType, 4> ParamTypes;
4387 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004388 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004389
Douglas Gregordab60ad2010-10-01 18:44:50 +00004390 QualType ResultType;
4391
Richard Smith9fbf3272012-08-14 22:51:13 +00004392 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004393 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004394 TL.getParmArray(),
4395 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004396 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004397 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004398 return QualType();
4399
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004400 {
4401 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004402 // If a declaration declares a member function or member function
4403 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004404 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004405 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004406 // declarator.
4407 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004408
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004409 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4410 if (ResultType.isNull())
4411 return QualType();
4412 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004413 }
4414 else {
4415 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4416 if (ResultType.isNull())
4417 return QualType();
4418
Chad Rosier4a9d7952012-08-08 18:46:20 +00004419 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004420 TL.getParmArray(),
4421 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004422 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004423 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004424 return QualType();
4425 }
4426
Richard Smithe6975e92012-04-17 00:58:00 +00004427 // FIXME: Need to transform the exception-specification too.
4428
John McCalla2becad2009-10-21 00:40:46 +00004429 QualType Result = TL.getType();
4430 if (getDerived().AlwaysRebuild() ||
4431 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004432 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004433 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004434 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004435 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004436 if (Result.isNull())
4437 return QualType();
4438 }
Mike Stump1eb44332009-09-09 15:08:12 +00004439
John McCalla2becad2009-10-21 00:40:46 +00004440 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004441 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004442 NewTL.setLParenLoc(TL.getLParenLoc());
4443 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004444 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004445 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4446 NewTL.setArg(i, ParamDecls[i]);
4447
4448 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004449}
Mike Stump1eb44332009-09-09 15:08:12 +00004450
Douglas Gregor577f75a2009-08-04 16:50:30 +00004451template<typename Derived>
4452QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004453 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004454 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004455 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004456 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4457 if (ResultType.isNull())
4458 return QualType();
4459
4460 QualType Result = TL.getType();
4461 if (getDerived().AlwaysRebuild() ||
4462 ResultType != T->getResultType())
4463 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4464
4465 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004466 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004467 NewTL.setLParenLoc(TL.getLParenLoc());
4468 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004469 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004470
4471 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004472}
Mike Stump1eb44332009-09-09 15:08:12 +00004473
John McCalled976492009-12-04 22:46:56 +00004474template<typename Derived> QualType
4475TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004476 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004477 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004478 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004479 if (!D)
4480 return QualType();
4481
4482 QualType Result = TL.getType();
4483 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4484 Result = getDerived().RebuildUnresolvedUsingType(D);
4485 if (Result.isNull())
4486 return QualType();
4487 }
4488
4489 // We might get an arbitrary type spec type back. We should at
4490 // least always get a type spec type, though.
4491 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4492 NewTL.setNameLoc(TL.getNameLoc());
4493
4494 return Result;
4495}
4496
Douglas Gregor577f75a2009-08-04 16:50:30 +00004497template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004498QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004499 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004500 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004501 TypedefNameDecl *Typedef
4502 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4503 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004504 if (!Typedef)
4505 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004506
John McCalla2becad2009-10-21 00:40:46 +00004507 QualType Result = TL.getType();
4508 if (getDerived().AlwaysRebuild() ||
4509 Typedef != T->getDecl()) {
4510 Result = getDerived().RebuildTypedefType(Typedef);
4511 if (Result.isNull())
4512 return QualType();
4513 }
Mike Stump1eb44332009-09-09 15:08:12 +00004514
John McCalla2becad2009-10-21 00:40:46 +00004515 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4516 NewTL.setNameLoc(TL.getNameLoc());
4517
4518 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004519}
Mike Stump1eb44332009-09-09 15:08:12 +00004520
Douglas Gregor577f75a2009-08-04 16:50:30 +00004521template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004522QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004523 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004524 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004525 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4526 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004527
John McCall60d7b3a2010-08-24 06:29:42 +00004528 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004529 if (E.isInvalid())
4530 return QualType();
4531
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004532 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4533 if (E.isInvalid())
4534 return QualType();
4535
John McCalla2becad2009-10-21 00:40:46 +00004536 QualType Result = TL.getType();
4537 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004538 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004539 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004540 if (Result.isNull())
4541 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004542 }
John McCalla2becad2009-10-21 00:40:46 +00004543 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004544
John McCalla2becad2009-10-21 00:40:46 +00004545 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004546 NewTL.setTypeofLoc(TL.getTypeofLoc());
4547 NewTL.setLParenLoc(TL.getLParenLoc());
4548 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004549
4550 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004551}
Mike Stump1eb44332009-09-09 15:08:12 +00004552
4553template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004554QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004555 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004556 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4557 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4558 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004559 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004560
John McCalla2becad2009-10-21 00:40:46 +00004561 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004562 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4563 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004564 if (Result.isNull())
4565 return QualType();
4566 }
Mike Stump1eb44332009-09-09 15:08:12 +00004567
John McCalla2becad2009-10-21 00:40:46 +00004568 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004569 NewTL.setTypeofLoc(TL.getTypeofLoc());
4570 NewTL.setLParenLoc(TL.getLParenLoc());
4571 NewTL.setRParenLoc(TL.getRParenLoc());
4572 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004573
4574 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004575}
Mike Stump1eb44332009-09-09 15:08:12 +00004576
4577template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004578QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004579 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004580 const DecltypeType *T = TL.getTypePtr();
Faisal Valiaecbb9d2013-10-03 05:32:48 +00004581 // Don't transform a decltype construct that has already been transformed
4582 // into a non-dependent type.
4583 // Allows the following to compile:
4584 // auto L = [](auto a) {
4585 // return [](auto b) ->decltype(a) {
4586 // return b;
4587 // };
4588 //};
4589 if (!T->isInstantiationDependentType()) {
4590 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(TL.getType());
4591 NewTL.setNameLoc(TL.getNameLoc());
4592 return NewTL.getType();
4593 }
John McCalla2becad2009-10-21 00:40:46 +00004594
Douglas Gregor670444e2009-08-04 22:27:00 +00004595 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004596 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4597 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004598
John McCall60d7b3a2010-08-24 06:29:42 +00004599 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004600 if (E.isInvalid())
4601 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004602
Richard Smith76f3f692012-02-22 02:04:18 +00004603 E = getSema().ActOnDecltypeExpression(E.take());
4604 if (E.isInvalid())
4605 return QualType();
4606
John McCalla2becad2009-10-21 00:40:46 +00004607 QualType Result = TL.getType();
4608 if (getDerived().AlwaysRebuild() ||
4609 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004610 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004611 if (Result.isNull())
4612 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004613 }
John McCalla2becad2009-10-21 00:40:46 +00004614 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004615
John McCalla2becad2009-10-21 00:40:46 +00004616 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4617 NewTL.setNameLoc(TL.getNameLoc());
4618
4619 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004620}
4621
4622template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004623QualType TreeTransform<Derived>::TransformUnaryTransformType(
4624 TypeLocBuilder &TLB,
4625 UnaryTransformTypeLoc TL) {
4626 QualType Result = TL.getType();
4627 if (Result->isDependentType()) {
4628 const UnaryTransformType *T = TL.getTypePtr();
4629 QualType NewBase =
4630 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4631 Result = getDerived().RebuildUnaryTransformType(NewBase,
4632 T->getUTTKind(),
4633 TL.getKWLoc());
4634 if (Result.isNull())
4635 return QualType();
4636 }
4637
4638 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4639 NewTL.setKWLoc(TL.getKWLoc());
4640 NewTL.setParensRange(TL.getParensRange());
4641 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4642 return Result;
4643}
4644
4645template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004646QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4647 AutoTypeLoc TL) {
4648 const AutoType *T = TL.getTypePtr();
4649 QualType OldDeduced = T->getDeducedType();
4650 QualType NewDeduced;
4651 if (!OldDeduced.isNull()) {
4652 NewDeduced = getDerived().TransformType(OldDeduced);
4653 if (NewDeduced.isNull())
4654 return QualType();
4655 }
4656
4657 QualType Result = TL.getType();
Richard Smithdc7a4f52013-04-30 13:56:41 +00004658 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4659 T->isDependentType()) {
Richard Smitha2c36462013-04-26 16:15:35 +00004660 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith34b41d92011-02-20 03:19:35 +00004661 if (Result.isNull())
4662 return QualType();
4663 }
4664
4665 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4666 NewTL.setNameLoc(TL.getNameLoc());
4667
4668 return Result;
4669}
4670
4671template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004672QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004673 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004674 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004675 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004676 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4677 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004678 if (!Record)
4679 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004680
John McCalla2becad2009-10-21 00:40:46 +00004681 QualType Result = TL.getType();
4682 if (getDerived().AlwaysRebuild() ||
4683 Record != T->getDecl()) {
4684 Result = getDerived().RebuildRecordType(Record);
4685 if (Result.isNull())
4686 return QualType();
4687 }
Mike Stump1eb44332009-09-09 15:08:12 +00004688
John McCalla2becad2009-10-21 00:40:46 +00004689 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4690 NewTL.setNameLoc(TL.getNameLoc());
4691
4692 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004693}
Mike Stump1eb44332009-09-09 15:08:12 +00004694
4695template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004696QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004697 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004698 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004699 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004700 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4701 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004702 if (!Enum)
4703 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004704
John McCalla2becad2009-10-21 00:40:46 +00004705 QualType Result = TL.getType();
4706 if (getDerived().AlwaysRebuild() ||
4707 Enum != T->getDecl()) {
4708 Result = getDerived().RebuildEnumType(Enum);
4709 if (Result.isNull())
4710 return QualType();
4711 }
Mike Stump1eb44332009-09-09 15:08:12 +00004712
John McCalla2becad2009-10-21 00:40:46 +00004713 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4714 NewTL.setNameLoc(TL.getNameLoc());
4715
4716 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004717}
John McCall7da24312009-09-05 00:15:47 +00004718
John McCall3cb0ebd2010-03-10 03:28:59 +00004719template<typename Derived>
4720QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4721 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004722 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004723 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4724 TL.getTypePtr()->getDecl());
4725 if (!D) return QualType();
4726
4727 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4728 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4729 return T;
4730}
4731
Douglas Gregor577f75a2009-08-04 16:50:30 +00004732template<typename Derived>
4733QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004734 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004735 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004736 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004737}
4738
Mike Stump1eb44332009-09-09 15:08:12 +00004739template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004740QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004741 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004742 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004743 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004744
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004745 // Substitute into the replacement type, which itself might involve something
4746 // that needs to be transformed. This only tends to occur with default
4747 // template arguments of template template parameters.
4748 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4749 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4750 if (Replacement.isNull())
4751 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004752
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004753 // Always canonicalize the replacement type.
4754 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4755 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004756 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004757 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004758
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004759 // Propagate type-source information.
4760 SubstTemplateTypeParmTypeLoc NewTL
4761 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4762 NewTL.setNameLoc(TL.getNameLoc());
4763 return Result;
4764
John McCall49a832b2009-10-18 09:09:24 +00004765}
4766
4767template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004768QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4769 TypeLocBuilder &TLB,
4770 SubstTemplateTypeParmPackTypeLoc TL) {
4771 return TransformTypeSpecType(TLB, TL);
4772}
4773
4774template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004775QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004776 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004777 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004778 const TemplateSpecializationType *T = TL.getTypePtr();
4779
Douglas Gregor1d752d72011-03-02 18:46:51 +00004780 // The nested-name-specifier never matters in a TemplateSpecializationType,
4781 // because we can't have a dependent nested-name-specifier anyway.
4782 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004783 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004784 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4785 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004786 if (Template.isNull())
4787 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004788
John McCall43fed0d2010-11-12 08:19:04 +00004789 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4790}
4791
Eli Friedmanb001de72011-10-06 23:00:33 +00004792template<typename Derived>
4793QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4794 AtomicTypeLoc TL) {
4795 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4796 if (ValueType.isNull())
4797 return QualType();
4798
4799 QualType Result = TL.getType();
4800 if (getDerived().AlwaysRebuild() ||
4801 ValueType != TL.getValueLoc().getType()) {
4802 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4803 if (Result.isNull())
4804 return QualType();
4805 }
4806
4807 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4808 NewTL.setKWLoc(TL.getKWLoc());
4809 NewTL.setLParenLoc(TL.getLParenLoc());
4810 NewTL.setRParenLoc(TL.getRParenLoc());
4811
4812 return Result;
4813}
4814
Chad Rosier4a9d7952012-08-08 18:46:20 +00004815 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004816 /// container that provides a \c getArgLoc() member function.
4817 ///
4818 /// This iterator is intended to be used with the iterator form of
4819 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4820 template<typename ArgLocContainer>
4821 class TemplateArgumentLocContainerIterator {
4822 ArgLocContainer *Container;
4823 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004824
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004825 public:
4826 typedef TemplateArgumentLoc value_type;
4827 typedef TemplateArgumentLoc reference;
4828 typedef int difference_type;
4829 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004830
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004831 class pointer {
4832 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004833
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004834 public:
4835 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004836
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004837 const TemplateArgumentLoc *operator->() const {
4838 return &Arg;
4839 }
4840 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004841
4842
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004843 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004844
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004845 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4846 unsigned Index)
4847 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004848
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004849 TemplateArgumentLocContainerIterator &operator++() {
4850 ++Index;
4851 return *this;
4852 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004853
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004854 TemplateArgumentLocContainerIterator operator++(int) {
4855 TemplateArgumentLocContainerIterator Old(*this);
4856 ++(*this);
4857 return Old;
4858 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004859
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004860 TemplateArgumentLoc operator*() const {
4861 return Container->getArgLoc(Index);
4862 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004863
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004864 pointer operator->() const {
4865 return pointer(Container->getArgLoc(Index));
4866 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004867
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004868 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004869 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004870 return X.Container == Y.Container && X.Index == Y.Index;
4871 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004872
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004873 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004874 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004875 return !(X == Y);
4876 }
4877 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004878
4879
John McCall43fed0d2010-11-12 08:19:04 +00004880template <typename Derived>
4881QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4882 TypeLocBuilder &TLB,
4883 TemplateSpecializationTypeLoc TL,
4884 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004885 TemplateArgumentListInfo NewTemplateArgs;
4886 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4887 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004888 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4889 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004890 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004891 ArgIterator(TL, TL.getNumArgs()),
4892 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004893 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004894
John McCall833ca992009-10-29 08:12:44 +00004895 // FIXME: maybe don't rebuild if all the template arguments are the same.
4896
4897 QualType Result =
4898 getDerived().RebuildTemplateSpecializationType(Template,
4899 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004900 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004901
4902 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004903 // Specializations of template template parameters are represented as
4904 // TemplateSpecializationTypes, and substitution of type alias templates
4905 // within a dependent context can transform them into
4906 // DependentTemplateSpecializationTypes.
4907 if (isa<DependentTemplateSpecializationType>(Result)) {
4908 DependentTemplateSpecializationTypeLoc NewTL
4909 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004910 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004911 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004912 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004913 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004914 NewTL.setLAngleLoc(TL.getLAngleLoc());
4915 NewTL.setRAngleLoc(TL.getRAngleLoc());
4916 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4917 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4918 return Result;
4919 }
4920
John McCall833ca992009-10-29 08:12:44 +00004921 TemplateSpecializationTypeLoc NewTL
4922 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004923 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004924 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4925 NewTL.setLAngleLoc(TL.getLAngleLoc());
4926 NewTL.setRAngleLoc(TL.getRAngleLoc());
4927 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4928 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004929 }
Mike Stump1eb44332009-09-09 15:08:12 +00004930
John McCall833ca992009-10-29 08:12:44 +00004931 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004932}
Mike Stump1eb44332009-09-09 15:08:12 +00004933
Douglas Gregora88f09f2011-02-28 17:23:35 +00004934template <typename Derived>
4935QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4936 TypeLocBuilder &TLB,
4937 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004938 TemplateName Template,
4939 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004940 TemplateArgumentListInfo NewTemplateArgs;
4941 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4942 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4943 typedef TemplateArgumentLocContainerIterator<
4944 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004945 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004946 ArgIterator(TL, TL.getNumArgs()),
4947 NewTemplateArgs))
4948 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004949
Douglas Gregora88f09f2011-02-28 17:23:35 +00004950 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004951
Douglas Gregora88f09f2011-02-28 17:23:35 +00004952 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4953 QualType Result
4954 = getSema().Context.getDependentTemplateSpecializationType(
4955 TL.getTypePtr()->getKeyword(),
4956 DTN->getQualifier(),
4957 DTN->getIdentifier(),
4958 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004959
Douglas Gregora88f09f2011-02-28 17:23:35 +00004960 DependentTemplateSpecializationTypeLoc NewTL
4961 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004962 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004963 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004964 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004965 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004966 NewTL.setLAngleLoc(TL.getLAngleLoc());
4967 NewTL.setRAngleLoc(TL.getRAngleLoc());
4968 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4969 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4970 return Result;
4971 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004972
4973 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004974 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004975 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004976 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004977
Douglas Gregora88f09f2011-02-28 17:23:35 +00004978 if (!Result.isNull()) {
4979 /// FIXME: Wrap this in an elaborated-type-specifier?
4980 TemplateSpecializationTypeLoc NewTL
4981 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004982 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004983 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004984 NewTL.setLAngleLoc(TL.getLAngleLoc());
4985 NewTL.setRAngleLoc(TL.getRAngleLoc());
4986 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4987 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4988 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004989
Douglas Gregora88f09f2011-02-28 17:23:35 +00004990 return Result;
4991}
4992
Mike Stump1eb44332009-09-09 15:08:12 +00004993template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004994QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004995TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004996 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004997 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004998
Douglas Gregor9e876872011-03-01 18:12:44 +00004999 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00005000 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00005001 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005002 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00005003 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5004 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00005005 return QualType();
5006 }
Mike Stump1eb44332009-09-09 15:08:12 +00005007
John McCall43fed0d2010-11-12 08:19:04 +00005008 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5009 if (NamedT.isNull())
5010 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00005011
Richard Smith3e4c6c42011-05-05 21:57:07 +00005012 // C++0x [dcl.type.elab]p2:
5013 // If the identifier resolves to a typedef-name or the simple-template-id
5014 // resolves to an alias template specialization, the
5015 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00005016 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5017 if (const TemplateSpecializationType *TST =
5018 NamedT->getAs<TemplateSpecializationType>()) {
5019 TemplateName Template = TST->getTemplateName();
5020 if (TypeAliasTemplateDecl *TAT =
5021 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
5022 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5023 diag::err_tag_reference_non_tag) << 4;
5024 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5025 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00005026 }
5027 }
5028
John McCalla2becad2009-10-21 00:40:46 +00005029 QualType Result = TL.getType();
5030 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00005031 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005032 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00005033 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00005034 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00005035 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00005036 if (Result.isNull())
5037 return QualType();
5038 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00005039
Abramo Bagnara465d41b2010-05-11 21:36:43 +00005040 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005041 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00005042 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00005043 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00005044}
Mike Stump1eb44332009-09-09 15:08:12 +00005045
5046template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00005047QualType TreeTransform<Derived>::TransformAttributedType(
5048 TypeLocBuilder &TLB,
5049 AttributedTypeLoc TL) {
5050 const AttributedType *oldType = TL.getTypePtr();
5051 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5052 if (modifiedType.isNull())
5053 return QualType();
5054
5055 QualType result = TL.getType();
5056
5057 // FIXME: dependent operand expressions?
5058 if (getDerived().AlwaysRebuild() ||
5059 modifiedType != oldType->getModifiedType()) {
5060 // TODO: this is really lame; we should really be rebuilding the
5061 // equivalent type from first principles.
5062 QualType equivalentType
5063 = getDerived().TransformType(oldType->getEquivalentType());
5064 if (equivalentType.isNull())
5065 return QualType();
5066 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5067 modifiedType,
5068 equivalentType);
5069 }
5070
5071 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5072 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5073 if (TL.hasAttrOperand())
5074 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5075 if (TL.hasAttrExprOperand())
5076 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5077 else if (TL.hasAttrEnumOperand())
5078 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5079
5080 return result;
5081}
5082
5083template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00005084QualType
5085TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5086 ParenTypeLoc TL) {
5087 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5088 if (Inner.isNull())
5089 return QualType();
5090
5091 QualType Result = TL.getType();
5092 if (getDerived().AlwaysRebuild() ||
5093 Inner != TL.getInnerLoc().getType()) {
5094 Result = getDerived().RebuildParenType(Inner);
5095 if (Result.isNull())
5096 return QualType();
5097 }
5098
5099 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5100 NewTL.setLParenLoc(TL.getLParenLoc());
5101 NewTL.setRParenLoc(TL.getRParenLoc());
5102 return Result;
5103}
5104
5105template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00005106QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005107 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00005108 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00005109
Douglas Gregor2494dd02011-03-01 01:34:45 +00005110 NestedNameSpecifierLoc QualifierLoc
5111 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5112 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00005113 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00005114
John McCall33500952010-06-11 00:33:02 +00005115 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00005116 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00005117 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00005118 QualifierLoc,
5119 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00005120 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00005121 if (Result.isNull())
5122 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005123
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005124 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5125 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00005126 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5127
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005128 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005129 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00005130 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00005131 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005132 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005133 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00005134 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005135 NewTL.setNameLoc(TL.getNameLoc());
5136 }
John McCalla2becad2009-10-21 00:40:46 +00005137 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00005138}
Mike Stump1eb44332009-09-09 15:08:12 +00005139
Douglas Gregor577f75a2009-08-04 16:50:30 +00005140template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00005141QualType TreeTransform<Derived>::
5142 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005143 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005144 NestedNameSpecifierLoc QualifierLoc;
5145 if (TL.getQualifierLoc()) {
5146 QualifierLoc
5147 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5148 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00005149 return QualType();
5150 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005151
John McCall43fed0d2010-11-12 08:19:04 +00005152 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005153 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00005154}
5155
5156template<typename Derived>
5157QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005158TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5159 DependentTemplateSpecializationTypeLoc TL,
5160 NestedNameSpecifierLoc QualifierLoc) {
5161 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005162
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005163 TemplateArgumentListInfo NewTemplateArgs;
5164 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5165 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005166
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005167 typedef TemplateArgumentLocContainerIterator<
5168 DependentTemplateSpecializationTypeLoc> ArgIterator;
5169 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5170 ArgIterator(TL, TL.getNumArgs()),
5171 NewTemplateArgs))
5172 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005173
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005174 QualType Result
5175 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5176 QualifierLoc,
5177 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005178 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005179 NewTemplateArgs);
5180 if (Result.isNull())
5181 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005182
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005183 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5184 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005185
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005186 // Copy information relevant to the template specialization.
5187 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005188 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005189 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005190 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005191 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5192 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005193 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005194 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005195
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005196 // Copy information relevant to the elaborated type.
5197 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005198 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005199 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005200 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5201 DependentTemplateSpecializationTypeLoc SpecTL
5202 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005203 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005204 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005205 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005206 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005207 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5208 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005209 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005210 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005211 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005212 TemplateSpecializationTypeLoc SpecTL
5213 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005214 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005215 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005216 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5217 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005218 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005219 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005220 }
5221 return Result;
5222}
5223
5224template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005225QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5226 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005227 QualType Pattern
5228 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005229 if (Pattern.isNull())
5230 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005231
5232 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005233 if (getDerived().AlwaysRebuild() ||
5234 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005235 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005236 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005237 TL.getEllipsisLoc(),
5238 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005239 if (Result.isNull())
5240 return QualType();
5241 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005242
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005243 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5244 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5245 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005246}
5247
5248template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005249QualType
5250TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005251 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005252 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005253 TLB.pushFullCopy(TL);
5254 return TL.getType();
5255}
5256
5257template<typename Derived>
5258QualType
5259TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005260 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005261 // ObjCObjectType is never dependent.
5262 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005263 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005264}
Mike Stump1eb44332009-09-09 15:08:12 +00005265
5266template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005267QualType
5268TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005269 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005270 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005271 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005272 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005273}
5274
Douglas Gregor577f75a2009-08-04 16:50:30 +00005275//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005276// Statement transformation
5277//===----------------------------------------------------------------------===//
5278template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005279StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005280TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005281 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005282}
5283
5284template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005285StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005286TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5287 return getDerived().TransformCompoundStmt(S, false);
5288}
5289
5290template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005291StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005292TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005293 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005294 Sema::CompoundScopeRAII CompoundScope(getSema());
5295
John McCall7114cba2010-08-27 19:56:05 +00005296 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005297 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005298 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005299 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5300 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005301 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005302 if (Result.isInvalid()) {
5303 // Immediately fail if this was a DeclStmt, since it's very
5304 // likely that this will cause problems for future statements.
5305 if (isa<DeclStmt>(*B))
5306 return StmtError();
5307
5308 // Otherwise, just keep processing substatements and fail later.
5309 SubStmtInvalid = true;
5310 continue;
5311 }
Mike Stump1eb44332009-09-09 15:08:12 +00005312
Douglas Gregor43959a92009-08-20 07:17:43 +00005313 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5314 Statements.push_back(Result.takeAs<Stmt>());
5315 }
Mike Stump1eb44332009-09-09 15:08:12 +00005316
John McCall7114cba2010-08-27 19:56:05 +00005317 if (SubStmtInvalid)
5318 return StmtError();
5319
Douglas Gregor43959a92009-08-20 07:17:43 +00005320 if (!getDerived().AlwaysRebuild() &&
5321 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005322 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005323
5324 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005325 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005326 S->getRBracLoc(),
5327 IsStmtExpr);
5328}
Mike Stump1eb44332009-09-09 15:08:12 +00005329
Douglas Gregor43959a92009-08-20 07:17:43 +00005330template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005331StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005332TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005333 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005334 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005335 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5336 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005337
Eli Friedman264c1f82009-11-19 03:14:00 +00005338 // Transform the left-hand case value.
5339 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005340 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005341 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005342 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005343
Eli Friedman264c1f82009-11-19 03:14:00 +00005344 // Transform the right-hand case value (for the GNU case-range extension).
5345 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005346 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005347 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005348 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005349 }
Mike Stump1eb44332009-09-09 15:08:12 +00005350
Douglas Gregor43959a92009-08-20 07:17:43 +00005351 // Build the case statement.
5352 // Case statements are always rebuilt so that they will attached to their
5353 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005354 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005355 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005356 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005357 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005358 S->getColonLoc());
5359 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005360 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005361
Douglas Gregor43959a92009-08-20 07:17:43 +00005362 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005363 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005364 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005365 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005366
Douglas Gregor43959a92009-08-20 07:17:43 +00005367 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005368 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005369}
5370
5371template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005372StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005373TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005374 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005375 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005376 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005377 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005378
Douglas Gregor43959a92009-08-20 07:17:43 +00005379 // Default statements are always rebuilt
5380 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005381 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005382}
Mike Stump1eb44332009-09-09 15:08:12 +00005383
Douglas Gregor43959a92009-08-20 07:17:43 +00005384template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005385StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005386TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005387 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005388 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005389 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005390
Chris Lattner57ad3782011-02-17 20:34:02 +00005391 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5392 S->getDecl());
5393 if (!LD)
5394 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005395
5396
Douglas Gregor43959a92009-08-20 07:17:43 +00005397 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005398 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005399 cast<LabelDecl>(LD), SourceLocation(),
5400 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005401}
Mike Stump1eb44332009-09-09 15:08:12 +00005402
Douglas Gregor43959a92009-08-20 07:17:43 +00005403template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005404StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005405TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5406 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5407 if (SubStmt.isInvalid())
5408 return StmtError();
5409
5410 // TODO: transform attributes
5411 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5412 return S;
5413
5414 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5415 S->getAttrs(),
5416 SubStmt.get());
5417}
5418
5419template<typename Derived>
5420StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005421TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005422 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005423 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005424 VarDecl *ConditionVar = 0;
5425 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005426 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005427 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005428 getDerived().TransformDefinition(
5429 S->getConditionVariable()->getLocation(),
5430 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005431 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005432 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005433 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005434 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005435
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005436 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005437 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005438
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005439 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005440 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005441 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005442 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005443 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005444 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005445
John McCall9ae2f072010-08-23 23:25:46 +00005446 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005447 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005448 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005449
John McCall9ae2f072010-08-23 23:25:46 +00005450 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5451 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005452 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005453
Douglas Gregor43959a92009-08-20 07:17:43 +00005454 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005455 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005456 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005457 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005458
Douglas Gregor43959a92009-08-20 07:17:43 +00005459 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005460 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005461 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005462 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005463
Douglas Gregor43959a92009-08-20 07:17:43 +00005464 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005465 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005466 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005467 Then.get() == S->getThen() &&
5468 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005469 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005470
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005471 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005472 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005473 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005474}
5475
5476template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005477StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005478TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005479 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005480 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005481 VarDecl *ConditionVar = 0;
5482 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005483 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005484 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005485 getDerived().TransformDefinition(
5486 S->getConditionVariable()->getLocation(),
5487 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005488 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005489 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005490 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005491 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005492
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005493 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005494 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005495 }
Mike Stump1eb44332009-09-09 15:08:12 +00005496
Douglas Gregor43959a92009-08-20 07:17:43 +00005497 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005498 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005499 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005500 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005501 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005502 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005503
Douglas Gregor43959a92009-08-20 07:17:43 +00005504 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005505 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005506 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005507 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005508
Douglas Gregor43959a92009-08-20 07:17:43 +00005509 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005510 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5511 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005512}
Mike Stump1eb44332009-09-09 15:08:12 +00005513
Douglas Gregor43959a92009-08-20 07:17:43 +00005514template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005515StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005516TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005517 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005518 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005519 VarDecl *ConditionVar = 0;
5520 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005521 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005522 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005523 getDerived().TransformDefinition(
5524 S->getConditionVariable()->getLocation(),
5525 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005526 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005527 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005528 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005529 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005530
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005531 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005532 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005533
5534 if (S->getCond()) {
5535 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005536 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005537 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005538 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005539 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005540 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005541 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005542 }
Mike Stump1eb44332009-09-09 15:08:12 +00005543
John McCall9ae2f072010-08-23 23:25:46 +00005544 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5545 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005546 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005547
Douglas Gregor43959a92009-08-20 07:17:43 +00005548 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005549 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005550 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005551 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005552
Douglas Gregor43959a92009-08-20 07:17:43 +00005553 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005554 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005555 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005556 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005557 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005558
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005559 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005560 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005561}
Mike Stump1eb44332009-09-09 15:08:12 +00005562
Douglas Gregor43959a92009-08-20 07:17:43 +00005563template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005564StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005565TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005566 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005567 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005568 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005569 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005570
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005571 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005572 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005573 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005574 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005575
Douglas Gregor43959a92009-08-20 07:17:43 +00005576 if (!getDerived().AlwaysRebuild() &&
5577 Cond.get() == S->getCond() &&
5578 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005579 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005580
John McCall9ae2f072010-08-23 23:25:46 +00005581 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5582 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005583 S->getRParenLoc());
5584}
Mike Stump1eb44332009-09-09 15:08:12 +00005585
Douglas Gregor43959a92009-08-20 07:17:43 +00005586template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005587StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005588TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005589 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005590 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005591 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005592 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005593
Douglas Gregor43959a92009-08-20 07:17:43 +00005594 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005595 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005596 VarDecl *ConditionVar = 0;
5597 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005598 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005599 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005600 getDerived().TransformDefinition(
5601 S->getConditionVariable()->getLocation(),
5602 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005603 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005604 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005605 } else {
5606 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005607
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005608 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005609 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005610
5611 if (S->getCond()) {
5612 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005613 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005614 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005615 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005616 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005617
John McCall9ae2f072010-08-23 23:25:46 +00005618 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005619 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005620 }
Mike Stump1eb44332009-09-09 15:08:12 +00005621
Chad Rosier4a9d7952012-08-08 18:46:20 +00005622 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005623 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005624 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005625
Douglas Gregor43959a92009-08-20 07:17:43 +00005626 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005627 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005628 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005629 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005630
Richard Smith41956372013-01-14 22:39:08 +00005631 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005632 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005633 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005634
Douglas Gregor43959a92009-08-20 07:17:43 +00005635 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005636 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005637 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005638 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005639
Douglas Gregor43959a92009-08-20 07:17:43 +00005640 if (!getDerived().AlwaysRebuild() &&
5641 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005642 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005643 Inc.get() == S->getInc() &&
5644 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005645 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005646
Douglas Gregor43959a92009-08-20 07:17:43 +00005647 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005648 Init.get(), FullCond, ConditionVar,
5649 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005650}
5651
5652template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005653StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005654TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005655 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5656 S->getLabel());
5657 if (!LD)
5658 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005659
Douglas Gregor43959a92009-08-20 07:17:43 +00005660 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005661 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005662 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005663}
5664
5665template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005666StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005667TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005668 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005669 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005670 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005671 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005672
Douglas Gregor43959a92009-08-20 07:17:43 +00005673 if (!getDerived().AlwaysRebuild() &&
5674 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005675 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005676
5677 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005678 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005679}
5680
5681template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005682StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005683TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005684 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005685}
Mike Stump1eb44332009-09-09 15:08:12 +00005686
Douglas Gregor43959a92009-08-20 07:17:43 +00005687template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005688StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005689TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005690 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005691}
Mike Stump1eb44332009-09-09 15:08:12 +00005692
Douglas Gregor43959a92009-08-20 07:17:43 +00005693template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005694StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005695TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005696 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005697 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005698 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005699
Mike Stump1eb44332009-09-09 15:08:12 +00005700 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005701 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005702 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005703}
Mike Stump1eb44332009-09-09 15:08:12 +00005704
Douglas Gregor43959a92009-08-20 07:17:43 +00005705template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005706StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005707TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005708 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005709 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005710 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5711 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005712 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5713 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005714 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005715 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005716
Douglas Gregor43959a92009-08-20 07:17:43 +00005717 if (Transformed != *D)
5718 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005719
Douglas Gregor43959a92009-08-20 07:17:43 +00005720 Decls.push_back(Transformed);
5721 }
Mike Stump1eb44332009-09-09 15:08:12 +00005722
Douglas Gregor43959a92009-08-20 07:17:43 +00005723 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005724 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005725
Rafael Espindola4549d7f2013-07-09 12:05:01 +00005726 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005727}
Mike Stump1eb44332009-09-09 15:08:12 +00005728
Douglas Gregor43959a92009-08-20 07:17:43 +00005729template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005730StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005731TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005732
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005733 SmallVector<Expr*, 8> Constraints;
5734 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005735 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005736
John McCall60d7b3a2010-08-24 06:29:42 +00005737 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005738 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005739
5740 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005741
Anders Carlsson703e3942010-01-24 05:50:09 +00005742 // Go through the outputs.
5743 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005744 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005745
Anders Carlsson703e3942010-01-24 05:50:09 +00005746 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005747 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005748
Anders Carlsson703e3942010-01-24 05:50:09 +00005749 // Transform the output expr.
5750 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005751 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005752 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005753 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005754
Anders Carlsson703e3942010-01-24 05:50:09 +00005755 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005756
John McCall9ae2f072010-08-23 23:25:46 +00005757 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005758 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005759
Anders Carlsson703e3942010-01-24 05:50:09 +00005760 // Go through the inputs.
5761 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005762 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005763
Anders Carlsson703e3942010-01-24 05:50:09 +00005764 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005765 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005766
Anders Carlsson703e3942010-01-24 05:50:09 +00005767 // Transform the input expr.
5768 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005769 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005770 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005771 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005772
Anders Carlsson703e3942010-01-24 05:50:09 +00005773 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005774
John McCall9ae2f072010-08-23 23:25:46 +00005775 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005776 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005777
Anders Carlsson703e3942010-01-24 05:50:09 +00005778 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005779 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005780
5781 // Go through the clobbers.
5782 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005783 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005784
5785 // No need to transform the asm string literal.
5786 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005787 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5788 S->isVolatile(), S->getNumOutputs(),
5789 S->getNumInputs(), Names.data(),
5790 Constraints, Exprs, AsmString.get(),
5791 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005792}
5793
Chad Rosier8cd64b42012-06-11 20:47:18 +00005794template<typename Derived>
5795StmtResult
5796TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005797 ArrayRef<Token> AsmToks =
5798 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005799
John McCallaeeacf72013-05-03 00:10:13 +00005800 bool HadError = false, HadChange = false;
5801
5802 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5803 SmallVector<Expr*, 8> TransformedExprs;
5804 TransformedExprs.reserve(SrcExprs.size());
5805 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5806 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5807 if (!Result.isUsable()) {
5808 HadError = true;
5809 } else {
5810 HadChange |= (Result.get() != SrcExprs[i]);
5811 TransformedExprs.push_back(Result.take());
5812 }
5813 }
5814
5815 if (HadError) return StmtError();
5816 if (!HadChange && !getDerived().AlwaysRebuild())
5817 return Owned(S);
5818
Chad Rosier7bd092b2012-08-15 16:53:30 +00005819 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallaeeacf72013-05-03 00:10:13 +00005820 AsmToks, S->getAsmString(),
5821 S->getNumOutputs(), S->getNumInputs(),
5822 S->getAllConstraints(), S->getClobbers(),
5823 TransformedExprs, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005824}
Douglas Gregor43959a92009-08-20 07:17:43 +00005825
5826template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005827StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005828TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005829 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005830 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005831 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005832 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005833
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005834 // Transform the @catch statements (if present).
5835 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005836 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005837 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005838 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005839 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005840 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005841 if (Catch.get() != S->getCatchStmt(I))
5842 AnyCatchChanged = true;
5843 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005844 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005845
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005846 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005847 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005848 if (S->getFinallyStmt()) {
5849 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5850 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005851 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005852 }
5853
5854 // If nothing changed, just retain this statement.
5855 if (!getDerived().AlwaysRebuild() &&
5856 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005857 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005858 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005859 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005860
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005861 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005862 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005863 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005864}
Mike Stump1eb44332009-09-09 15:08:12 +00005865
Douglas Gregor43959a92009-08-20 07:17:43 +00005866template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005867StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005868TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005869 // Transform the @catch parameter, if there is one.
5870 VarDecl *Var = 0;
5871 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5872 TypeSourceInfo *TSInfo = 0;
5873 if (FromVar->getTypeSourceInfo()) {
5874 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5875 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005876 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005877 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005878
Douglas Gregorbe270a02010-04-26 17:57:08 +00005879 QualType T;
5880 if (TSInfo)
5881 T = TSInfo->getType();
5882 else {
5883 T = getDerived().TransformType(FromVar->getType());
5884 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005885 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005886 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005887
Douglas Gregorbe270a02010-04-26 17:57:08 +00005888 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5889 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005890 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005891 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005892
John McCall60d7b3a2010-08-24 06:29:42 +00005893 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005894 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005895 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005896
5897 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005898 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005899 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005900}
Mike Stump1eb44332009-09-09 15:08:12 +00005901
Douglas Gregor43959a92009-08-20 07:17:43 +00005902template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005903StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005904TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005905 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005906 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005907 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005908 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005909
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005910 // If nothing changed, just retain this statement.
5911 if (!getDerived().AlwaysRebuild() &&
5912 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005913 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005914
5915 // Build a new statement.
5916 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005917 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005918}
Mike Stump1eb44332009-09-09 15:08:12 +00005919
Douglas Gregor43959a92009-08-20 07:17:43 +00005920template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005921StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005922TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005923 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005924 if (S->getThrowExpr()) {
5925 Operand = getDerived().TransformExpr(S->getThrowExpr());
5926 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005927 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005928 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005929
Douglas Gregord1377b22010-04-22 21:44:01 +00005930 if (!getDerived().AlwaysRebuild() &&
5931 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005932 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005933
John McCall9ae2f072010-08-23 23:25:46 +00005934 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005935}
Mike Stump1eb44332009-09-09 15:08:12 +00005936
Douglas Gregor43959a92009-08-20 07:17:43 +00005937template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005938StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005939TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005940 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005941 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005942 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005943 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005944 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005945 Object =
5946 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5947 Object.get());
5948 if (Object.isInvalid())
5949 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005950
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005951 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005952 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005953 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005954 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005955
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005956 // If nothing change, just retain the current statement.
5957 if (!getDerived().AlwaysRebuild() &&
5958 Object.get() == S->getSynchExpr() &&
5959 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005960 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005961
5962 // Build a new statement.
5963 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005964 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005965}
5966
5967template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005968StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005969TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5970 ObjCAutoreleasePoolStmt *S) {
5971 // Transform the body.
5972 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5973 if (Body.isInvalid())
5974 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005975
John McCallf85e1932011-06-15 23:02:42 +00005976 // If nothing changed, just retain this statement.
5977 if (!getDerived().AlwaysRebuild() &&
5978 Body.get() == S->getSubStmt())
5979 return SemaRef.Owned(S);
5980
5981 // Build a new statement.
5982 return getDerived().RebuildObjCAutoreleasePoolStmt(
5983 S->getAtLoc(), Body.get());
5984}
5985
5986template<typename Derived>
5987StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005988TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005989 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005990 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005991 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005992 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005993 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005994
Douglas Gregorc3203e72010-04-22 23:10:45 +00005995 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005996 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005997 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005998 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005999
Douglas Gregorc3203e72010-04-22 23:10:45 +00006000 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00006001 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00006002 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006003 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006004
Douglas Gregorc3203e72010-04-22 23:10:45 +00006005 // If nothing changed, just retain this statement.
6006 if (!getDerived().AlwaysRebuild() &&
6007 Element.get() == S->getElement() &&
6008 Collection.get() == S->getCollection() &&
6009 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00006010 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006011
Douglas Gregorc3203e72010-04-22 23:10:45 +00006012 // Build a new statement.
6013 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006014 Element.get(),
6015 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00006016 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006017 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00006018}
6019
6020
6021template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006022StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00006023TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
6024 // Transform the exception declaration, if any.
6025 VarDecl *Var = 0;
6026 if (S->getExceptionDecl()) {
6027 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00006028 TypeSourceInfo *T = getDerived().TransformType(
6029 ExceptionDecl->getTypeSourceInfo());
6030 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006031 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006032
Douglas Gregor83cb9422010-09-09 17:09:21 +00006033 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00006034 ExceptionDecl->getInnerLocStart(),
6035 ExceptionDecl->getLocation(),
6036 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00006037 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00006038 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00006039 }
Mike Stump1eb44332009-09-09 15:08:12 +00006040
Douglas Gregor43959a92009-08-20 07:17:43 +00006041 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00006042 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00006043 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006044 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006045
Douglas Gregor43959a92009-08-20 07:17:43 +00006046 if (!getDerived().AlwaysRebuild() &&
6047 !Var &&
6048 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00006049 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00006050
6051 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
6052 Var,
John McCall9ae2f072010-08-23 23:25:46 +00006053 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00006054}
Mike Stump1eb44332009-09-09 15:08:12 +00006055
Douglas Gregor43959a92009-08-20 07:17:43 +00006056template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006057StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00006058TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
6059 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006060 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00006061 = getDerived().TransformCompoundStmt(S->getTryBlock());
6062 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006063 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006064
Douglas Gregor43959a92009-08-20 07:17:43 +00006065 // Transform the handlers.
6066 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006067 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00006068 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006069 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00006070 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
6071 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006072 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006073
Douglas Gregor43959a92009-08-20 07:17:43 +00006074 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6075 Handlers.push_back(Handler.takeAs<Stmt>());
6076 }
Mike Stump1eb44332009-09-09 15:08:12 +00006077
Douglas Gregor43959a92009-08-20 07:17:43 +00006078 if (!getDerived().AlwaysRebuild() &&
6079 TryBlock.get() == S->getTryBlock() &&
6080 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006081 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00006082
John McCall9ae2f072010-08-23 23:25:46 +00006083 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006084 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00006085}
Mike Stump1eb44332009-09-09 15:08:12 +00006086
Richard Smithad762fc2011-04-14 22:09:26 +00006087template<typename Derived>
6088StmtResult
6089TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6090 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6091 if (Range.isInvalid())
6092 return StmtError();
6093
6094 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6095 if (BeginEnd.isInvalid())
6096 return StmtError();
6097
6098 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6099 if (Cond.isInvalid())
6100 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006101 if (Cond.get())
6102 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6103 if (Cond.isInvalid())
6104 return StmtError();
6105 if (Cond.get())
6106 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006107
6108 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6109 if (Inc.isInvalid())
6110 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006111 if (Inc.get())
6112 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006113
6114 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6115 if (LoopVar.isInvalid())
6116 return StmtError();
6117
6118 StmtResult NewStmt = S;
6119 if (getDerived().AlwaysRebuild() ||
6120 Range.get() != S->getRangeStmt() ||
6121 BeginEnd.get() != S->getBeginEndStmt() ||
6122 Cond.get() != S->getCond() ||
6123 Inc.get() != S->getInc() ||
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006124 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smithad762fc2011-04-14 22:09:26 +00006125 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6126 S->getColonLoc(), Range.get(),
6127 BeginEnd.get(), Cond.get(),
6128 Inc.get(), LoopVar.get(),
6129 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006130 if (NewStmt.isInvalid())
6131 return StmtError();
6132 }
Richard Smithad762fc2011-04-14 22:09:26 +00006133
6134 StmtResult Body = getDerived().TransformStmt(S->getBody());
6135 if (Body.isInvalid())
6136 return StmtError();
6137
6138 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6139 // it now so we have a new statement to attach the body to.
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006140 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smithad762fc2011-04-14 22:09:26 +00006141 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6142 S->getColonLoc(), Range.get(),
6143 BeginEnd.get(), Cond.get(),
6144 Inc.get(), LoopVar.get(),
6145 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006146 if (NewStmt.isInvalid())
6147 return StmtError();
6148 }
Richard Smithad762fc2011-04-14 22:09:26 +00006149
6150 if (NewStmt.get() == S)
6151 return SemaRef.Owned(S);
6152
6153 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6154}
6155
John Wiegley28bbe4b2011-04-28 01:08:34 +00006156template<typename Derived>
6157StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00006158TreeTransform<Derived>::TransformMSDependentExistsStmt(
6159 MSDependentExistsStmt *S) {
6160 // Transform the nested-name-specifier, if any.
6161 NestedNameSpecifierLoc QualifierLoc;
6162 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006163 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00006164 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6165 if (!QualifierLoc)
6166 return StmtError();
6167 }
6168
6169 // Transform the declaration name.
6170 DeclarationNameInfo NameInfo = S->getNameInfo();
6171 if (NameInfo.getName()) {
6172 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6173 if (!NameInfo.getName())
6174 return StmtError();
6175 }
6176
6177 // Check whether anything changed.
6178 if (!getDerived().AlwaysRebuild() &&
6179 QualifierLoc == S->getQualifierLoc() &&
6180 NameInfo.getName() == S->getNameInfo().getName())
6181 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006182
Douglas Gregorba0513d2011-10-25 01:33:02 +00006183 // Determine whether this name exists, if we can.
6184 CXXScopeSpec SS;
6185 SS.Adopt(QualifierLoc);
6186 bool Dependent = false;
6187 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6188 case Sema::IER_Exists:
6189 if (S->isIfExists())
6190 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006191
Douglas Gregorba0513d2011-10-25 01:33:02 +00006192 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6193
6194 case Sema::IER_DoesNotExist:
6195 if (S->isIfNotExists())
6196 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006197
Douglas Gregorba0513d2011-10-25 01:33:02 +00006198 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006199
Douglas Gregorba0513d2011-10-25 01:33:02 +00006200 case Sema::IER_Dependent:
6201 Dependent = true;
6202 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006203
Douglas Gregor65019ac2011-10-25 03:44:56 +00006204 case Sema::IER_Error:
6205 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006206 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006207
Douglas Gregorba0513d2011-10-25 01:33:02 +00006208 // We need to continue with the instantiation, so do so now.
6209 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6210 if (SubStmt.isInvalid())
6211 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006212
Douglas Gregorba0513d2011-10-25 01:33:02 +00006213 // If we have resolved the name, just transform to the substatement.
6214 if (!Dependent)
6215 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006216
Douglas Gregorba0513d2011-10-25 01:33:02 +00006217 // The name is still dependent, so build a dependent expression again.
6218 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6219 S->isIfExists(),
6220 QualifierLoc,
6221 NameInfo,
6222 SubStmt.get());
6223}
6224
6225template<typename Derived>
John McCall76da55d2013-04-16 07:28:30 +00006226ExprResult
6227TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6228 NestedNameSpecifierLoc QualifierLoc;
6229 if (E->getQualifierLoc()) {
6230 QualifierLoc
6231 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6232 if (!QualifierLoc)
6233 return ExprError();
6234 }
6235
6236 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6237 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6238 if (!PD)
6239 return ExprError();
6240
6241 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6242 if (Base.isInvalid())
6243 return ExprError();
6244
6245 return new (SemaRef.getASTContext())
6246 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6247 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6248 QualifierLoc, E->getMemberLoc());
6249}
6250
6251template<typename Derived>
Douglas Gregorba0513d2011-10-25 01:33:02 +00006252StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006253TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6254 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6255 if(TryBlock.isInvalid()) return StmtError();
6256
6257 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6258 if(!getDerived().AlwaysRebuild() &&
6259 TryBlock.get() == S->getTryBlock() &&
6260 Handler.get() == S->getHandler())
6261 return SemaRef.Owned(S);
6262
6263 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6264 S->getTryLoc(),
6265 TryBlock.take(),
6266 Handler.take());
6267}
6268
6269template<typename Derived>
6270StmtResult
6271TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6272 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6273 if(Block.isInvalid()) return StmtError();
6274
6275 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6276 Block.take());
6277}
6278
6279template<typename Derived>
6280StmtResult
6281TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6282 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6283 if(FilterExpr.isInvalid()) return StmtError();
6284
6285 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6286 if(Block.isInvalid()) return StmtError();
6287
6288 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6289 FilterExpr.take(),
6290 Block.take());
6291}
6292
6293template<typename Derived>
6294StmtResult
6295TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6296 if(isa<SEHFinallyStmt>(Handler))
6297 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6298 else
6299 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6300}
6301
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006302template<typename Derived>
6303StmtResult
6304TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
Alexey Bataev0c018352013-09-06 18:03:48 +00006305 DeclarationNameInfo DirName;
6306 getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);
6307
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006308 // Transform the clauses
Alexey Bataev0c018352013-09-06 18:03:48 +00006309 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006310 ArrayRef<OMPClause *> Clauses = D->clauses();
6311 TClauses.reserve(Clauses.size());
6312 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6313 I != E; ++I) {
6314 if (*I) {
6315 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev0c018352013-09-06 18:03:48 +00006316 if (!Clause) {
6317 getSema().EndOpenMPDSABlock(0);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006318 return StmtError();
Alexey Bataev0c018352013-09-06 18:03:48 +00006319 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006320 TClauses.push_back(Clause);
6321 }
6322 else {
6323 TClauses.push_back(0);
6324 }
6325 }
Alexey Bataev0c018352013-09-06 18:03:48 +00006326 if (!D->getAssociatedStmt()) {
6327 getSema().EndOpenMPDSABlock(0);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006328 return StmtError();
Alexey Bataev0c018352013-09-06 18:03:48 +00006329 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006330 StmtResult AssociatedStmt =
6331 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev0c018352013-09-06 18:03:48 +00006332 if (AssociatedStmt.isInvalid()) {
6333 getSema().EndOpenMPDSABlock(0);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006334 return StmtError();
Alexey Bataev0c018352013-09-06 18:03:48 +00006335 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006336
Alexey Bataev0c018352013-09-06 18:03:48 +00006337 StmtResult Res = getDerived().RebuildOMPParallelDirective(TClauses,
6338 AssociatedStmt.take(),
6339 D->getLocStart(),
6340 D->getLocEnd());
6341 getSema().EndOpenMPDSABlock(Res.get());
6342 return Res;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006343}
6344
6345template<typename Derived>
6346OMPClause *
6347TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6348 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6349 C->getDefaultKindKwLoc(),
6350 C->getLocStart(),
6351 C->getLParenLoc(),
6352 C->getLocEnd());
6353}
6354
6355template<typename Derived>
6356OMPClause *
6357TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev0c018352013-09-06 18:03:48 +00006358 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006359 Vars.reserve(C->varlist_size());
Alexey Bataev543c4ae2013-09-24 03:17:45 +00006360 for (OMPPrivateClause::varlist_iterator I = C->varlist_begin(),
6361 E = C->varlist_end();
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006362 I != E; ++I) {
6363 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6364 if (EVar.isInvalid())
6365 return 0;
6366 Vars.push_back(EVar.take());
6367 }
6368 return getDerived().RebuildOMPPrivateClause(Vars,
6369 C->getLocStart(),
6370 C->getLParenLoc(),
6371 C->getLocEnd());
6372}
6373
Alexey Bataev0c018352013-09-06 18:03:48 +00006374template<typename Derived>
6375OMPClause *
Alexey Bataevd195bc32013-10-01 05:32:34 +00006376TreeTransform<Derived>::TransformOMPFirstprivateClause(
6377 OMPFirstprivateClause *C) {
6378 llvm::SmallVector<Expr *, 16> Vars;
6379 Vars.reserve(C->varlist_size());
6380 for (OMPFirstprivateClause::varlist_iterator I = C->varlist_begin(),
6381 E = C->varlist_end();
6382 I != E; ++I) {
6383 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6384 if (EVar.isInvalid())
6385 return 0;
6386 Vars.push_back(EVar.take());
6387 }
6388 return getDerived().RebuildOMPFirstprivateClause(Vars,
6389 C->getLocStart(),
6390 C->getLParenLoc(),
6391 C->getLocEnd());
6392}
6393
6394template<typename Derived>
6395OMPClause *
Alexey Bataev0c018352013-09-06 18:03:48 +00006396TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6397 llvm::SmallVector<Expr *, 16> Vars;
6398 Vars.reserve(C->varlist_size());
Alexey Bataev543c4ae2013-09-24 03:17:45 +00006399 for (OMPSharedClause::varlist_iterator I = C->varlist_begin(),
6400 E = C->varlist_end();
Alexey Bataev0c018352013-09-06 18:03:48 +00006401 I != E; ++I) {
6402 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6403 if (EVar.isInvalid())
6404 return 0;
6405 Vars.push_back(EVar.take());
6406 }
6407 return getDerived().RebuildOMPSharedClause(Vars,
6408 C->getLocStart(),
6409 C->getLParenLoc(),
6410 C->getLocEnd());
6411}
6412
Douglas Gregor43959a92009-08-20 07:17:43 +00006413//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006414// Expression transformation
6415//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006416template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006417ExprResult
John McCall454feb92009-12-08 09:21:05 +00006418TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006419 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006420}
Mike Stump1eb44332009-09-09 15:08:12 +00006421
6422template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006423ExprResult
John McCall454feb92009-12-08 09:21:05 +00006424TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006425 NestedNameSpecifierLoc QualifierLoc;
6426 if (E->getQualifierLoc()) {
6427 QualifierLoc
6428 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6429 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006430 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006431 }
John McCalldbd872f2009-12-08 09:08:17 +00006432
6433 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006434 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6435 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006436 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006437 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006438
John McCallec8045d2010-08-17 21:27:17 +00006439 DeclarationNameInfo NameInfo = E->getNameInfo();
6440 if (NameInfo.getName()) {
6441 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6442 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006443 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006444 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006445
6446 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006447 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006448 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006449 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006450 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006451
6452 // Mark it referenced in the new context regardless.
6453 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006454 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006455
John McCall3fa5cae2010-10-26 07:05:15 +00006456 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006457 }
John McCalldbd872f2009-12-08 09:08:17 +00006458
6459 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006460 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006461 TemplateArgs = &TransArgs;
6462 TransArgs.setLAngleLoc(E->getLAngleLoc());
6463 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006464 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6465 E->getNumTemplateArgs(),
6466 TransArgs))
6467 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006468 }
6469
Chad Rosier4a9d7952012-08-08 18:46:20 +00006470 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006471 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006472}
Mike Stump1eb44332009-09-09 15:08:12 +00006473
Douglas Gregorb98b1992009-08-11 05:31:07 +00006474template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006475ExprResult
John McCall454feb92009-12-08 09:21:05 +00006476TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006477 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006478}
Mike Stump1eb44332009-09-09 15:08:12 +00006479
Douglas Gregorb98b1992009-08-11 05:31:07 +00006480template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006481ExprResult
John McCall454feb92009-12-08 09:21:05 +00006482TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006483 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006484}
Mike Stump1eb44332009-09-09 15:08:12 +00006485
Douglas Gregorb98b1992009-08-11 05:31:07 +00006486template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006487ExprResult
John McCall454feb92009-12-08 09:21:05 +00006488TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006489 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006490}
Mike Stump1eb44332009-09-09 15:08:12 +00006491
Douglas Gregorb98b1992009-08-11 05:31:07 +00006492template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006493ExprResult
John McCall454feb92009-12-08 09:21:05 +00006494TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006495 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006496}
Mike Stump1eb44332009-09-09 15:08:12 +00006497
Douglas Gregorb98b1992009-08-11 05:31:07 +00006498template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006499ExprResult
John McCall454feb92009-12-08 09:21:05 +00006500TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006501 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006502}
6503
6504template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006505ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006506TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis391ca9f2013-04-09 01:17:02 +00006507 if (FunctionDecl *FD = E->getDirectCallee())
6508 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smith9fcce652012-03-07 08:35:16 +00006509 return SemaRef.MaybeBindToTemporary(E);
6510}
6511
6512template<typename Derived>
6513ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006514TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6515 ExprResult ControllingExpr =
6516 getDerived().TransformExpr(E->getControllingExpr());
6517 if (ControllingExpr.isInvalid())
6518 return ExprError();
6519
Chris Lattner686775d2011-07-20 06:58:45 +00006520 SmallVector<Expr *, 4> AssocExprs;
6521 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006522 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6523 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6524 if (TS) {
6525 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6526 if (!AssocType)
6527 return ExprError();
6528 AssocTypes.push_back(AssocType);
6529 } else {
6530 AssocTypes.push_back(0);
6531 }
6532
6533 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6534 if (AssocExpr.isInvalid())
6535 return ExprError();
6536 AssocExprs.push_back(AssocExpr.release());
6537 }
6538
6539 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6540 E->getDefaultLoc(),
6541 E->getRParenLoc(),
6542 ControllingExpr.release(),
Dmitri Gribenko80613222013-05-10 13:06:58 +00006543 AssocTypes,
6544 AssocExprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00006545}
6546
6547template<typename Derived>
6548ExprResult
John McCall454feb92009-12-08 09:21:05 +00006549TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006550 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006551 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006552 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006553
Douglas Gregorb98b1992009-08-11 05:31:07 +00006554 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006555 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006556
John McCall9ae2f072010-08-23 23:25:46 +00006557 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006558 E->getRParen());
6559}
6560
Richard Smithefeeccf2012-10-21 03:28:35 +00006561/// \brief The operand of a unary address-of operator has special rules: it's
6562/// allowed to refer to a non-static member of a class even if there's no 'this'
6563/// object available.
6564template<typename Derived>
6565ExprResult
6566TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6567 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6568 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6569 else
6570 return getDerived().TransformExpr(E);
6571}
6572
Mike Stump1eb44332009-09-09 15:08:12 +00006573template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006574ExprResult
John McCall454feb92009-12-08 09:21:05 +00006575TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smith82b00012013-05-21 23:29:46 +00006576 ExprResult SubExpr;
6577 if (E->getOpcode() == UO_AddrOf)
6578 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6579 else
6580 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006581 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006582 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006583
Douglas Gregorb98b1992009-08-11 05:31:07 +00006584 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006585 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006586
Douglas Gregorb98b1992009-08-11 05:31:07 +00006587 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6588 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006589 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006590}
Mike Stump1eb44332009-09-09 15:08:12 +00006591
Douglas Gregorb98b1992009-08-11 05:31:07 +00006592template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006593ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006594TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6595 // Transform the type.
6596 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6597 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006598 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006599
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006600 // Transform all of the components into components similar to what the
6601 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006602 // FIXME: It would be slightly more efficient in the non-dependent case to
6603 // just map FieldDecls, rather than requiring the rebuilder to look for
6604 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006605 // template code that we don't care.
6606 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006607 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006608 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006609 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006610 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6611 const Node &ON = E->getComponent(I);
6612 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006613 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006614 Comp.LocStart = ON.getSourceRange().getBegin();
6615 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006616 switch (ON.getKind()) {
6617 case Node::Array: {
6618 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006619 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006620 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006621 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006622
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006623 ExprChanged = ExprChanged || Index.get() != FromIndex;
6624 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006625 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006626 break;
6627 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006628
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006629 case Node::Field:
6630 case Node::Identifier:
6631 Comp.isBrackets = false;
6632 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006633 if (!Comp.U.IdentInfo)
6634 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006635
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006636 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006637
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006638 case Node::Base:
6639 // Will be recomputed during the rebuild.
6640 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006641 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006642
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006643 Components.push_back(Comp);
6644 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006645
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006646 // If nothing changed, retain the existing expression.
6647 if (!getDerived().AlwaysRebuild() &&
6648 Type == E->getTypeSourceInfo() &&
6649 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006650 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006651
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006652 // Build a new offsetof expression.
6653 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6654 Components.data(), Components.size(),
6655 E->getRParenLoc());
6656}
6657
6658template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006659ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006660TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6661 assert(getDerived().AlreadyTransformed(E->getType()) &&
6662 "opaque value expression requires transformation");
6663 return SemaRef.Owned(E);
6664}
6665
6666template<typename Derived>
6667ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006668TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006669 // Rebuild the syntactic form. The original syntactic form has
6670 // opaque-value expressions in it, so strip those away and rebuild
6671 // the result. This is a really awful way of doing this, but the
6672 // better solution (rebuilding the semantic expressions and
6673 // rebinding OVEs as necessary) doesn't work; we'd need
6674 // TreeTransform to not strip away implicit conversions.
6675 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6676 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006677 if (result.isInvalid()) return ExprError();
6678
6679 // If that gives us a pseudo-object result back, the pseudo-object
6680 // expression must have been an lvalue-to-rvalue conversion which we
6681 // should reapply.
6682 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6683 result = SemaRef.checkPseudoObjectRValue(result.take());
6684
6685 return result;
6686}
6687
6688template<typename Derived>
6689ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006690TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6691 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006692 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006693 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006694
John McCalla93c9342009-12-07 02:54:59 +00006695 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006696 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006697 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006698
John McCall5ab75172009-11-04 07:28:41 +00006699 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006700 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006701
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006702 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6703 E->getKind(),
6704 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006705 }
Mike Stump1eb44332009-09-09 15:08:12 +00006706
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006707 // C++0x [expr.sizeof]p1:
6708 // The operand is either an expression, which is an unevaluated operand
6709 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006710 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6711 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006712
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006713 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6714 if (SubExpr.isInvalid())
6715 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006716
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006717 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6718 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006719
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006720 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6721 E->getOperatorLoc(),
6722 E->getKind(),
6723 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006724}
Mike Stump1eb44332009-09-09 15:08:12 +00006725
Douglas Gregorb98b1992009-08-11 05:31:07 +00006726template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006727ExprResult
John McCall454feb92009-12-08 09:21:05 +00006728TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006729 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006730 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006731 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006732
John McCall60d7b3a2010-08-24 06:29:42 +00006733 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006734 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006735 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006736
6737
Douglas Gregorb98b1992009-08-11 05:31:07 +00006738 if (!getDerived().AlwaysRebuild() &&
6739 LHS.get() == E->getLHS() &&
6740 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006741 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006742
John McCall9ae2f072010-08-23 23:25:46 +00006743 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006744 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006745 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006746 E->getRBracketLoc());
6747}
Mike Stump1eb44332009-09-09 15:08:12 +00006748
6749template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006750ExprResult
John McCall454feb92009-12-08 09:21:05 +00006751TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006752 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006753 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006754 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006755 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006756
6757 // Transform arguments.
6758 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006759 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006760 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006761 &ArgChanged))
6762 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006763
Douglas Gregorb98b1992009-08-11 05:31:07 +00006764 if (!getDerived().AlwaysRebuild() &&
6765 Callee.get() == E->getCallee() &&
6766 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006767 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006768
Douglas Gregorb98b1992009-08-11 05:31:07 +00006769 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006770 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006771 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006772 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006773 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006774 E->getRParenLoc());
6775}
Mike Stump1eb44332009-09-09 15:08:12 +00006776
6777template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006778ExprResult
John McCall454feb92009-12-08 09:21:05 +00006779TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006780 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006781 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006782 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006783
Douglas Gregor40d96a62011-02-28 21:54:11 +00006784 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006785 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006786 QualifierLoc
6787 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006788
Douglas Gregor40d96a62011-02-28 21:54:11 +00006789 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006790 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006791 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006792 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006793
Eli Friedmanf595cc42009-12-04 06:40:45 +00006794 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006795 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6796 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006797 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006798 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006799
John McCall6bb80172010-03-30 21:47:33 +00006800 NamedDecl *FoundDecl = E->getFoundDecl();
6801 if (FoundDecl == E->getMemberDecl()) {
6802 FoundDecl = Member;
6803 } else {
6804 FoundDecl = cast_or_null<NamedDecl>(
6805 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6806 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006807 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006808 }
6809
Douglas Gregorb98b1992009-08-11 05:31:07 +00006810 if (!getDerived().AlwaysRebuild() &&
6811 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006812 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006813 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006814 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006815 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006816
Anders Carlsson1f240322009-12-22 05:24:09 +00006817 // Mark it referenced in the new context regardless.
6818 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006819 SemaRef.MarkMemberReferenced(E);
6820
John McCall3fa5cae2010-10-26 07:05:15 +00006821 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006822 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006823
John McCalld5532b62009-11-23 01:53:49 +00006824 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006825 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006826 TransArgs.setLAngleLoc(E->getLAngleLoc());
6827 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006828 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6829 E->getNumTemplateArgs(),
6830 TransArgs))
6831 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006832 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006833
Douglas Gregorb98b1992009-08-11 05:31:07 +00006834 // FIXME: Bogus source location for the operator
6835 SourceLocation FakeOperatorLoc
6836 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6837
John McCallc2233c52010-01-15 08:34:02 +00006838 // FIXME: to do this check properly, we will need to preserve the
6839 // first-qualifier-in-scope here, just in case we had a dependent
6840 // base (and therefore couldn't do the check) and a
6841 // nested-name-qualifier (and therefore could do the lookup).
6842 NamedDecl *FirstQualifierInScope = 0;
6843
John McCall9ae2f072010-08-23 23:25:46 +00006844 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006845 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006846 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006847 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006848 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006849 Member,
John McCall6bb80172010-03-30 21:47:33 +00006850 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006851 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006852 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006853 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006854}
Mike Stump1eb44332009-09-09 15:08:12 +00006855
Douglas Gregorb98b1992009-08-11 05:31:07 +00006856template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006857ExprResult
John McCall454feb92009-12-08 09:21:05 +00006858TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006859 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006860 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006861 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006862
John McCall60d7b3a2010-08-24 06:29:42 +00006863 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006864 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006865 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006866
Douglas Gregorb98b1992009-08-11 05:31:07 +00006867 if (!getDerived().AlwaysRebuild() &&
6868 LHS.get() == E->getLHS() &&
6869 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006870 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006871
Lang Hamesbe9af122012-10-02 04:45:10 +00006872 Sema::FPContractStateRAII FPContractState(getSema());
6873 getSema().FPFeatures.fp_contract = E->isFPContractable();
6874
Douglas Gregorb98b1992009-08-11 05:31:07 +00006875 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006876 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006877}
6878
Mike Stump1eb44332009-09-09 15:08:12 +00006879template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006880ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006881TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006882 CompoundAssignOperator *E) {
6883 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006884}
Mike Stump1eb44332009-09-09 15:08:12 +00006885
Douglas Gregorb98b1992009-08-11 05:31:07 +00006886template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006887ExprResult TreeTransform<Derived>::
6888TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6889 // Just rebuild the common and RHS expressions and see whether we
6890 // get any changes.
6891
6892 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6893 if (commonExpr.isInvalid())
6894 return ExprError();
6895
6896 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6897 if (rhs.isInvalid())
6898 return ExprError();
6899
6900 if (!getDerived().AlwaysRebuild() &&
6901 commonExpr.get() == e->getCommon() &&
6902 rhs.get() == e->getFalseExpr())
6903 return SemaRef.Owned(e);
6904
6905 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6906 e->getQuestionLoc(),
6907 0,
6908 e->getColonLoc(),
6909 rhs.get());
6910}
6911
6912template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006913ExprResult
John McCall454feb92009-12-08 09:21:05 +00006914TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006915 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006916 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006917 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006918
John McCall60d7b3a2010-08-24 06:29:42 +00006919 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006920 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006921 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006922
John McCall60d7b3a2010-08-24 06:29:42 +00006923 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006924 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006925 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006926
Douglas Gregorb98b1992009-08-11 05:31:07 +00006927 if (!getDerived().AlwaysRebuild() &&
6928 Cond.get() == E->getCond() &&
6929 LHS.get() == E->getLHS() &&
6930 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006931 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006932
John McCall9ae2f072010-08-23 23:25:46 +00006933 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006934 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006935 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006936 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006937 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006938}
Mike Stump1eb44332009-09-09 15:08:12 +00006939
6940template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006941ExprResult
John McCall454feb92009-12-08 09:21:05 +00006942TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006943 // Implicit casts are eliminated during transformation, since they
6944 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006945 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006946}
Mike Stump1eb44332009-09-09 15:08:12 +00006947
Douglas Gregorb98b1992009-08-11 05:31:07 +00006948template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006949ExprResult
John McCall454feb92009-12-08 09:21:05 +00006950TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006951 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6952 if (!Type)
6953 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006954
John McCall60d7b3a2010-08-24 06:29:42 +00006955 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006956 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006957 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006958 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006959
Douglas Gregorb98b1992009-08-11 05:31:07 +00006960 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006961 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006962 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006963 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006964
John McCall9d125032010-01-15 18:39:57 +00006965 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006966 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006967 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006968 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006969}
Mike Stump1eb44332009-09-09 15:08:12 +00006970
Douglas Gregorb98b1992009-08-11 05:31:07 +00006971template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006972ExprResult
John McCall454feb92009-12-08 09:21:05 +00006973TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006974 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6975 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6976 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006977 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006978
John McCall60d7b3a2010-08-24 06:29:42 +00006979 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006980 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006981 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006982
Douglas Gregorb98b1992009-08-11 05:31:07 +00006983 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006984 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006985 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006986 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006987
John McCall1d7d8d62010-01-19 22:33:45 +00006988 // Note: the expression type doesn't necessarily match the
6989 // type-as-written, but that's okay, because it should always be
6990 // derivable from the initializer.
6991
John McCall42f56b52010-01-18 19:35:47 +00006992 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006993 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006994 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006995}
Mike Stump1eb44332009-09-09 15:08:12 +00006996
Douglas Gregorb98b1992009-08-11 05:31:07 +00006997template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006998ExprResult
John McCall454feb92009-12-08 09:21:05 +00006999TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007000 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007001 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007002 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007003
Douglas Gregorb98b1992009-08-11 05:31:07 +00007004 if (!getDerived().AlwaysRebuild() &&
7005 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007006 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007007
Douglas Gregorb98b1992009-08-11 05:31:07 +00007008 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00007009 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007010 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00007011 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007012 E->getAccessorLoc(),
7013 E->getAccessor());
7014}
Mike Stump1eb44332009-09-09 15:08:12 +00007015
Douglas Gregorb98b1992009-08-11 05:31:07 +00007016template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007017ExprResult
John McCall454feb92009-12-08 09:21:05 +00007018TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007019 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00007020
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007021 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007022 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007023 Inits, &InitChanged))
7024 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007025
Douglas Gregorb98b1992009-08-11 05:31:07 +00007026 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007027 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007028
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007029 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00007030 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007031}
Mike Stump1eb44332009-09-09 15:08:12 +00007032
Douglas Gregorb98b1992009-08-11 05:31:07 +00007033template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007034ExprResult
John McCall454feb92009-12-08 09:21:05 +00007035TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007036 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00007037
Douglas Gregor43959a92009-08-20 07:17:43 +00007038 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00007039 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007040 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007041 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007042
Douglas Gregor43959a92009-08-20 07:17:43 +00007043 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007044 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007045 bool ExprChanged = false;
7046 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7047 DEnd = E->designators_end();
7048 D != DEnd; ++D) {
7049 if (D->isFieldDesignator()) {
7050 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7051 D->getDotLoc(),
7052 D->getFieldLoc()));
7053 continue;
7054 }
Mike Stump1eb44332009-09-09 15:08:12 +00007055
Douglas Gregorb98b1992009-08-11 05:31:07 +00007056 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00007057 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007058 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007059 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007060
7061 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007062 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00007063
Douglas Gregorb98b1992009-08-11 05:31:07 +00007064 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7065 ArrayExprs.push_back(Index.release());
7066 continue;
7067 }
Mike Stump1eb44332009-09-09 15:08:12 +00007068
Douglas Gregorb98b1992009-08-11 05:31:07 +00007069 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00007070 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00007071 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7072 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007073 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007074
John McCall60d7b3a2010-08-24 06:29:42 +00007075 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007076 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007077 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007078
7079 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007080 End.get(),
7081 D->getLBracketLoc(),
7082 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00007083
Douglas Gregorb98b1992009-08-11 05:31:07 +00007084 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7085 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00007086
Douglas Gregorb98b1992009-08-11 05:31:07 +00007087 ArrayExprs.push_back(Start.release());
7088 ArrayExprs.push_back(End.release());
7089 }
Mike Stump1eb44332009-09-09 15:08:12 +00007090
Douglas Gregorb98b1992009-08-11 05:31:07 +00007091 if (!getDerived().AlwaysRebuild() &&
7092 Init.get() == E->getInit() &&
7093 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007094 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007095
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007096 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007097 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007098 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007099}
Mike Stump1eb44332009-09-09 15:08:12 +00007100
Douglas Gregorb98b1992009-08-11 05:31:07 +00007101template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007102ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007103TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00007104 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00007105 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007106
Douglas Gregor5557b252009-10-28 00:29:27 +00007107 // FIXME: Will we ever have proper type location here? Will we actually
7108 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00007109 QualType T = getDerived().TransformType(E->getType());
7110 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007111 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007112
Douglas Gregorb98b1992009-08-11 05:31:07 +00007113 if (!getDerived().AlwaysRebuild() &&
7114 T == E->getType())
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().RebuildImplicitValueInitExpr(T);
7118}
Mike Stump1eb44332009-09-09 15:08:12 +00007119
Douglas Gregorb98b1992009-08-11 05:31:07 +00007120template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007121ExprResult
John McCall454feb92009-12-08 09:21:05 +00007122TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00007123 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7124 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007125 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007126
John McCall60d7b3a2010-08-24 06:29:42 +00007127 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007128 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007129 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007130
Douglas Gregorb98b1992009-08-11 05:31:07 +00007131 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007132 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007133 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007134 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007135
John McCall9ae2f072010-08-23 23:25:46 +00007136 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007137 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007138}
7139
7140template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007141ExprResult
John McCall454feb92009-12-08 09:21:05 +00007142TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007143 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007144 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00007145 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7146 &ArgumentChanged))
7147 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007148
Douglas Gregorb98b1992009-08-11 05:31:07 +00007149 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007150 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007151 E->getRParenLoc());
7152}
Mike Stump1eb44332009-09-09 15:08:12 +00007153
Douglas Gregorb98b1992009-08-11 05:31:07 +00007154/// \brief Transform an address-of-label expression.
7155///
7156/// By default, the transformation of an address-of-label expression always
7157/// rebuilds the expression, so that the label identifier can be resolved to
7158/// the corresponding label statement by semantic analysis.
7159template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007160ExprResult
John McCall454feb92009-12-08 09:21:05 +00007161TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00007162 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7163 E->getLabel());
7164 if (!LD)
7165 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007166
Douglas Gregorb98b1992009-08-11 05:31:07 +00007167 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00007168 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007169}
Mike Stump1eb44332009-09-09 15:08:12 +00007170
7171template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00007172ExprResult
John McCall454feb92009-12-08 09:21:05 +00007173TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00007174 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00007175 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00007176 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00007177 if (SubStmt.isInvalid()) {
7178 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00007179 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00007180 }
Mike Stump1eb44332009-09-09 15:08:12 +00007181
Douglas Gregorb98b1992009-08-11 05:31:07 +00007182 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00007183 SubStmt.get() == E->getSubStmt()) {
7184 // Calling this an 'error' is unintuitive, but it does the right thing.
7185 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00007186 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00007187 }
Mike Stump1eb44332009-09-09 15:08:12 +00007188
7189 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007190 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007191 E->getRParenLoc());
7192}
Mike Stump1eb44332009-09-09 15:08:12 +00007193
Douglas Gregorb98b1992009-08-11 05:31:07 +00007194template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007195ExprResult
John McCall454feb92009-12-08 09:21:05 +00007196TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007197 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007198 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007199 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007200
John McCall60d7b3a2010-08-24 06:29:42 +00007201 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007202 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007203 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007204
John McCall60d7b3a2010-08-24 06:29:42 +00007205 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007206 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007207 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007208
Douglas Gregorb98b1992009-08-11 05:31:07 +00007209 if (!getDerived().AlwaysRebuild() &&
7210 Cond.get() == E->getCond() &&
7211 LHS.get() == E->getLHS() &&
7212 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00007213 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007214
Douglas Gregorb98b1992009-08-11 05:31:07 +00007215 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007216 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007217 E->getRParenLoc());
7218}
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
John McCall454feb92009-12-08 09:21:05 +00007222TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007223 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007224}
7225
7226template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007227ExprResult
John McCall454feb92009-12-08 09:21:05 +00007228TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00007229 switch (E->getOperator()) {
7230 case OO_New:
7231 case OO_Delete:
7232 case OO_Array_New:
7233 case OO_Array_Delete:
7234 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00007235
Douglas Gregor668d6d92009-12-13 20:44:55 +00007236 case OO_Call: {
7237 // This is a call to an object's operator().
7238 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7239
7240 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00007241 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00007242 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007243 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007244
7245 // FIXME: Poor location information
7246 SourceLocation FakeLParenLoc
7247 = SemaRef.PP.getLocForEndOfToken(
7248 static_cast<Expr *>(Object.get())->getLocEnd());
7249
7250 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007251 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007252 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007253 Args))
7254 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007255
John McCall9ae2f072010-08-23 23:25:46 +00007256 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007257 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00007258 E->getLocEnd());
7259 }
7260
7261#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7262 case OO_##Name:
7263#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7264#include "clang/Basic/OperatorKinds.def"
7265 case OO_Subscript:
7266 // Handled below.
7267 break;
7268
7269 case OO_Conditional:
7270 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007271
7272 case OO_None:
7273 case NUM_OVERLOADED_OPERATORS:
7274 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007275 }
7276
John McCall60d7b3a2010-08-24 06:29:42 +00007277 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007278 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007279 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007280
Richard Smithefeeccf2012-10-21 03:28:35 +00007281 ExprResult First;
7282 if (E->getOperator() == OO_Amp)
7283 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7284 else
7285 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007286 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007287 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007288
John McCall60d7b3a2010-08-24 06:29:42 +00007289 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007290 if (E->getNumArgs() == 2) {
7291 Second = getDerived().TransformExpr(E->getArg(1));
7292 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007293 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007294 }
Mike Stump1eb44332009-09-09 15:08:12 +00007295
Douglas Gregorb98b1992009-08-11 05:31:07 +00007296 if (!getDerived().AlwaysRebuild() &&
7297 Callee.get() == E->getCallee() &&
7298 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00007299 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00007300 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007301
Lang Hamesbe9af122012-10-02 04:45:10 +00007302 Sema::FPContractStateRAII FPContractState(getSema());
7303 getSema().FPFeatures.fp_contract = E->isFPContractable();
7304
Douglas Gregorb98b1992009-08-11 05:31:07 +00007305 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7306 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007307 Callee.get(),
7308 First.get(),
7309 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007310}
Mike Stump1eb44332009-09-09 15:08:12 +00007311
Douglas Gregorb98b1992009-08-11 05:31:07 +00007312template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007313ExprResult
John McCall454feb92009-12-08 09:21:05 +00007314TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7315 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007316}
Mike Stump1eb44332009-09-09 15:08:12 +00007317
Douglas Gregorb98b1992009-08-11 05:31:07 +00007318template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007319ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00007320TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7321 // Transform the callee.
7322 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7323 if (Callee.isInvalid())
7324 return ExprError();
7325
7326 // Transform exec config.
7327 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7328 if (EC.isInvalid())
7329 return ExprError();
7330
7331 // Transform arguments.
7332 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007333 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007334 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007335 &ArgChanged))
7336 return ExprError();
7337
7338 if (!getDerived().AlwaysRebuild() &&
7339 Callee.get() == E->getCallee() &&
7340 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007341 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00007342
7343 // FIXME: Wrong source location information for the '('.
7344 SourceLocation FakeLParenLoc
7345 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7346 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007347 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007348 E->getRParenLoc(), EC.get());
7349}
7350
7351template<typename Derived>
7352ExprResult
John McCall454feb92009-12-08 09:21:05 +00007353TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007354 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7355 if (!Type)
7356 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007357
John McCall60d7b3a2010-08-24 06:29:42 +00007358 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007359 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007360 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007361 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007362
Douglas Gregorb98b1992009-08-11 05:31:07 +00007363 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007364 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007365 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007366 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007367 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007368 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007369 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007370 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007371 E->getAngleBrackets().getEnd(),
7372 // FIXME. this should be '(' location
7373 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007374 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007375 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007376}
Mike Stump1eb44332009-09-09 15:08:12 +00007377
Douglas Gregorb98b1992009-08-11 05:31:07 +00007378template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007379ExprResult
John McCall454feb92009-12-08 09:21:05 +00007380TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7381 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007382}
Mike Stump1eb44332009-09-09 15:08:12 +00007383
7384template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007385ExprResult
John McCall454feb92009-12-08 09:21:05 +00007386TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7387 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007388}
7389
Douglas Gregorb98b1992009-08-11 05:31:07 +00007390template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007391ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007392TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007393 CXXReinterpretCastExpr *E) {
7394 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007395}
Mike Stump1eb44332009-09-09 15:08:12 +00007396
Douglas Gregorb98b1992009-08-11 05:31:07 +00007397template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007398ExprResult
John McCall454feb92009-12-08 09:21:05 +00007399TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7400 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007401}
Mike Stump1eb44332009-09-09 15:08:12 +00007402
Douglas Gregorb98b1992009-08-11 05:31:07 +00007403template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007404ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007405TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007406 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007407 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7408 if (!Type)
7409 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007410
John McCall60d7b3a2010-08-24 06:29:42 +00007411 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007412 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007413 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007414 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007415
Douglas Gregorb98b1992009-08-11 05:31:07 +00007416 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007417 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007418 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007419 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007420
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007421 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedmancdd4b782013-08-15 22:02:56 +00007422 E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007423 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007424 E->getRParenLoc());
7425}
Mike Stump1eb44332009-09-09 15:08:12 +00007426
Douglas Gregorb98b1992009-08-11 05:31:07 +00007427template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007428ExprResult
John McCall454feb92009-12-08 09:21:05 +00007429TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007430 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007431 TypeSourceInfo *TInfo
7432 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7433 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007434 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007435
Douglas Gregorb98b1992009-08-11 05:31:07 +00007436 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007437 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007438 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007439
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007440 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7441 E->getLocStart(),
7442 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007443 E->getLocEnd());
7444 }
Mike Stump1eb44332009-09-09 15:08:12 +00007445
Eli Friedmanef331b72012-01-20 01:26:23 +00007446 // We don't know whether the subexpression is potentially evaluated until
7447 // after we perform semantic analysis. We speculatively assume it is
7448 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007449 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007450 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7451 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007452
John McCall60d7b3a2010-08-24 06:29:42 +00007453 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007454 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007455 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007456
Douglas Gregorb98b1992009-08-11 05:31:07 +00007457 if (!getDerived().AlwaysRebuild() &&
7458 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007459 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007460
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007461 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7462 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007463 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007464 E->getLocEnd());
7465}
7466
7467template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007468ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007469TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7470 if (E->isTypeOperand()) {
7471 TypeSourceInfo *TInfo
7472 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7473 if (!TInfo)
7474 return ExprError();
7475
7476 if (!getDerived().AlwaysRebuild() &&
7477 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007478 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007479
Douglas Gregor3c52a212011-03-06 17:40:41 +00007480 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007481 E->getLocStart(),
7482 TInfo,
7483 E->getLocEnd());
7484 }
7485
Francois Pichet01b7c302010-09-08 12:20:18 +00007486 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7487
7488 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7489 if (SubExpr.isInvalid())
7490 return ExprError();
7491
7492 if (!getDerived().AlwaysRebuild() &&
7493 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007494 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007495
7496 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7497 E->getLocStart(),
7498 SubExpr.get(),
7499 E->getLocEnd());
7500}
7501
7502template<typename Derived>
7503ExprResult
John McCall454feb92009-12-08 09:21:05 +00007504TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007505 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007506}
Mike Stump1eb44332009-09-09 15:08:12 +00007507
Douglas Gregorb98b1992009-08-11 05:31:07 +00007508template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007509ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007510TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007511 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007512 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007513}
Mike Stump1eb44332009-09-09 15:08:12 +00007514
Douglas Gregorb98b1992009-08-11 05:31:07 +00007515template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007516ExprResult
John McCall454feb92009-12-08 09:21:05 +00007517TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithcafeb942013-06-07 02:33:37 +00007518 QualType T = getSema().getCurrentThisType();
Mike Stump1eb44332009-09-09 15:08:12 +00007519
Douglas Gregorec79d872012-02-24 17:41:38 +00007520 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7521 // Make sure that we capture 'this'.
7522 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007523 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007524 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007525
Douglas Gregor828a1972010-01-07 23:12:05 +00007526 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007527}
Mike Stump1eb44332009-09-09 15:08:12 +00007528
Douglas Gregorb98b1992009-08-11 05:31:07 +00007529template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007530ExprResult
John McCall454feb92009-12-08 09:21:05 +00007531TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007532 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007533 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007534 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007535
Douglas Gregorb98b1992009-08-11 05:31:07 +00007536 if (!getDerived().AlwaysRebuild() &&
7537 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007538 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007539
Douglas Gregorbca01b42011-07-06 22:04:06 +00007540 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7541 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007542}
Mike Stump1eb44332009-09-09 15:08:12 +00007543
Douglas Gregorb98b1992009-08-11 05:31:07 +00007544template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007545ExprResult
John McCall454feb92009-12-08 09:21:05 +00007546TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007547 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007548 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7549 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007550 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007551 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007552
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007553 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007554 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007555 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007556
Douglas Gregor036aed12009-12-23 23:03:06 +00007557 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007558}
Mike Stump1eb44332009-09-09 15:08:12 +00007559
Douglas Gregorb98b1992009-08-11 05:31:07 +00007560template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007561ExprResult
Richard Smithc3bf52c2013-04-20 22:23:05 +00007562TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7563 FieldDecl *Field
7564 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7565 E->getField()));
7566 if (!Field)
7567 return ExprError();
7568
7569 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7570 return SemaRef.Owned(E);
7571
7572 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7573}
7574
7575template<typename Derived>
7576ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007577TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7578 CXXScalarValueInitExpr *E) {
7579 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7580 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007581 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007582
Douglas Gregorb98b1992009-08-11 05:31:07 +00007583 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007584 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007585 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007586
Chad Rosier4a9d7952012-08-08 18:46:20 +00007587 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007588 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007589 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007590}
Mike Stump1eb44332009-09-09 15:08:12 +00007591
Douglas Gregorb98b1992009-08-11 05:31:07 +00007592template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007593ExprResult
John McCall454feb92009-12-08 09:21:05 +00007594TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007595 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007596 TypeSourceInfo *AllocTypeInfo
7597 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7598 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007599 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007600
Douglas Gregorb98b1992009-08-11 05:31:07 +00007601 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007602 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007603 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007604 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007605
Douglas Gregorb98b1992009-08-11 05:31:07 +00007606 // Transform the placement arguments (if any).
7607 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007608 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007609 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007610 E->getNumPlacementArgs(), true,
7611 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007612 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007613
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007614 // Transform the initializer (if any).
7615 Expr *OldInit = E->getInitializer();
7616 ExprResult NewInit;
7617 if (OldInit)
7618 NewInit = getDerived().TransformExpr(OldInit);
7619 if (NewInit.isInvalid())
7620 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007621
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007622 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007623 FunctionDecl *OperatorNew = 0;
7624 if (E->getOperatorNew()) {
7625 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007626 getDerived().TransformDecl(E->getLocStart(),
7627 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007628 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007629 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007630 }
7631
7632 FunctionDecl *OperatorDelete = 0;
7633 if (E->getOperatorDelete()) {
7634 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007635 getDerived().TransformDecl(E->getLocStart(),
7636 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007637 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007638 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007639 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007640
Douglas Gregorb98b1992009-08-11 05:31:07 +00007641 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007642 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007643 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007644 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007645 OperatorNew == E->getOperatorNew() &&
7646 OperatorDelete == E->getOperatorDelete() &&
7647 !ArgumentChanged) {
7648 // Mark any declarations we need as referenced.
7649 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007650 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007651 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007652 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007653 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007654
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007655 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007656 QualType ElementType
7657 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7658 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7659 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7660 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007661 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007662 }
7663 }
7664 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007665
John McCall3fa5cae2010-10-26 07:05:15 +00007666 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007667 }
Mike Stump1eb44332009-09-09 15:08:12 +00007668
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007669 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007670 if (!ArraySize.get()) {
7671 // If no array size was specified, but the new expression was
7672 // instantiated with an array type (e.g., "new T" where T is
7673 // instantiated with "int[4]"), extract the outer bound from the
7674 // array type as our array size. We do this with constant and
7675 // dependently-sized array types.
7676 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7677 if (!ArrayT) {
7678 // Do nothing
7679 } else if (const ConstantArrayType *ConsArrayT
7680 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007681 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007682 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007683 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007684 SemaRef.Context.getSizeType(),
7685 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007686 AllocType = ConsArrayT->getElementType();
7687 } else if (const DependentSizedArrayType *DepArrayT
7688 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7689 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007690 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007691 AllocType = DepArrayT->getElementType();
7692 }
7693 }
7694 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007695
Douglas Gregorb98b1992009-08-11 05:31:07 +00007696 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7697 E->isGlobalNew(),
7698 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007699 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007700 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007701 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007702 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007703 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007704 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007705 E->getDirectInitRange(),
7706 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007707}
Mike Stump1eb44332009-09-09 15:08:12 +00007708
Douglas Gregorb98b1992009-08-11 05:31:07 +00007709template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007710ExprResult
John McCall454feb92009-12-08 09:21:05 +00007711TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007712 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007713 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007714 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007715
Douglas Gregor1af74512010-02-26 00:38:10 +00007716 // Transform the delete operator, if known.
7717 FunctionDecl *OperatorDelete = 0;
7718 if (E->getOperatorDelete()) {
7719 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007720 getDerived().TransformDecl(E->getLocStart(),
7721 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007722 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007723 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007724 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007725
Douglas Gregorb98b1992009-08-11 05:31:07 +00007726 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007727 Operand.get() == E->getArgument() &&
7728 OperatorDelete == E->getOperatorDelete()) {
7729 // Mark any declarations we need as referenced.
7730 // FIXME: instantiation-specific.
7731 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007732 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007733
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007734 if (!E->getArgument()->isTypeDependent()) {
7735 QualType Destroyed = SemaRef.Context.getBaseElementType(
7736 E->getDestroyedType());
7737 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7738 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007739 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007740 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007741 }
7742 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007743
John McCall3fa5cae2010-10-26 07:05:15 +00007744 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007745 }
Mike Stump1eb44332009-09-09 15:08:12 +00007746
Douglas Gregorb98b1992009-08-11 05:31:07 +00007747 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7748 E->isGlobalDelete(),
7749 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007750 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007751}
Mike Stump1eb44332009-09-09 15:08:12 +00007752
Douglas Gregorb98b1992009-08-11 05:31:07 +00007753template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007754ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007755TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007756 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007757 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007758 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007759 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007760
John McCallb3d87482010-08-24 05:47:05 +00007761 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007762 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007763 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007764 E->getOperatorLoc(),
7765 E->isArrow()? tok::arrow : tok::period,
7766 ObjectTypePtr,
7767 MayBePseudoDestructor);
7768 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007769 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007770
John McCallb3d87482010-08-24 05:47:05 +00007771 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007772 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7773 if (QualifierLoc) {
7774 QualifierLoc
7775 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7776 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007777 return ExprError();
7778 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007779 CXXScopeSpec SS;
7780 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007781
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007782 PseudoDestructorTypeStorage Destroyed;
7783 if (E->getDestroyedTypeInfo()) {
7784 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007785 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007786 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007787 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007788 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007789 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007790 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007791 // We aren't likely to be able to resolve the identifier down to a type
7792 // now anyway, so just retain the identifier.
7793 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7794 E->getDestroyedTypeLoc());
7795 } else {
7796 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007797 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007798 *E->getDestroyedTypeIdentifier(),
7799 E->getDestroyedTypeLoc(),
7800 /*Scope=*/0,
7801 SS, ObjectTypePtr,
7802 false);
7803 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007804 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007805
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007806 Destroyed
7807 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7808 E->getDestroyedTypeLoc());
7809 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007810
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007811 TypeSourceInfo *ScopeTypeInfo = 0;
7812 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007813 CXXScopeSpec EmptySS;
7814 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7815 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007816 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007817 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007818 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007819
John McCall9ae2f072010-08-23 23:25:46 +00007820 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007821 E->getOperatorLoc(),
7822 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007823 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007824 ScopeTypeInfo,
7825 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007826 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007827 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007828}
Mike Stump1eb44332009-09-09 15:08:12 +00007829
Douglas Gregora71d8192009-09-04 17:36:40 +00007830template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007831ExprResult
John McCallba135432009-11-21 08:51:07 +00007832TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007833 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007834 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7835 Sema::LookupOrdinaryName);
7836
7837 // Transform all the decls.
7838 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7839 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007840 NamedDecl *InstD = static_cast<NamedDecl*>(
7841 getDerived().TransformDecl(Old->getNameLoc(),
7842 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007843 if (!InstD) {
7844 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7845 // This can happen because of dependent hiding.
7846 if (isa<UsingShadowDecl>(*I))
7847 continue;
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007848 else {
7849 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007850 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007851 }
John McCall9f54ad42009-12-10 09:41:52 +00007852 }
John McCallf7a1a742009-11-24 19:00:30 +00007853
7854 // Expand using declarations.
7855 if (isa<UsingDecl>(InstD)) {
7856 UsingDecl *UD = cast<UsingDecl>(InstD);
7857 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7858 E = UD->shadow_end(); I != E; ++I)
7859 R.addDecl(*I);
7860 continue;
7861 }
7862
7863 R.addDecl(InstD);
7864 }
7865
7866 // Resolve a kind, but don't do any further analysis. If it's
7867 // ambiguous, the callee needs to deal with it.
7868 R.resolveKind();
7869
7870 // Rebuild the nested-name qualifier, if present.
7871 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007872 if (Old->getQualifierLoc()) {
7873 NestedNameSpecifierLoc QualifierLoc
7874 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7875 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007876 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007877
Douglas Gregor4c9be892011-02-28 20:01:57 +00007878 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007879 }
7880
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007881 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007882 CXXRecordDecl *NamingClass
7883 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7884 Old->getNameLoc(),
7885 Old->getNamingClass()));
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007886 if (!NamingClass) {
7887 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007888 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007889 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007890
Douglas Gregor66c45152010-04-27 16:10:10 +00007891 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007892 }
7893
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007894 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7895
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007896 // If we have neither explicit template arguments, nor the template keyword,
7897 // it's a normal declaration name.
7898 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007899 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7900
7901 // If we have template arguments, rebuild them, then rebuild the
7902 // templateid expression.
7903 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007904 if (Old->hasExplicitTemplateArgs() &&
7905 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007906 Old->getNumTemplateArgs(),
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007907 TransArgs)) {
7908 R.clear();
Douglas Gregorfcc12532010-12-20 17:31:10 +00007909 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007910 }
John McCallf7a1a742009-11-24 19:00:30 +00007911
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007912 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007913 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007914}
Mike Stump1eb44332009-09-09 15:08:12 +00007915
Douglas Gregorb98b1992009-08-11 05:31:07 +00007916template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007917ExprResult
John McCall454feb92009-12-08 09:21:05 +00007918TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007919 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7920 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007921 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007922
Douglas Gregorb98b1992009-08-11 05:31:07 +00007923 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007924 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007925 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007926
Mike Stump1eb44332009-09-09 15:08:12 +00007927 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007928 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007929 T,
7930 E->getLocEnd());
7931}
Mike Stump1eb44332009-09-09 15:08:12 +00007932
Douglas Gregorb98b1992009-08-11 05:31:07 +00007933template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007934ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007935TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7936 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7937 if (!LhsT)
7938 return ExprError();
7939
7940 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7941 if (!RhsT)
7942 return ExprError();
7943
7944 if (!getDerived().AlwaysRebuild() &&
7945 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7946 return SemaRef.Owned(E);
7947
7948 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7949 E->getLocStart(),
7950 LhsT, RhsT,
7951 E->getLocEnd());
7952}
7953
7954template<typename Derived>
7955ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007956TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7957 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007958 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007959 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7960 TypeSourceInfo *From = E->getArg(I);
7961 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007962 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007963 TypeLocBuilder TLB;
7964 TLB.reserve(FromTL.getFullDataSize());
7965 QualType To = getDerived().TransformType(TLB, FromTL);
7966 if (To.isNull())
7967 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007968
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007969 if (To == From->getType())
7970 Args.push_back(From);
7971 else {
7972 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7973 ArgChanged = true;
7974 }
7975 continue;
7976 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007977
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007978 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007979
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007980 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007981 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007982 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7983 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7984 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007985
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007986 // Determine whether the set of unexpanded parameter packs can and should
7987 // be expanded.
7988 bool Expand = true;
7989 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007990 Optional<unsigned> OrigNumExpansions =
7991 ExpansionTL.getTypePtr()->getNumExpansions();
7992 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007993 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7994 PatternTL.getSourceRange(),
7995 Unexpanded,
7996 Expand, RetainExpansion,
7997 NumExpansions))
7998 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007999
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008000 if (!Expand) {
8001 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008002 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008003 // expansion.
8004 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008005
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008006 TypeLocBuilder TLB;
8007 TLB.reserve(From->getTypeLoc().getFullDataSize());
8008
8009 QualType To = getDerived().TransformType(TLB, PatternTL);
8010 if (To.isNull())
8011 return ExprError();
8012
Chad Rosier4a9d7952012-08-08 18:46:20 +00008013 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008014 PatternTL.getSourceRange(),
8015 ExpansionTL.getEllipsisLoc(),
8016 NumExpansions);
8017 if (To.isNull())
8018 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008019
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008020 PackExpansionTypeLoc ToExpansionTL
8021 = TLB.push<PackExpansionTypeLoc>(To);
8022 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8023 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8024 continue;
8025 }
8026
8027 // Expand the pack expansion by substituting for each argument in the
8028 // pack(s).
8029 for (unsigned I = 0; I != *NumExpansions; ++I) {
8030 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8031 TypeLocBuilder TLB;
8032 TLB.reserve(PatternTL.getFullDataSize());
8033 QualType To = getDerived().TransformType(TLB, PatternTL);
8034 if (To.isNull())
8035 return ExprError();
8036
Eli Friedman20cfeca2013-07-19 21:49:32 +00008037 if (To->containsUnexpandedParameterPack()) {
8038 To = getDerived().RebuildPackExpansionType(To,
8039 PatternTL.getSourceRange(),
8040 ExpansionTL.getEllipsisLoc(),
8041 NumExpansions);
8042 if (To.isNull())
8043 return ExprError();
8044
8045 PackExpansionTypeLoc ToExpansionTL
8046 = TLB.push<PackExpansionTypeLoc>(To);
8047 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8048 }
8049
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008050 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8051 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008052
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008053 if (!RetainExpansion)
8054 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008055
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008056 // If we're supposed to retain a pack expansion, do so by temporarily
8057 // forgetting the partially-substituted parameter pack.
8058 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8059
8060 TypeLocBuilder TLB;
8061 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008062
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008063 QualType To = getDerived().TransformType(TLB, PatternTL);
8064 if (To.isNull())
8065 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008066
8067 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008068 PatternTL.getSourceRange(),
8069 ExpansionTL.getEllipsisLoc(),
8070 NumExpansions);
8071 if (To.isNull())
8072 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008073
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008074 PackExpansionTypeLoc ToExpansionTL
8075 = TLB.push<PackExpansionTypeLoc>(To);
8076 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8077 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8078 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008079
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008080 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8081 return SemaRef.Owned(E);
8082
8083 return getDerived().RebuildTypeTrait(E->getTrait(),
8084 E->getLocStart(),
8085 Args,
8086 E->getLocEnd());
8087}
8088
8089template<typename Derived>
8090ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00008091TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8092 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8093 if (!T)
8094 return ExprError();
8095
8096 if (!getDerived().AlwaysRebuild() &&
8097 T == E->getQueriedTypeSourceInfo())
8098 return SemaRef.Owned(E);
8099
8100 ExprResult SubExpr;
8101 {
8102 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8103 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8104 if (SubExpr.isInvalid())
8105 return ExprError();
8106
8107 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8108 return SemaRef.Owned(E);
8109 }
8110
8111 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8112 E->getLocStart(),
8113 T,
8114 SubExpr.get(),
8115 E->getLocEnd());
8116}
8117
8118template<typename Derived>
8119ExprResult
John Wiegley55262202011-04-25 06:54:41 +00008120TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8121 ExprResult SubExpr;
8122 {
8123 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8124 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8125 if (SubExpr.isInvalid())
8126 return ExprError();
8127
8128 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8129 return SemaRef.Owned(E);
8130 }
8131
8132 return getDerived().RebuildExpressionTrait(
8133 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8134}
8135
8136template<typename Derived>
8137ExprResult
John McCall865d4472009-11-19 22:55:06 +00008138TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008139 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00008140 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8141}
8142
8143template<typename Derived>
8144ExprResult
8145TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8146 DependentScopeDeclRefExpr *E,
8147 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008148 NestedNameSpecifierLoc QualifierLoc
8149 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8150 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008151 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008152 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00008153
John McCall43fed0d2010-11-12 08:19:04 +00008154 // TODO: If this is a conversion-function-id, verify that the
8155 // destination type name (if present) resolves the same way after
8156 // instantiation as it did in the local scope.
8157
Abramo Bagnara25777432010-08-11 22:01:17 +00008158 DeclarationNameInfo NameInfo
8159 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8160 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008161 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008162
John McCallf7a1a742009-11-24 19:00:30 +00008163 if (!E->hasExplicitTemplateArgs()) {
8164 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008165 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008166 // Note: it is sufficient to compare the Name component of NameInfo:
8167 // if name has not changed, DNLoc has not changed either.
8168 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00008169 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008170
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008171 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008172 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008173 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008174 /*TemplateArgs*/ 0,
8175 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00008176 }
John McCalld5532b62009-11-23 01:53:49 +00008177
8178 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008179 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8180 E->getNumTemplateArgs(),
8181 TransArgs))
8182 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008183
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008184 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008185 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008186 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008187 &TransArgs,
8188 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008189}
8190
8191template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008192ExprResult
John McCall454feb92009-12-08 09:21:05 +00008193TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00008194 // CXXConstructExprs other than for list-initialization and
8195 // CXXTemporaryObjectExpr are always implicit, so when we have
8196 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00008197 if ((E->getNumArgs() == 1 ||
8198 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00008199 (!getDerived().DropCallArgument(E->getArg(0))) &&
8200 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00008201 return getDerived().TransformExpr(E->getArg(0));
8202
Douglas Gregorb98b1992009-08-11 05:31:07 +00008203 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8204
8205 QualType T = getDerived().TransformType(E->getType());
8206 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00008207 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008208
8209 CXXConstructorDecl *Constructor
8210 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008211 getDerived().TransformDecl(E->getLocStart(),
8212 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008213 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008214 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008215
Douglas Gregorb98b1992009-08-11 05:31:07 +00008216 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008217 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008218 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008219 &ArgumentChanged))
8220 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008221
Douglas Gregorb98b1992009-08-11 05:31:07 +00008222 if (!getDerived().AlwaysRebuild() &&
8223 T == E->getType() &&
8224 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00008225 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00008226 // Mark the constructor as referenced.
8227 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008228 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008229 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00008230 }
Mike Stump1eb44332009-09-09 15:08:12 +00008231
Douglas Gregor4411d2e2009-12-14 16:27:04 +00008232 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8233 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008234 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00008235 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00008236 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00008237 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00008238 E->getConstructionKind(),
Enea Zaffanella1245a542013-09-07 05:49:53 +00008239 E->getParenOrBraceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008240}
Mike Stump1eb44332009-09-09 15:08:12 +00008241
Douglas Gregorb98b1992009-08-11 05:31:07 +00008242/// \brief Transform a C++ temporary-binding expression.
8243///
Douglas Gregor51326552009-12-24 18:51:59 +00008244/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8245/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008246template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008247ExprResult
John McCall454feb92009-12-08 09:21:05 +00008248TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008249 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008250}
Mike Stump1eb44332009-09-09 15:08:12 +00008251
John McCall4765fa02010-12-06 08:20:24 +00008252/// \brief Transform a C++ expression that contains cleanups that should
8253/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008254///
John McCall4765fa02010-12-06 08:20:24 +00008255/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00008256/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008257template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008258ExprResult
John McCall4765fa02010-12-06 08:20:24 +00008259TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008260 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008261}
Mike Stump1eb44332009-09-09 15:08:12 +00008262
Douglas Gregorb98b1992009-08-11 05:31:07 +00008263template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008264ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008265TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00008266 CXXTemporaryObjectExpr *E) {
8267 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8268 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008269 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008270
Douglas Gregorb98b1992009-08-11 05:31:07 +00008271 CXXConstructorDecl *Constructor
8272 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008273 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008274 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008275 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008276 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008277
Douglas Gregorb98b1992009-08-11 05:31:07 +00008278 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008279 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00008280 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008281 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008282 &ArgumentChanged))
8283 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008284
Douglas Gregorb98b1992009-08-11 05:31:07 +00008285 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008286 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008287 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00008288 !ArgumentChanged) {
8289 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008290 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008291 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00008292 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008293
Richard Smithc83c2302012-12-19 01:39:02 +00008294 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00008295 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8296 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008297 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008298 E->getLocEnd());
8299}
Mike Stump1eb44332009-09-09 15:08:12 +00008300
Douglas Gregorb98b1992009-08-11 05:31:07 +00008301template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008302ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00008303TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Valifad9e132013-09-26 19:54:12 +00008304
Faisal Valiaecbb9d2013-10-03 05:32:48 +00008305 getSema().PushLambdaScope();
8306 LambdaScopeInfo *LSI = getSema().getCurLambda();
8307 TemplateParameterList *const OrigTPL = E->getTemplateParameterList();
8308 TemplateParameterList *NewTPL = 0;
8309 // Transform the template parameters, and add them to the
8310 // current instantiation scope.
8311 if (OrigTPL) {
8312 NewTPL = getDerived().TransformTemplateParameterList(OrigTPL);
Faisal Valifad9e132013-09-26 19:54:12 +00008313 }
Faisal Valiaecbb9d2013-10-03 05:32:48 +00008314 LSI->GLTemplateParameterList = NewTPL;
8315 // Transform the type of the lambda parameters and start the definition of
8316 // the lambda itself.
8317 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
8318 TypeSourceInfo *NewCallOpTSI = TransformType(OldCallOpTSI);
8319 if (!NewCallOpTSI)
Douglas Gregordfca6f52012-02-13 22:00:16 +00008320 return ExprError();
8321
Eli Friedman8da8a662012-09-19 01:18:11 +00008322 // Create the local class that will describe the lambda.
8323 CXXRecordDecl *Class
8324 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Valiaecbb9d2013-10-03 05:32:48 +00008325 NewCallOpTSI,
Eli Friedman8da8a662012-09-19 01:18:11 +00008326 /*KnownDependent=*/false);
8327 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8328
Douglas Gregorc6889e72012-02-14 22:28:59 +00008329 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008330 SmallVector<QualType, 4> ParamTypes;
8331 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00008332 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
8333 E->getCallOperator()->param_begin(),
8334 E->getCallOperator()->param_size(),
8335 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00008336 return ExprError();
Faisal Valiaecbb9d2013-10-03 05:32:48 +00008337
Douglas Gregordfca6f52012-02-13 22:00:16 +00008338 // Build the call operator.
Faisal Valiaecbb9d2013-10-03 05:32:48 +00008339 CXXMethodDecl *NewCallOperator
Douglas Gregordfca6f52012-02-13 22:00:16 +00008340 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Faisal Valiaecbb9d2013-10-03 05:32:48 +00008341 NewCallOpTSI,
Douglas Gregorc6889e72012-02-14 22:28:59 +00008342 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008343 Params);
Faisal Valiaecbb9d2013-10-03 05:32:48 +00008344 LSI->CallOperator = NewCallOperator;
8345 // Fix the Decl Contexts of the parameters within the call op function
8346 // prototype.
8347 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
8348
8349 TypeLoc NewCallOpTL = NewCallOpTSI->getTypeLoc();
8350 FunctionProtoTypeLoc NewFPTL = NewCallOpTL.castAs<FunctionProtoTypeLoc>();
8351 ParmVarDecl **NewParamDeclArray = NewFPTL.getParmArray();
8352 const unsigned NewNumArgs = NewFPTL.getNumArgs();
8353 for (unsigned I = 0; I < NewNumArgs; ++I) {
8354 NewParamDeclArray[I]->setOwningFunction(NewCallOperator);
8355 }
8356 // If this is a non-generic lambda, the parameters do not get added to the
8357 // current instantiation scope, so add them. This feels kludgey.
8358 // Anyway, it allows the following to compile when the enclosing template
8359 // is specialized and the entire lambda expression has to be
8360 // transformed. Without this FindInstantiatedDecl causes an assertion.
8361 // template<class T> void foo(T t) {
8362 // auto L = [](auto a) {
8363 // auto M = [](char b) { <-- note: non-generic lambda
8364 // auto N = [](auto c) {
8365 // int x = sizeof(a);
8366 // x = sizeof(b); <-- specifically this line
8367 // x = sizeof(c);
8368 // };
8369 // };
8370 // };
8371 // }
8372 // foo('a');
8373 //
8374 if (!E->isGenericLambda()) {
8375 for (unsigned I = 0; I < NewNumArgs; ++I)
8376 SemaRef.CurrentInstantiationScope->InstantiatedLocal(
8377 NewParamDeclArray[I], NewParamDeclArray[I]);
8378 }
8379 return getDerived().TransformLambdaScope(E, NewCallOperator);
Richard Smith612409e2012-07-25 03:56:55 +00008380}
8381
8382template<typename Derived>
8383ExprResult
8384TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8385 CXXMethodDecl *CallOperator) {
Richard Smith0d8e9642013-05-16 06:20:58 +00008386 bool Invalid = false;
8387
8388 // Transform any init-capture expressions before entering the scope of the
8389 // lambda.
Robert Wilhelme7205c02013-08-10 12:33:24 +00008390 SmallVector<ExprResult, 8> InitCaptureExprs;
Richard Smith0d8e9642013-05-16 06:20:58 +00008391 InitCaptureExprs.resize(E->explicit_capture_end() -
8392 E->explicit_capture_begin());
8393 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8394 CEnd = E->capture_end();
8395 C != CEnd; ++C) {
8396 if (!C->isInitCapture())
8397 continue;
8398 InitCaptureExprs[C - E->capture_begin()] =
Richard Smith04fa7a32013-09-28 04:02:39 +00008399 getDerived().TransformInitializer(
8400 C->getCapturedVar()->getInit(),
8401 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith0d8e9642013-05-16 06:20:58 +00008402 }
8403
Douglas Gregord5387e82012-02-14 00:00:48 +00008404 // Introduce the context of the call operator.
8405 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8406
Faisal Valifad9e132013-09-26 19:54:12 +00008407 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregordfca6f52012-02-13 22:00:16 +00008408 // Enter the scope of the lambda.
Faisal Valifad9e132013-09-26 19:54:12 +00008409 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008410 E->getCaptureDefault(),
James Dennettf68af642013-08-09 23:08:25 +00008411 E->getCaptureDefaultLoc(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008412 E->hasExplicitParameters(),
8413 E->hasExplicitResultType(),
8414 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008415
Douglas Gregordfca6f52012-02-13 22:00:16 +00008416 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00008417 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008418 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008419 CEnd = E->capture_end();
8420 C != CEnd; ++C) {
8421 // When we hit the first implicit capture, tell Sema that we've finished
8422 // the list of explicit captures.
8423 if (!FinishedExplicitCaptures && C->isImplicit()) {
8424 getSema().finishLambdaExplicitCaptures(LSI);
8425 FinishedExplicitCaptures = true;
8426 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008427
Douglas Gregordfca6f52012-02-13 22:00:16 +00008428 // Capturing 'this' is trivial.
8429 if (C->capturesThis()) {
8430 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8431 continue;
8432 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008433
Richard Smith0d8e9642013-05-16 06:20:58 +00008434 // Rebuild init-captures, including the implied field declaration.
8435 if (C->isInitCapture()) {
8436 ExprResult Init = InitCaptureExprs[C - E->capture_begin()];
8437 if (Init.isInvalid()) {
8438 Invalid = true;
8439 continue;
8440 }
Richard Smith04fa7a32013-09-28 04:02:39 +00008441 VarDecl *OldVD = C->getCapturedVar();
8442 VarDecl *NewVD = getSema().checkInitCapture(
8443 C->getLocation(), OldVD->getType()->isReferenceType(),
8444 OldVD->getIdentifier(), Init.take());
8445 if (!NewVD)
Richard Smith0d8e9642013-05-16 06:20:58 +00008446 Invalid = true;
8447 else
Richard Smith04fa7a32013-09-28 04:02:39 +00008448 getDerived().transformedLocalDecl(OldVD, NewVD);
8449 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smith0d8e9642013-05-16 06:20:58 +00008450 continue;
8451 }
8452
8453 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8454
Douglas Gregora7365242012-02-14 19:27:52 +00008455 // Determine the capture kind for Sema.
8456 Sema::TryCaptureKind Kind
8457 = C->isImplicit()? Sema::TryCapture_Implicit
8458 : C->getCaptureKind() == LCK_ByCopy
8459 ? Sema::TryCapture_ExplicitByVal
8460 : Sema::TryCapture_ExplicitByRef;
8461 SourceLocation EllipsisLoc;
8462 if (C->isPackExpansion()) {
8463 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8464 bool ShouldExpand = false;
8465 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008466 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008467 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8468 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008469 Unexpanded,
8470 ShouldExpand, RetainExpansion,
Richard Smith0d8e9642013-05-16 06:20:58 +00008471 NumExpansions)) {
8472 Invalid = true;
8473 continue;
8474 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008475
Douglas Gregora7365242012-02-14 19:27:52 +00008476 if (ShouldExpand) {
8477 // The transform has determined that we should perform an expansion;
8478 // transform and capture each of the arguments.
8479 // expansion of the pattern. Do so.
8480 VarDecl *Pack = C->getCapturedVar();
8481 for (unsigned I = 0; I != *NumExpansions; ++I) {
8482 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8483 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008484 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008485 Pack));
8486 if (!CapturedVar) {
8487 Invalid = true;
8488 continue;
8489 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008490
Douglas Gregora7365242012-02-14 19:27:52 +00008491 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008492 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8493 }
Douglas Gregora7365242012-02-14 19:27:52 +00008494 continue;
8495 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008496
Douglas Gregora7365242012-02-14 19:27:52 +00008497 EllipsisLoc = C->getEllipsisLoc();
8498 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008499
Douglas Gregordfca6f52012-02-13 22:00:16 +00008500 // Transform the captured variable.
8501 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008502 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008503 C->getCapturedVar()));
8504 if (!CapturedVar) {
8505 Invalid = true;
8506 continue;
8507 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008508
Douglas Gregordfca6f52012-02-13 22:00:16 +00008509 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008510 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008511 }
8512 if (!FinishedExplicitCaptures)
8513 getSema().finishLambdaExplicitCaptures(LSI);
8514
Douglas Gregordfca6f52012-02-13 22:00:16 +00008515
8516 // Enter a new evaluation context to insulate the lambda from any
8517 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008518 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008519
8520 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008521 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008522 /*IsInstantiation=*/true);
8523 return ExprError();
8524 }
8525
8526 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008527 StmtResult Body = getDerived().TransformStmt(E->getBody());
8528 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008529 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008530 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008531 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008532 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008533
Chad Rosier4a9d7952012-08-08 18:46:20 +00008534 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008535 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008536}
8537
8538template<typename Derived>
8539ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008540TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008541 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008542 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8543 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008544 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008545
Douglas Gregorb98b1992009-08-11 05:31:07 +00008546 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008547 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008548 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008549 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008550 &ArgumentChanged))
8551 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008552
Douglas Gregorb98b1992009-08-11 05:31:07 +00008553 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008554 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008555 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008556 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008557
Douglas Gregorb98b1992009-08-11 05:31:07 +00008558 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008559 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008560 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008561 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008562 E->getRParenLoc());
8563}
Mike Stump1eb44332009-09-09 15:08:12 +00008564
Douglas Gregorb98b1992009-08-11 05:31:07 +00008565template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008566ExprResult
John McCall865d4472009-11-19 22:55:06 +00008567TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008568 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008569 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008570 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008571 Expr *OldBase;
8572 QualType BaseType;
8573 QualType ObjectType;
8574 if (!E->isImplicitAccess()) {
8575 OldBase = E->getBase();
8576 Base = getDerived().TransformExpr(OldBase);
8577 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008578 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008579
John McCallaa81e162009-12-01 22:10:20 +00008580 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008581 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008582 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008583 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008584 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008585 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008586 ObjectTy,
8587 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008588 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008589 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008590
John McCallb3d87482010-08-24 05:47:05 +00008591 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008592 BaseType = ((Expr*) Base.get())->getType();
8593 } else {
8594 OldBase = 0;
8595 BaseType = getDerived().TransformType(E->getBaseType());
8596 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8597 }
Mike Stump1eb44332009-09-09 15:08:12 +00008598
Douglas Gregor6cd21982009-10-20 05:58:46 +00008599 // Transform the first part of the nested-name-specifier that qualifies
8600 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008601 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008602 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008603 E->getFirstQualifierFoundInScope(),
8604 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008605
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008606 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008607 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008608 QualifierLoc
8609 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8610 ObjectType,
8611 FirstQualifierInScope);
8612 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008613 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008614 }
Mike Stump1eb44332009-09-09 15:08:12 +00008615
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008616 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8617
John McCall43fed0d2010-11-12 08:19:04 +00008618 // TODO: If this is a conversion-function-id, verify that the
8619 // destination type name (if present) resolves the same way after
8620 // instantiation as it did in the local scope.
8621
Abramo Bagnara25777432010-08-11 22:01:17 +00008622 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008623 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008624 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008625 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008626
John McCallaa81e162009-12-01 22:10:20 +00008627 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008628 // This is a reference to a member without an explicitly-specified
8629 // template argument list. Optimize for this common case.
8630 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008631 Base.get() == OldBase &&
8632 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008633 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008634 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008635 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008636 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008637
John McCall9ae2f072010-08-23 23:25:46 +00008638 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008639 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008640 E->isArrow(),
8641 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008642 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008643 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008644 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008645 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008646 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008647 }
8648
John McCalld5532b62009-11-23 01:53:49 +00008649 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008650 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8651 E->getNumTemplateArgs(),
8652 TransArgs))
8653 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008654
John McCall9ae2f072010-08-23 23:25:46 +00008655 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008656 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008657 E->isArrow(),
8658 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008659 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008660 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008661 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008662 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008663 &TransArgs);
8664}
8665
8666template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008667ExprResult
John McCall454feb92009-12-08 09:21:05 +00008668TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008669 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008670 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008671 QualType BaseType;
8672 if (!Old->isImplicitAccess()) {
8673 Base = getDerived().TransformExpr(Old->getBase());
8674 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008675 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008676 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8677 Old->isArrow());
8678 if (Base.isInvalid())
8679 return ExprError();
8680 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008681 } else {
8682 BaseType = getDerived().TransformType(Old->getBaseType());
8683 }
John McCall129e2df2009-11-30 22:42:35 +00008684
Douglas Gregor4c9be892011-02-28 20:01:57 +00008685 NestedNameSpecifierLoc QualifierLoc;
8686 if (Old->getQualifierLoc()) {
8687 QualifierLoc
8688 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8689 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008690 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008691 }
8692
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008693 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8694
Abramo Bagnara25777432010-08-11 22:01:17 +00008695 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008696 Sema::LookupOrdinaryName);
8697
8698 // Transform all the decls.
8699 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8700 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008701 NamedDecl *InstD = static_cast<NamedDecl*>(
8702 getDerived().TransformDecl(Old->getMemberLoc(),
8703 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008704 if (!InstD) {
8705 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8706 // This can happen because of dependent hiding.
8707 if (isa<UsingShadowDecl>(*I))
8708 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008709 else {
8710 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008711 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008712 }
John McCall9f54ad42009-12-10 09:41:52 +00008713 }
John McCall129e2df2009-11-30 22:42:35 +00008714
8715 // Expand using declarations.
8716 if (isa<UsingDecl>(InstD)) {
8717 UsingDecl *UD = cast<UsingDecl>(InstD);
8718 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8719 E = UD->shadow_end(); I != E; ++I)
8720 R.addDecl(*I);
8721 continue;
8722 }
8723
8724 R.addDecl(InstD);
8725 }
8726
8727 R.resolveKind();
8728
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008729 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008730 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008731 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008732 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008733 Old->getMemberLoc(),
8734 Old->getNamingClass()));
8735 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008736 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008737
Douglas Gregor66c45152010-04-27 16:10:10 +00008738 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008739 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008740
John McCall129e2df2009-11-30 22:42:35 +00008741 TemplateArgumentListInfo TransArgs;
8742 if (Old->hasExplicitTemplateArgs()) {
8743 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8744 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008745 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8746 Old->getNumTemplateArgs(),
8747 TransArgs))
8748 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008749 }
John McCallc2233c52010-01-15 08:34:02 +00008750
8751 // FIXME: to do this check properly, we will need to preserve the
8752 // first-qualifier-in-scope here, just in case we had a dependent
8753 // base (and therefore couldn't do the check) and a
8754 // nested-name-qualifier (and therefore could do the lookup).
8755 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008756
John McCall9ae2f072010-08-23 23:25:46 +00008757 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008758 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008759 Old->getOperatorLoc(),
8760 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008761 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008762 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008763 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008764 R,
8765 (Old->hasExplicitTemplateArgs()
8766 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008767}
8768
8769template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008770ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008771TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008772 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008773 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8774 if (SubExpr.isInvalid())
8775 return ExprError();
8776
8777 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008778 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008779
8780 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8781}
8782
8783template<typename Derived>
8784ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008785TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008786 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8787 if (Pattern.isInvalid())
8788 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008789
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008790 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8791 return SemaRef.Owned(E);
8792
Douglas Gregor67fd1252011-01-14 21:20:45 +00008793 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8794 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008795}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008796
8797template<typename Derived>
8798ExprResult
8799TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8800 // If E is not value-dependent, then nothing will change when we transform it.
8801 // Note: This is an instantiation-centric view.
8802 if (!E->isValueDependent())
8803 return SemaRef.Owned(E);
8804
8805 // Note: None of the implementations of TryExpandParameterPacks can ever
8806 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008807 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008808 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8809 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008810 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008811 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008812 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008813 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008814 ShouldExpand, RetainExpansion,
8815 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008816 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008817
Douglas Gregor089e8932011-10-10 18:59:29 +00008818 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008819 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008820
Douglas Gregor089e8932011-10-10 18:59:29 +00008821 NamedDecl *Pack = E->getPack();
8822 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008823 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008824 Pack));
8825 if (!Pack)
8826 return ExprError();
8827 }
8828
Chad Rosier4a9d7952012-08-08 18:46:20 +00008829
Douglas Gregoree8aff02011-01-04 17:33:58 +00008830 // We now know the length of the parameter pack, so build a new expression
8831 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008832 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8833 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008834 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008835}
8836
Douglas Gregorbe230c32011-01-03 17:17:50 +00008837template<typename Derived>
8838ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008839TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8840 SubstNonTypeTemplateParmPackExpr *E) {
8841 // Default behavior is to do nothing with this transformation.
8842 return SemaRef.Owned(E);
8843}
8844
8845template<typename Derived>
8846ExprResult
John McCall91a57552011-07-15 05:09:51 +00008847TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8848 SubstNonTypeTemplateParmExpr *E) {
8849 // Default behavior is to do nothing with this transformation.
8850 return SemaRef.Owned(E);
8851}
8852
8853template<typename Derived>
8854ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008855TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8856 // Default behavior is to do nothing with this transformation.
8857 return SemaRef.Owned(E);
8858}
8859
8860template<typename Derived>
8861ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008862TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8863 MaterializeTemporaryExpr *E) {
8864 return getDerived().TransformExpr(E->GetTemporaryExpr());
8865}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008866
Douglas Gregor03e80032011-06-21 17:03:29 +00008867template<typename Derived>
8868ExprResult
Richard Smith7c3e6152013-06-12 22:31:48 +00008869TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8870 CXXStdInitializerListExpr *E) {
8871 return getDerived().TransformExpr(E->getSubExpr());
8872}
8873
8874template<typename Derived>
8875ExprResult
John McCall454feb92009-12-08 09:21:05 +00008876TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008877 return SemaRef.MaybeBindToTemporary(E);
8878}
8879
8880template<typename Derived>
8881ExprResult
8882TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008883 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008884}
8885
8886template<typename Derived>
8887ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008888TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8889 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8890 if (SubExpr.isInvalid())
8891 return ExprError();
8892
8893 if (!getDerived().AlwaysRebuild() &&
8894 SubExpr.get() == E->getSubExpr())
8895 return SemaRef.Owned(E);
8896
8897 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008898}
8899
8900template<typename Derived>
8901ExprResult
8902TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8903 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008904 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008905 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008906 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008907 /*IsCall=*/false, Elements, &ArgChanged))
8908 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008909
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008910 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8911 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008912
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008913 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8914 Elements.data(),
8915 Elements.size());
8916}
8917
8918template<typename Derived>
8919ExprResult
8920TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008921 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008922 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008923 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008924 bool ArgChanged = false;
8925 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8926 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008927
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008928 if (OrigElement.isPackExpansion()) {
8929 // This key/value element is a pack expansion.
8930 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8931 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8932 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8933 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8934
8935 // Determine whether the set of unexpanded parameter packs can
8936 // and should be expanded.
8937 bool Expand = true;
8938 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008939 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8940 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008941 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8942 OrigElement.Value->getLocEnd());
8943 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8944 PatternRange,
8945 Unexpanded,
8946 Expand, RetainExpansion,
8947 NumExpansions))
8948 return ExprError();
8949
8950 if (!Expand) {
8951 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008952 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008953 // expansion.
8954 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8955 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8956 if (Key.isInvalid())
8957 return ExprError();
8958
8959 if (Key.get() != OrigElement.Key)
8960 ArgChanged = true;
8961
8962 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8963 if (Value.isInvalid())
8964 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008965
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008966 if (Value.get() != OrigElement.Value)
8967 ArgChanged = true;
8968
Chad Rosier4a9d7952012-08-08 18:46:20 +00008969 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008970 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8971 };
8972 Elements.push_back(Expansion);
8973 continue;
8974 }
8975
8976 // Record right away that the argument was changed. This needs
8977 // to happen even if the array expands to nothing.
8978 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008979
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008980 // The transform has determined that we should perform an elementwise
8981 // expansion of the pattern. Do so.
8982 for (unsigned I = 0; I != *NumExpansions; ++I) {
8983 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8984 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8985 if (Key.isInvalid())
8986 return ExprError();
8987
8988 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8989 if (Value.isInvalid())
8990 return ExprError();
8991
Chad Rosier4a9d7952012-08-08 18:46:20 +00008992 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008993 Key.get(), Value.get(), SourceLocation(), NumExpansions
8994 };
8995
8996 // If any unexpanded parameter packs remain, we still have a
8997 // pack expansion.
8998 if (Key.get()->containsUnexpandedParameterPack() ||
8999 Value.get()->containsUnexpandedParameterPack())
9000 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00009001
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009002 Elements.push_back(Element);
9003 }
9004
9005 // We've finished with this pack expansion.
9006 continue;
9007 }
9008
9009 // Transform and check key.
9010 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
9011 if (Key.isInvalid())
9012 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009013
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009014 if (Key.get() != OrigElement.Key)
9015 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00009016
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009017 // Transform and check value.
9018 ExprResult Value
9019 = getDerived().TransformExpr(OrigElement.Value);
9020 if (Value.isInvalid())
9021 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009022
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009023 if (Value.get() != OrigElement.Value)
9024 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00009025
9026 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00009027 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009028 };
9029 Elements.push_back(Element);
9030 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00009031
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009032 if (!getDerived().AlwaysRebuild() && !ArgChanged)
9033 return SemaRef.MaybeBindToTemporary(E);
9034
9035 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
9036 Elements.data(),
9037 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009038}
9039
Mike Stump1eb44332009-09-09 15:08:12 +00009040template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009041ExprResult
John McCall454feb92009-12-08 09:21:05 +00009042TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00009043 TypeSourceInfo *EncodedTypeInfo
9044 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
9045 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00009046 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009047
Douglas Gregorb98b1992009-08-11 05:31:07 +00009048 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00009049 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00009050 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009051
9052 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00009053 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00009054 E->getRParenLoc());
9055}
Mike Stump1eb44332009-09-09 15:08:12 +00009056
Douglas Gregorb98b1992009-08-11 05:31:07 +00009057template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00009058ExprResult TreeTransform<Derived>::
9059TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCall93b64572013-04-11 02:14:26 +00009060 // This is a kind of implicit conversion, and it needs to get dropped
9061 // and recomputed for the same general reasons that ImplicitCastExprs
9062 // do, as well a more specific one: this expression is only valid when
9063 // it appears *immediately* as an argument expression.
9064 return getDerived().TransformExpr(E->getSubExpr());
John McCallf85e1932011-06-15 23:02:42 +00009065}
9066
9067template<typename Derived>
9068ExprResult TreeTransform<Derived>::
9069TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00009070 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00009071 = getDerived().TransformType(E->getTypeInfoAsWritten());
9072 if (!TSInfo)
9073 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009074
John McCallf85e1932011-06-15 23:02:42 +00009075 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009076 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00009077 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009078
John McCallf85e1932011-06-15 23:02:42 +00009079 if (!getDerived().AlwaysRebuild() &&
9080 TSInfo == E->getTypeInfoAsWritten() &&
9081 Result.get() == E->getSubExpr())
9082 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009083
John McCallf85e1932011-06-15 23:02:42 +00009084 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00009085 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00009086 Result.get());
9087}
9088
9089template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009090ExprResult
John McCall454feb92009-12-08 09:21:05 +00009091TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00009092 // Transform arguments.
9093 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009094 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00009095 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009096 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00009097 &ArgChanged))
9098 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009099
Douglas Gregor92e986e2010-04-22 16:44:27 +00009100 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9101 // Class message: transform the receiver type.
9102 TypeSourceInfo *ReceiverTypeInfo
9103 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9104 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00009105 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009106
Douglas Gregor92e986e2010-04-22 16:44:27 +00009107 // If nothing changed, just retain the existing message send.
9108 if (!getDerived().AlwaysRebuild() &&
9109 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00009110 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00009111
9112 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009113 SmallVector<SourceLocation, 16> SelLocs;
9114 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00009115 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9116 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009117 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009118 E->getMethodDecl(),
9119 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009120 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009121 E->getRightLoc());
9122 }
9123
9124 // Instance message: transform the receiver
9125 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9126 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00009127 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00009128 = getDerived().TransformExpr(E->getInstanceReceiver());
9129 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009130 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00009131
9132 // If nothing changed, just retain the existing message send.
9133 if (!getDerived().AlwaysRebuild() &&
9134 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00009135 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009136
Douglas Gregor92e986e2010-04-22 16:44:27 +00009137 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009138 SmallVector<SourceLocation, 16> SelLocs;
9139 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00009140 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00009141 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009142 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009143 E->getMethodDecl(),
9144 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009145 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009146 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009147}
9148
Mike Stump1eb44332009-09-09 15:08:12 +00009149template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009150ExprResult
John McCall454feb92009-12-08 09:21:05 +00009151TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00009152 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009153}
9154
Mike Stump1eb44332009-09-09 15:08:12 +00009155template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009156ExprResult
John McCall454feb92009-12-08 09:21:05 +00009157TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00009158 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009159}
9160
Mike Stump1eb44332009-09-09 15:08:12 +00009161template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009162ExprResult
John McCall454feb92009-12-08 09:21:05 +00009163TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009164 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009165 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009166 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009167 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009168
9169 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009170
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009171 // If nothing changed, just retain the existing expression.
9172 if (!getDerived().AlwaysRebuild() &&
9173 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009174 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009175
John McCall9ae2f072010-08-23 23:25:46 +00009176 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009177 E->getLocation(),
9178 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009179}
9180
Mike Stump1eb44332009-09-09 15:08:12 +00009181template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009182ExprResult
John McCall454feb92009-12-08 09:21:05 +00009183TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00009184 // 'super' and types never change. Property never changes. Just
9185 // retain the existing expression.
9186 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00009187 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009188
Douglas Gregore3303542010-04-26 20:47:02 +00009189 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009190 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00009191 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009192 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009193
Douglas Gregore3303542010-04-26 20:47:02 +00009194 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009195
Douglas Gregore3303542010-04-26 20:47:02 +00009196 // If nothing changed, just retain the existing expression.
9197 if (!getDerived().AlwaysRebuild() &&
9198 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009199 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009200
John McCall12f78a62010-12-02 01:19:52 +00009201 if (E->isExplicitProperty())
9202 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9203 E->getExplicitProperty(),
9204 E->getLocation());
9205
9206 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00009207 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00009208 E->getImplicitPropertyGetter(),
9209 E->getImplicitPropertySetter(),
9210 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009211}
9212
Mike Stump1eb44332009-09-09 15:08:12 +00009213template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009214ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009215TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9216 // Transform the base expression.
9217 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9218 if (Base.isInvalid())
9219 return ExprError();
9220
9221 // Transform the key expression.
9222 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9223 if (Key.isInvalid())
9224 return ExprError();
9225
9226 // If nothing changed, just retain the existing expression.
9227 if (!getDerived().AlwaysRebuild() &&
9228 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9229 return SemaRef.Owned(E);
9230
Chad Rosier4a9d7952012-08-08 18:46:20 +00009231 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009232 Base.get(), Key.get(),
9233 E->getAtIndexMethodDecl(),
9234 E->setAtIndexMethodDecl());
9235}
9236
9237template<typename Derived>
9238ExprResult
John McCall454feb92009-12-08 09:21:05 +00009239TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009240 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009241 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009242 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009243 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009244
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009245 // If nothing changed, just retain the existing expression.
9246 if (!getDerived().AlwaysRebuild() &&
9247 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009248 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009249
John McCall9ae2f072010-08-23 23:25:46 +00009250 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00009251 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009252 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009253}
9254
Mike Stump1eb44332009-09-09 15:08:12 +00009255template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009256ExprResult
John McCall454feb92009-12-08 09:21:05 +00009257TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009258 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009259 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00009260 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009261 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00009262 SubExprs, &ArgumentChanged))
9263 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009264
Douglas Gregorb98b1992009-08-11 05:31:07 +00009265 if (!getDerived().AlwaysRebuild() &&
9266 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00009267 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00009268
Douglas Gregorb98b1992009-08-11 05:31:07 +00009269 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009270 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00009271 E->getRParenLoc());
9272}
9273
Mike Stump1eb44332009-09-09 15:08:12 +00009274template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009275ExprResult
Hal Finkel414a1bd2013-09-18 03:29:45 +00009276TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9277 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9278 if (SrcExpr.isInvalid())
9279 return ExprError();
9280
9281 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9282 if (!Type)
9283 return ExprError();
9284
9285 if (!getDerived().AlwaysRebuild() &&
9286 Type == E->getTypeSourceInfo() &&
9287 SrcExpr.get() == E->getSrcExpr())
9288 return SemaRef.Owned(E);
9289
9290 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9291 SrcExpr.get(), Type,
9292 E->getRParenLoc());
9293}
9294
9295template<typename Derived>
9296ExprResult
John McCall454feb92009-12-08 09:21:05 +00009297TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00009298 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009299
John McCallc6ac9c32011-02-04 18:33:18 +00009300 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9301 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9302
9303 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00009304 blockScope->TheDecl->setBlockMissingReturnType(
9305 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009306
Chris Lattner686775d2011-07-20 06:58:45 +00009307 SmallVector<ParmVarDecl*, 4> params;
9308 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00009309
Fariborz Jahaniana729da22010-07-09 18:44:02 +00009310 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00009311 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9312 oldBlock->param_begin(),
9313 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009314 0, paramTypes, &params)) {
9315 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00009316 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009317 }
John McCallc6ac9c32011-02-04 18:33:18 +00009318
Jordan Rose09189892013-03-08 22:25:36 +00009319 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00009320 QualType exprResultType =
9321 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00009322
Jordan Rosebea522f2013-03-08 21:51:21 +00009323 QualType functionType =
9324 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009325 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00009326 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00009327
9328 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00009329 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00009330 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00009331
9332 if (!oldBlock->blockMissingReturnType()) {
9333 blockScope->HasImplicitReturnType = false;
9334 blockScope->ReturnType = exprResultType;
9335 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00009336
John McCall711c52b2011-01-05 12:14:39 +00009337 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00009338 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009339 if (body.isInvalid()) {
9340 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00009341 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009342 }
John McCall711c52b2011-01-05 12:14:39 +00009343
John McCallc6ac9c32011-02-04 18:33:18 +00009344#ifndef NDEBUG
9345 // In builds with assertions, make sure that we captured everything we
9346 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00009347 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9348 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9349 e = oldBlock->capture_end(); i != e; ++i) {
9350 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00009351
Douglas Gregorfc921372011-05-20 15:32:55 +00009352 // Ignore parameter packs.
9353 if (isa<ParmVarDecl>(oldCapture) &&
9354 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9355 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00009356
Douglas Gregorfc921372011-05-20 15:32:55 +00009357 VarDecl *newCapture =
9358 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9359 oldCapture));
9360 assert(blockScope->CaptureMap.count(newCapture));
9361 }
Douglas Gregorec79d872012-02-24 17:41:38 +00009362 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00009363 }
9364#endif
9365
9366 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9367 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009368}
9369
Mike Stump1eb44332009-09-09 15:08:12 +00009370template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009371ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009372TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00009373 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009374}
Eli Friedman276b0612011-10-11 02:20:01 +00009375
9376template<typename Derived>
9377ExprResult
9378TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009379 QualType RetTy = getDerived().TransformType(E->getType());
9380 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009381 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009382 SubExprs.reserve(E->getNumSubExprs());
9383 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9384 SubExprs, &ArgumentChanged))
9385 return ExprError();
9386
9387 if (!getDerived().AlwaysRebuild() &&
9388 !ArgumentChanged)
9389 return SemaRef.Owned(E);
9390
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009391 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009392 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00009393}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009394
Douglas Gregorb98b1992009-08-11 05:31:07 +00009395//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00009396// Type reconstruction
9397//===----------------------------------------------------------------------===//
9398
Mike Stump1eb44332009-09-09 15:08:12 +00009399template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009400QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9401 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009402 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009403 getDerived().getBaseEntity());
9404}
9405
Mike Stump1eb44332009-09-09 15:08:12 +00009406template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009407QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9408 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009409 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009410 getDerived().getBaseEntity());
9411}
9412
Mike Stump1eb44332009-09-09 15:08:12 +00009413template<typename Derived>
9414QualType
John McCall85737a72009-10-30 00:06:24 +00009415TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9416 bool WrittenAsLValue,
9417 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009418 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00009419 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009420}
9421
9422template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009423QualType
John McCall85737a72009-10-30 00:06:24 +00009424TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9425 QualType ClassType,
9426 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009427 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00009428 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009429}
9430
9431template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009432QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00009433TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9434 ArrayType::ArraySizeModifier SizeMod,
9435 const llvm::APInt *Size,
9436 Expr *SizeExpr,
9437 unsigned IndexTypeQuals,
9438 SourceRange BracketsRange) {
9439 if (SizeExpr || !Size)
9440 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9441 IndexTypeQuals, BracketsRange,
9442 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00009443
9444 QualType Types[] = {
9445 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9446 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9447 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00009448 };
Craig Topperb9602322013-07-15 03:38:40 +00009449 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009450 QualType SizeType;
9451 for (unsigned I = 0; I != NumTypes; ++I)
9452 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9453 SizeType = Types[I];
9454 break;
9455 }
Mike Stump1eb44332009-09-09 15:08:12 +00009456
Eli Friedman01f276d2012-01-25 23:20:27 +00009457 // Note that we can return a VariableArrayType here in the case where
9458 // the element type was a dependent VariableArrayType.
9459 IntegerLiteral *ArraySize
9460 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9461 /*FIXME*/BracketsRange.getBegin());
9462 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009463 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00009464 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009465}
Mike Stump1eb44332009-09-09 15:08:12 +00009466
Douglas Gregor577f75a2009-08-04 16:50:30 +00009467template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009468QualType
9469TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009470 ArrayType::ArraySizeModifier SizeMod,
9471 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009472 unsigned IndexTypeQuals,
9473 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009474 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009475 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009476}
9477
9478template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009479QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009480TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009481 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009482 unsigned IndexTypeQuals,
9483 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009484 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009485 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009486}
Mike Stump1eb44332009-09-09 15:08:12 +00009487
Douglas Gregor577f75a2009-08-04 16:50:30 +00009488template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009489QualType
9490TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009491 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009492 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009493 unsigned IndexTypeQuals,
9494 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009495 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009496 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009497 IndexTypeQuals, BracketsRange);
9498}
9499
9500template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009501QualType
9502TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009503 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009504 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009505 unsigned IndexTypeQuals,
9506 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009507 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009508 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009509 IndexTypeQuals, BracketsRange);
9510}
9511
9512template<typename Derived>
9513QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009514 unsigned NumElements,
9515 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009516 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009517 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009518}
Mike Stump1eb44332009-09-09 15:08:12 +00009519
Douglas Gregor577f75a2009-08-04 16:50:30 +00009520template<typename Derived>
9521QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9522 unsigned NumElements,
9523 SourceLocation AttributeLoc) {
9524 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9525 NumElements, true);
9526 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009527 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9528 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009529 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009530}
Mike Stump1eb44332009-09-09 15:08:12 +00009531
Douglas Gregor577f75a2009-08-04 16:50:30 +00009532template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009533QualType
9534TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009535 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009536 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009537 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009538}
Mike Stump1eb44332009-09-09 15:08:12 +00009539
Douglas Gregor577f75a2009-08-04 16:50:30 +00009540template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009541QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9542 QualType T,
9543 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009544 const FunctionProtoType::ExtProtoInfo &EPI) {
9545 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009546 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009547 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009548 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009549}
Mike Stump1eb44332009-09-09 15:08:12 +00009550
Douglas Gregor577f75a2009-08-04 16:50:30 +00009551template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009552QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9553 return SemaRef.Context.getFunctionNoProtoType(T);
9554}
9555
9556template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009557QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9558 assert(D && "no decl found");
9559 if (D->isInvalidDecl()) return QualType();
9560
Douglas Gregor92e986e2010-04-22 16:44:27 +00009561 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009562 TypeDecl *Ty;
9563 if (isa<UsingDecl>(D)) {
9564 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanella8d030c72013-07-22 10:54:09 +00009565 assert(Using->hasTypename() &&
John McCalled976492009-12-04 22:46:56 +00009566 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9567
9568 // A valid resolved using typename decl points to exactly one type decl.
9569 assert(++Using->shadow_begin() == Using->shadow_end());
9570 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009571
John McCalled976492009-12-04 22:46:56 +00009572 } else {
9573 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9574 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9575 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9576 }
9577
9578 return SemaRef.Context.getTypeDeclType(Ty);
9579}
9580
9581template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009582QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9583 SourceLocation Loc) {
9584 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009585}
9586
9587template<typename Derived>
9588QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9589 return SemaRef.Context.getTypeOfType(Underlying);
9590}
9591
9592template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009593QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9594 SourceLocation Loc) {
9595 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009596}
9597
9598template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009599QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9600 UnaryTransformType::UTTKind UKind,
9601 SourceLocation Loc) {
9602 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9603}
9604
9605template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009606QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009607 TemplateName Template,
9608 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009609 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009610 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009611}
Mike Stump1eb44332009-09-09 15:08:12 +00009612
Douglas Gregordcee1a12009-08-06 05:28:30 +00009613template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009614QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9615 SourceLocation KWLoc) {
9616 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9617}
9618
9619template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009620TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009621TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009622 bool TemplateKW,
9623 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009624 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009625 Template);
9626}
9627
9628template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009629TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009630TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9631 const IdentifierInfo &Name,
9632 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009633 QualType ObjectType,
9634 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009635 UnqualifiedId TemplateName;
9636 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009637 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009638 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009639 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009640 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009641 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009642 /*EnteringContext=*/false,
9643 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009644 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009645}
Mike Stump1eb44332009-09-09 15:08:12 +00009646
Douglas Gregorb98b1992009-08-11 05:31:07 +00009647template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009648TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009649TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009650 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009651 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009652 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009653 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009654 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009655 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009656 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009657 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009658 Sema::TemplateTy Template;
9659 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009660 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009661 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009662 /*EnteringContext=*/false,
9663 Template);
Serge Pavlov18062392013-08-27 13:15:56 +00009664 return Template.get();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009665}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009666
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009667template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009668ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009669TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9670 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009671 Expr *OrigCallee,
9672 Expr *First,
9673 Expr *Second) {
9674 Expr *Callee = OrigCallee->IgnoreParenCasts();
9675 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009676
Douglas Gregorb98b1992009-08-11 05:31:07 +00009677 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009678 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009679 if (!First->getType()->isOverloadableType() &&
9680 !Second->getType()->isOverloadableType())
9681 return getSema().CreateBuiltinArraySubscriptExpr(First,
9682 Callee->getLocStart(),
9683 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009684 } else if (Op == OO_Arrow) {
9685 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009686 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9687 } else if (Second == 0 || isPostIncDec) {
9688 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009689 // The argument is not of overloadable type, so try to create a
9690 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009691 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009692 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009693
John McCall9ae2f072010-08-23 23:25:46 +00009694 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009695 }
9696 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009697 if (!First->getType()->isOverloadableType() &&
9698 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009699 // Neither of the arguments is an overloadable type, so try to
9700 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009701 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009702 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009703 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009704 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009705 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009706
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009707 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009708 }
9709 }
Mike Stump1eb44332009-09-09 15:08:12 +00009710
9711 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009712 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009713 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009714
John McCall9ae2f072010-08-23 23:25:46 +00009715 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009716 assert(ULE->requiresADL());
9717
9718 // FIXME: Do we have to check
9719 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009720 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009721 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009722 // If we've resolved this to a particular non-member function, just call
9723 // that function. If we resolved it to a member function,
9724 // CreateOverloaded* will find that function for us.
9725 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9726 if (!isa<CXXMethodDecl>(ND))
9727 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009728 }
Mike Stump1eb44332009-09-09 15:08:12 +00009729
Douglas Gregorb98b1992009-08-11 05:31:07 +00009730 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009731 Expr *Args[2] = { First, Second };
9732 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009733
Douglas Gregorb98b1992009-08-11 05:31:07 +00009734 // Create the overloaded operator invocation for unary operators.
9735 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009736 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009737 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009738 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009739 }
Mike Stump1eb44332009-09-09 15:08:12 +00009740
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009741 if (Op == OO_Subscript) {
9742 SourceLocation LBrace;
9743 SourceLocation RBrace;
9744
9745 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9746 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9747 LBrace = SourceLocation::getFromRawEncoding(
9748 NameLoc.CXXOperatorName.BeginOpNameLoc);
9749 RBrace = SourceLocation::getFromRawEncoding(
9750 NameLoc.CXXOperatorName.EndOpNameLoc);
9751 } else {
9752 LBrace = Callee->getLocStart();
9753 RBrace = OpLoc;
9754 }
9755
9756 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9757 First, Second);
9758 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009759
Douglas Gregorb98b1992009-08-11 05:31:07 +00009760 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009761 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009762 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009763 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9764 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009765 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009766
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009767 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009768}
Mike Stump1eb44332009-09-09 15:08:12 +00009769
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009770template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009771ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009772TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009773 SourceLocation OperatorLoc,
9774 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009775 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009776 TypeSourceInfo *ScopeType,
9777 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009778 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009779 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009780 QualType BaseType = Base->getType();
9781 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009782 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009783 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009784 !BaseType->getAs<PointerType>()->getPointeeType()
9785 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009786 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009787 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009788 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009789 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009790 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009791 /*FIXME?*/true);
9792 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009793
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009794 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009795 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9796 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9797 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9798 NameInfo.setNamedTypeInfo(DestroyedType);
9799
Richard Smith6314db92012-05-15 06:15:11 +00009800 // The scope type is now known to be a valid nested name specifier
9801 // component. Tack it on to the end of the nested name specifier.
9802 if (ScopeType)
9803 SS.Extend(SemaRef.Context, SourceLocation(),
9804 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009805
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009806 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009807 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009808 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009809 SS, TemplateKWLoc,
9810 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009811 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009812 /*TemplateArgs*/ 0);
9813}
9814
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009815template<typename Derived>
9816StmtResult
9817TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan9fd6b8f2013-05-04 03:59:06 +00009818 SourceLocation Loc = S->getLocStart();
9819 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9820 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9821 S->getCapturedRegionKind(), NumParams);
9822 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9823
9824 if (Body.isInvalid()) {
9825 getSema().ActOnCapturedRegionError();
9826 return StmtError();
9827 }
9828
9829 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009830}
9831
Douglas Gregor577f75a2009-08-04 16:50:30 +00009832} // end namespace clang
9833
9834#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H