blob: d79d145c12e780ce58b0f822cd97fcc52b5b5480 [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
David Majnemerfc210492013-10-15 09:33:02 +0000547 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley28bbe4b2011-04-28 01:08:34 +0000548
Chad Rosier4a9d7952012-08-08 18:46:20 +0000549 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000550 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
551 TemplateSpecializationTypeLoc TL,
552 TemplateName Template);
553
Chad Rosier4a9d7952012-08-08 18:46:20 +0000554 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000555 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
556 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000557 TemplateName Template,
558 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000559
Chad Rosier4a9d7952012-08-08 18:46:20 +0000560 QualType
Douglas Gregora88f09f2011-02-28 17:23:35 +0000561 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000562 DependentTemplateSpecializationTypeLoc TL,
563 NestedNameSpecifierLoc QualifierLoc);
564
John McCall21ef0fa2010-03-11 09:03:00 +0000565 /// \brief Transforms the parameters of a function type into the
566 /// given vectors.
567 ///
568 /// The result vectors should be kept in sync; null entries in the
569 /// variables vector are acceptable.
570 ///
571 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000572 bool TransformFunctionTypeParams(SourceLocation Loc,
573 ParmVarDecl **Params, unsigned NumParams,
574 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000575 SmallVectorImpl<QualType> &PTypes,
576 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000577
578 /// \brief Transforms a single function-type parameter. Return null
579 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000580 ///
581 /// \param indexAdjustment - A number to add to the parameter's
582 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000583 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000584 int indexAdjustment,
David Blaikiedc84cd52013-02-20 22:23:23 +0000585 Optional<unsigned> NumExpansions,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000586 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000587
John McCall43fed0d2010-11-12 08:19:04 +0000588 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000589
John McCall60d7b3a2010-08-24 06:29:42 +0000590 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
591 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000592
Richard Smith612409e2012-07-25 03:56:55 +0000593 /// \brief Transform the captures and body of a lambda expression.
594 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator);
595
Richard Smithefeeccf2012-10-21 03:28:35 +0000596 ExprResult TransformAddressOfOperand(Expr *E);
597 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
598 bool IsAddressOfOperand);
599
Eli Friedman1ac6c932013-09-06 01:13:30 +0000600// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
601// amount of stack usage with clang.
Douglas Gregor43959a92009-08-20 07:17:43 +0000602#define STMT(Node, Parent) \
Eli Friedman1ac6c932013-09-06 01:13:30 +0000603 LLVM_ATTRIBUTE_NOINLINE \
John McCall60d7b3a2010-08-24 06:29:42 +0000604 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000605#define EXPR(Node, Parent) \
Eli Friedman1ac6c932013-09-06 01:13:30 +0000606 LLVM_ATTRIBUTE_NOINLINE \
John McCall60d7b3a2010-08-24 06:29:42 +0000607 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000608#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000609#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000610
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000611#define OPENMP_CLAUSE(Name, Class) \
Eli Friedman1ac6c932013-09-06 01:13:30 +0000612 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000613 OMPClause *Transform ## Class(Class *S);
614#include "clang/Basic/OpenMPKinds.def"
615
Douglas Gregor577f75a2009-08-04 16:50:30 +0000616 /// \brief Build a new pointer type given its pointee type.
617 ///
618 /// By default, performs semantic analysis when building the pointer type.
619 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000620 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000621
622 /// \brief Build a new block pointer type given its pointee type.
623 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000624 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000625 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000626 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000627
John McCall85737a72009-10-30 00:06:24 +0000628 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000629 ///
John McCall85737a72009-10-30 00:06:24 +0000630 /// By default, performs semantic analysis when building the
631 /// reference type. Subclasses may override this routine to provide
632 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000633 ///
John McCall85737a72009-10-30 00:06:24 +0000634 /// \param LValue whether the type was written with an lvalue sigil
635 /// or an rvalue sigil.
636 QualType RebuildReferenceType(QualType ReferentType,
637 bool LValue,
638 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000639
Douglas Gregor577f75a2009-08-04 16:50:30 +0000640 /// \brief Build a new member pointer type given the pointee type and the
641 /// class type it refers into.
642 ///
643 /// By default, performs semantic analysis when building the member pointer
644 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000645 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
646 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000647
Douglas Gregor577f75a2009-08-04 16:50:30 +0000648 /// \brief Build a new array type given the element type, size
649 /// modifier, size of the array (if known), size expression, and index type
650 /// qualifiers.
651 ///
652 /// By default, performs semantic analysis when building the array type.
653 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000654 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000655 QualType RebuildArrayType(QualType ElementType,
656 ArrayType::ArraySizeModifier SizeMod,
657 const llvm::APInt *Size,
658 Expr *SizeExpr,
659 unsigned IndexTypeQuals,
660 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000661
Douglas Gregor577f75a2009-08-04 16:50:30 +0000662 /// \brief Build a new constant array type given the element type, size
663 /// modifier, (known) size of the array, and index type qualifiers.
664 ///
665 /// By default, performs semantic analysis when building the array type.
666 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000667 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000668 ArrayType::ArraySizeModifier SizeMod,
669 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000670 unsigned IndexTypeQuals,
671 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000672
Douglas Gregor577f75a2009-08-04 16:50:30 +0000673 /// \brief Build a new incomplete array type given the element type, size
674 /// modifier, and index type qualifiers.
675 ///
676 /// By default, performs semantic analysis when building the array type.
677 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000678 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000679 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000680 unsigned IndexTypeQuals,
681 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000682
Mike Stump1eb44332009-09-09 15:08:12 +0000683 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000684 /// size modifier, size expression, and index type qualifiers.
685 ///
686 /// By default, performs semantic analysis when building the array type.
687 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000688 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000689 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000690 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000691 unsigned IndexTypeQuals,
692 SourceRange BracketsRange);
693
Mike Stump1eb44332009-09-09 15:08:12 +0000694 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000695 /// size modifier, size expression, and index type qualifiers.
696 ///
697 /// By default, performs semantic analysis when building the array type.
698 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000699 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000700 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000701 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000702 unsigned IndexTypeQuals,
703 SourceRange BracketsRange);
704
705 /// \brief Build a new vector type given the element type and
706 /// number of elements.
707 ///
708 /// By default, performs semantic analysis when building the vector type.
709 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000710 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000711 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000712
Douglas Gregor577f75a2009-08-04 16:50:30 +0000713 /// \brief Build a new extended vector type given the element type and
714 /// number of elements.
715 ///
716 /// By default, performs semantic analysis when building the vector type.
717 /// Subclasses may override this routine to provide different behavior.
718 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
719 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000720
721 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000722 /// given the element type and number of elements.
723 ///
724 /// By default, performs semantic analysis when building the vector type.
725 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000726 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000727 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000728 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000729
Douglas Gregor577f75a2009-08-04 16:50:30 +0000730 /// \brief Build a new function type.
731 ///
732 /// By default, performs semantic analysis when building the function type.
733 /// Subclasses may override this routine to provide different behavior.
734 QualType RebuildFunctionProtoType(QualType T,
Jordan Rosebea522f2013-03-08 21:51:21 +0000735 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +0000736 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump1eb44332009-09-09 15:08:12 +0000737
John McCalla2becad2009-10-21 00:40:46 +0000738 /// \brief Build a new unprototyped function type.
739 QualType RebuildFunctionNoProtoType(QualType ResultType);
740
John McCalled976492009-12-04 22:46:56 +0000741 /// \brief Rebuild an unresolved typename type, given the decl that
742 /// the UnresolvedUsingTypenameDecl was transformed to.
743 QualType RebuildUnresolvedUsingType(Decl *D);
744
Douglas Gregor577f75a2009-08-04 16:50:30 +0000745 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000746 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000747 return SemaRef.Context.getTypeDeclType(Typedef);
748 }
749
750 /// \brief Build a new class/struct/union type.
751 QualType RebuildRecordType(RecordDecl *Record) {
752 return SemaRef.Context.getTypeDeclType(Record);
753 }
754
755 /// \brief Build a new Enum type.
756 QualType RebuildEnumType(EnumDecl *Enum) {
757 return SemaRef.Context.getTypeDeclType(Enum);
758 }
John McCall7da24312009-09-05 00:15:47 +0000759
Mike Stump1eb44332009-09-09 15:08:12 +0000760 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000761 ///
762 /// By default, performs semantic analysis when building the typeof type.
763 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000764 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000765
Mike Stump1eb44332009-09-09 15:08:12 +0000766 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000767 ///
768 /// By default, builds a new TypeOfType with the given underlying type.
769 QualType RebuildTypeOfType(QualType Underlying);
770
Sean Huntca63c202011-05-24 22:41:36 +0000771 /// \brief Build a new unary transform type.
772 QualType RebuildUnaryTransformType(QualType BaseType,
773 UnaryTransformType::UTTKind UKind,
774 SourceLocation Loc);
775
Richard Smitha2c36462013-04-26 16:15:35 +0000776 /// \brief Build a new C++11 decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000777 ///
778 /// By default, performs semantic analysis when building the decltype type.
779 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000780 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000781
Richard Smitha2c36462013-04-26 16:15:35 +0000782 /// \brief Build a new C++11 auto type.
Richard Smith34b41d92011-02-20 03:19:35 +0000783 ///
784 /// By default, builds a new AutoType with the given deduced type.
Richard Smitha2c36462013-04-26 16:15:35 +0000785 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smithdc7a4f52013-04-30 13:56:41 +0000786 // Note, IsDependent is always false here: we implicitly convert an 'auto'
787 // which has been deduced to a dependent type into an undeduced 'auto', so
788 // that we'll retry deduction after the transformation.
Faisal Valifad9e132013-09-26 19:54:12 +0000789 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
790 /*IsDependent*/ false);
Richard Smith34b41d92011-02-20 03:19:35 +0000791 }
792
Douglas Gregor577f75a2009-08-04 16:50:30 +0000793 /// \brief Build a new template specialization type.
794 ///
795 /// By default, performs semantic analysis when building the template
796 /// specialization type. Subclasses may override this routine to provide
797 /// different behavior.
798 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000799 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000800 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000801
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000802 /// \brief Build a new parenthesized type.
803 ///
804 /// By default, builds a new ParenType type from the inner type.
805 /// Subclasses may override this routine to provide different behavior.
806 QualType RebuildParenType(QualType InnerType) {
807 return SemaRef.Context.getParenType(InnerType);
808 }
809
Douglas Gregor577f75a2009-08-04 16:50:30 +0000810 /// \brief Build a new qualified name type.
811 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000812 /// By default, builds a new ElaboratedType type from the keyword,
813 /// the nested-name-specifier and the named type.
814 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000815 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
816 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000817 NestedNameSpecifierLoc QualifierLoc,
818 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000819 return SemaRef.Context.getElaboratedType(Keyword,
820 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000821 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000822 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000823
824 /// \brief Build a new typename type that refers to a template-id.
825 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000826 /// By default, builds a new DependentNameType type from the
827 /// nested-name-specifier and the given type. Subclasses may override
828 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000829 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000830 ElaboratedTypeKeyword Keyword,
831 NestedNameSpecifierLoc QualifierLoc,
832 const IdentifierInfo *Name,
833 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000834 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000835 // Rebuild the template name.
836 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000837 CXXScopeSpec SS;
838 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000839 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000840 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000841
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000842 if (InstName.isNull())
843 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000844
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000845 // If it's still dependent, make a dependent specialization.
846 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000847 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
848 QualifierLoc.getNestedNameSpecifier(),
849 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000850 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000851
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000852 // Otherwise, make an elaborated type wrapping a non-dependent
853 // specialization.
854 QualType T =
855 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
856 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000857
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000858 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
859 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000860
861 return SemaRef.Context.getElaboratedType(Keyword,
862 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000863 T);
864 }
865
Douglas Gregor577f75a2009-08-04 16:50:30 +0000866 /// \brief Build a new typename type that refers to an identifier.
867 ///
868 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000869 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000870 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000871 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000872 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000873 NestedNameSpecifierLoc QualifierLoc,
874 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000875 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000876 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000877 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000878
Douglas Gregor2494dd02011-03-01 01:34:45 +0000879 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000880 // If the name is still dependent, just build a new dependent name type.
881 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000882 return SemaRef.Context.getDependentNameType(Keyword,
883 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000884 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000885 }
886
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000887 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000888 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000889 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000890
891 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
892
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000893 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000894 // into a non-dependent elaborated-type-specifier. Find the tag we're
895 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000896 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000897 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
898 if (!DC)
899 return QualType();
900
John McCall56138762010-05-27 06:40:31 +0000901 if (SemaRef.RequireCompleteDeclContext(SS, DC))
902 return QualType();
903
Douglas Gregor40336422010-03-31 22:19:08 +0000904 TagDecl *Tag = 0;
905 SemaRef.LookupQualifiedName(Result, DC);
906 switch (Result.getResultKind()) {
907 case LookupResult::NotFound:
908 case LookupResult::NotFoundInCurrentInstantiation:
909 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000910
Douglas Gregor40336422010-03-31 22:19:08 +0000911 case LookupResult::Found:
912 Tag = Result.getAsSingle<TagDecl>();
913 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000914
Douglas Gregor40336422010-03-31 22:19:08 +0000915 case LookupResult::FoundOverloaded:
916 case LookupResult::FoundUnresolvedValue:
917 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000918
Douglas Gregor40336422010-03-31 22:19:08 +0000919 case LookupResult::Ambiguous:
920 // Let the LookupResult structure handle ambiguities.
921 return QualType();
922 }
923
924 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000925 // Check where the name exists but isn't a tag type and use that to emit
926 // better diagnostics.
927 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
928 SemaRef.LookupQualifiedName(Result, DC);
929 switch (Result.getResultKind()) {
930 case LookupResult::Found:
931 case LookupResult::FoundOverloaded:
932 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000933 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000934 unsigned Kind = 0;
935 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000936 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
937 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000938 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
939 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
940 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000941 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000942 default:
943 // FIXME: Would be nice to highlight just the source range.
944 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
945 << Kind << Id << DC;
946 break;
947 }
Douglas Gregor40336422010-03-31 22:19:08 +0000948 return QualType();
949 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000950
Richard Trieubbf34c02011-06-10 03:11:26 +0000951 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
952 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000953 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000954 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
955 return QualType();
956 }
957
958 // Build the elaborated-type-specifier type.
959 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000960 return SemaRef.Context.getElaboratedType(Keyword,
961 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000962 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000963 }
Mike Stump1eb44332009-09-09 15:08:12 +0000964
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000965 /// \brief Build a new pack expansion type.
966 ///
967 /// By default, builds a new PackExpansionType type from the given pattern.
968 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000969 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000970 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000971 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +0000972 Optional<unsigned> NumExpansions) {
Douglas Gregorcded4f62011-01-14 17:04:44 +0000973 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
974 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000975 }
976
Eli Friedmanb001de72011-10-06 23:00:33 +0000977 /// \brief Build a new atomic type given its value type.
978 ///
979 /// By default, performs semantic analysis when building the atomic type.
980 /// Subclasses may override this routine to provide different behavior.
981 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
982
Douglas Gregord1067e52009-08-06 06:41:21 +0000983 /// \brief Build a new template name given a nested name specifier, a flag
984 /// indicating whether the "template" keyword was provided, and the template
985 /// that the template name refers to.
986 ///
987 /// By default, builds the new template name directly. Subclasses may override
988 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000989 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000990 bool TemplateKW,
991 TemplateDecl *Template);
992
Douglas Gregord1067e52009-08-06 06:41:21 +0000993 /// \brief Build a new template name given a nested name specifier and the
994 /// name that is referred to as a template.
995 ///
996 /// By default, performs semantic analysis to determine whether the name can
997 /// be resolved to a specific template, then builds the appropriate kind of
998 /// template name. Subclasses may override this routine to provide different
999 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001000 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1001 const IdentifierInfo &Name,
1002 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00001003 QualType ObjectType,
1004 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00001005
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001006 /// \brief Build a new template name given a nested name specifier and the
1007 /// overloaded operator name that is referred to as a template.
1008 ///
1009 /// By default, performs semantic analysis to determine whether the name can
1010 /// be resolved to a specific template, then builds the appropriate kind of
1011 /// template name. Subclasses may override this routine to provide different
1012 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001013 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001014 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00001015 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001016 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001017
1018 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +00001019 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001020 ///
1021 /// By default, performs semantic analysis to determine whether the name can
1022 /// be resolved to a specific template, then builds the appropriate kind of
1023 /// template name. Subclasses may override this routine to provide different
1024 /// behavior.
1025 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1026 const TemplateArgument &ArgPack) {
1027 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1028 }
1029
Douglas Gregor43959a92009-08-20 07:17:43 +00001030 /// \brief Build a new compound statement.
1031 ///
1032 /// By default, performs semantic analysis to build the new statement.
1033 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001034 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001035 MultiStmtArg Statements,
1036 SourceLocation RBraceLoc,
1037 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001038 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001039 IsStmtExpr);
1040 }
1041
1042 /// \brief Build a new case statement.
1043 ///
1044 /// By default, performs semantic analysis to build the new statement.
1045 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001046 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001047 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001048 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001049 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001050 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001051 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001052 ColonLoc);
1053 }
Mike Stump1eb44332009-09-09 15:08:12 +00001054
Douglas Gregor43959a92009-08-20 07:17:43 +00001055 /// \brief Attach the body to a new case statement.
1056 ///
1057 /// By default, performs semantic analysis to build the new statement.
1058 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001059 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001060 getSema().ActOnCaseStmtBody(S, Body);
1061 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001062 }
Mike Stump1eb44332009-09-09 15:08:12 +00001063
Douglas Gregor43959a92009-08-20 07:17:43 +00001064 /// \brief Build a new default statement.
1065 ///
1066 /// By default, performs semantic analysis to build the new statement.
1067 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001068 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001069 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001070 Stmt *SubStmt) {
1071 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001072 /*CurScope=*/0);
1073 }
Mike Stump1eb44332009-09-09 15:08:12 +00001074
Douglas Gregor43959a92009-08-20 07:17:43 +00001075 /// \brief Build a new label statement.
1076 ///
1077 /// By default, performs semantic analysis to build the new statement.
1078 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001079 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1080 SourceLocation ColonLoc, Stmt *SubStmt) {
1081 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001082 }
Mike Stump1eb44332009-09-09 15:08:12 +00001083
Richard Smith534986f2012-04-14 00:33:13 +00001084 /// \brief Build a new label statement.
1085 ///
1086 /// By default, performs semantic analysis to build the new statement.
1087 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001088 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1089 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001090 Stmt *SubStmt) {
1091 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1092 }
1093
Douglas Gregor43959a92009-08-20 07:17:43 +00001094 /// \brief Build a new "if" statement.
1095 ///
1096 /// By default, performs semantic analysis to build the new statement.
1097 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001098 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001099 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001100 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001101 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001102 }
Mike Stump1eb44332009-09-09 15:08:12 +00001103
Douglas Gregor43959a92009-08-20 07:17:43 +00001104 /// \brief Start building a new switch statement.
1105 ///
1106 /// By default, performs semantic analysis to build the new statement.
1107 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001108 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001109 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001110 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001111 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001112 }
Mike Stump1eb44332009-09-09 15:08:12 +00001113
Douglas Gregor43959a92009-08-20 07:17:43 +00001114 /// \brief Attach the body to the switch statement.
1115 ///
1116 /// By default, performs semantic analysis to build the new statement.
1117 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001118 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001119 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001120 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001121 }
1122
1123 /// \brief Build a new while statement.
1124 ///
1125 /// By default, performs semantic analysis to build the new statement.
1126 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001127 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1128 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001129 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001130 }
Mike Stump1eb44332009-09-09 15:08:12 +00001131
Douglas Gregor43959a92009-08-20 07:17:43 +00001132 /// \brief Build a new do-while statement.
1133 ///
1134 /// By default, performs semantic analysis to build the new statement.
1135 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001136 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001137 SourceLocation WhileLoc, SourceLocation LParenLoc,
1138 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001139 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1140 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001141 }
1142
1143 /// \brief Build a new for statement.
1144 ///
1145 /// By default, performs semantic analysis to build the new statement.
1146 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001147 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001148 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001149 VarDecl *CondVar, Sema::FullExprArg Inc,
1150 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001151 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001152 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001153 }
Mike Stump1eb44332009-09-09 15:08:12 +00001154
Douglas Gregor43959a92009-08-20 07:17:43 +00001155 /// \brief Build a new goto statement.
1156 ///
1157 /// By default, performs semantic analysis to build the new statement.
1158 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001159 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1160 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001161 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001162 }
1163
1164 /// \brief Build a new indirect goto statement.
1165 ///
1166 /// By default, performs semantic analysis to build the new statement.
1167 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001168 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001169 SourceLocation StarLoc,
1170 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001171 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001172 }
Mike Stump1eb44332009-09-09 15:08:12 +00001173
Douglas Gregor43959a92009-08-20 07:17:43 +00001174 /// \brief Build a new return statement.
1175 ///
1176 /// By default, performs semantic analysis to build the new statement.
1177 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001178 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001179 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001180 }
Mike Stump1eb44332009-09-09 15:08:12 +00001181
Douglas Gregor43959a92009-08-20 07:17:43 +00001182 /// \brief Build a new declaration statement.
1183 ///
1184 /// By default, performs semantic analysis to build the new statement.
1185 /// Subclasses may override this routine to provide different behavior.
Rafael Espindola4549d7f2013-07-09 12:05:01 +00001186 StmtResult RebuildDeclStmt(llvm::MutableArrayRef<Decl *> Decls,
1187 SourceLocation StartLoc, SourceLocation EndLoc) {
1188 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith406c38e2011-02-23 00:37:57 +00001189 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001190 }
Mike Stump1eb44332009-09-09 15:08:12 +00001191
Anders Carlsson703e3942010-01-24 05:50:09 +00001192 /// \brief Build a new inline asm statement.
1193 ///
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001196 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1197 bool IsVolatile, unsigned NumOutputs,
1198 unsigned NumInputs, IdentifierInfo **Names,
1199 MultiExprArg Constraints, MultiExprArg Exprs,
1200 Expr *AsmString, MultiExprArg Clobbers,
1201 SourceLocation RParenLoc) {
1202 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1203 NumInputs, Names, Constraints, Exprs,
1204 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001205 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001206
Chad Rosier8cd64b42012-06-11 20:47:18 +00001207 /// \brief Build a new MS style inline asm statement.
1208 ///
1209 /// By default, performs semantic analysis to build the new statement.
1210 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001211 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallaeeacf72013-05-03 00:10:13 +00001212 ArrayRef<Token> AsmToks,
1213 StringRef AsmString,
1214 unsigned NumOutputs, unsigned NumInputs,
1215 ArrayRef<StringRef> Constraints,
1216 ArrayRef<StringRef> Clobbers,
1217 ArrayRef<Expr*> Exprs,
1218 SourceLocation EndLoc) {
1219 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1220 NumOutputs, NumInputs,
1221 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001222 }
1223
James Dennett699c9042012-06-15 07:13:21 +00001224 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001225 ///
1226 /// By default, performs semantic analysis to build the new statement.
1227 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001228 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001229 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001230 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001231 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001232 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001233 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001234 }
1235
Douglas Gregorbe270a02010-04-26 17:57:08 +00001236 /// \brief Rebuild an Objective-C exception declaration.
1237 ///
1238 /// By default, performs semantic analysis to build the new declaration.
1239 /// Subclasses may override this routine to provide different behavior.
1240 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1241 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001242 return getSema().BuildObjCExceptionDecl(TInfo, T,
1243 ExceptionDecl->getInnerLocStart(),
1244 ExceptionDecl->getLocation(),
1245 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001246 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001247
James Dennett699c9042012-06-15 07:13:21 +00001248 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001249 ///
1250 /// By default, performs semantic analysis to build the new statement.
1251 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001252 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001253 SourceLocation RParenLoc,
1254 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001255 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001256 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001257 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001258 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001259
James Dennett699c9042012-06-15 07:13:21 +00001260 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001261 ///
1262 /// By default, performs semantic analysis to build the new statement.
1263 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001264 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001265 Stmt *Body) {
1266 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001267 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001268
James Dennett699c9042012-06-15 07:13:21 +00001269 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001270 ///
1271 /// By default, performs semantic analysis to build the new statement.
1272 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001273 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001274 Expr *Operand) {
1275 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001276 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001277
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00001278 /// \brief Build a new OpenMP parallel directive.
1279 ///
1280 /// By default, performs semantic analysis to build the new statement.
1281 /// Subclasses may override this routine to provide different behavior.
1282 StmtResult RebuildOMPParallelDirective(ArrayRef<OMPClause *> Clauses,
1283 Stmt *AStmt,
1284 SourceLocation StartLoc,
1285 SourceLocation EndLoc) {
1286 return getSema().ActOnOpenMPParallelDirective(Clauses, AStmt,
1287 StartLoc, EndLoc);
1288 }
1289
1290 /// \brief Build a new OpenMP 'default' clause.
1291 ///
1292 /// By default, performs semantic analysis to build the new statement.
1293 /// Subclasses may override this routine to provide different behavior.
1294 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1295 SourceLocation KindKwLoc,
1296 SourceLocation StartLoc,
1297 SourceLocation LParenLoc,
1298 SourceLocation EndLoc) {
1299 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1300 StartLoc, LParenLoc, EndLoc);
1301 }
1302
1303 /// \brief Build a new OpenMP 'private' clause.
1304 ///
1305 /// By default, performs semantic analysis to build the new statement.
1306 /// Subclasses may override this routine to provide different behavior.
1307 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1308 SourceLocation StartLoc,
1309 SourceLocation LParenLoc,
1310 SourceLocation EndLoc) {
1311 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1312 EndLoc);
1313 }
1314
Alexey Bataevd195bc32013-10-01 05:32:34 +00001315 /// \brief Build a new OpenMP 'firstprivate' clause.
1316 ///
1317 /// By default, performs semantic analysis to build the new statement.
1318 /// Subclasses may override this routine to provide different behavior.
1319 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1320 SourceLocation StartLoc,
1321 SourceLocation LParenLoc,
1322 SourceLocation EndLoc) {
1323 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1324 EndLoc);
1325 }
1326
Alexey Bataev0c018352013-09-06 18:03:48 +00001327 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1328 SourceLocation StartLoc,
1329 SourceLocation LParenLoc,
1330 SourceLocation EndLoc) {
1331 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1332 EndLoc);
1333 }
1334
James Dennett699c9042012-06-15 07:13:21 +00001335 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001336 ///
1337 /// By default, performs semantic analysis to build the new statement.
1338 /// Subclasses may override this routine to provide different behavior.
1339 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1340 Expr *object) {
1341 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1342 }
1343
James Dennett699c9042012-06-15 07:13:21 +00001344 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001345 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001346 /// By default, performs semantic analysis to build the new statement.
1347 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001348 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001349 Expr *Object, Stmt *Body) {
1350 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001351 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001352
James Dennett699c9042012-06-15 07:13:21 +00001353 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001354 ///
1355 /// By default, performs semantic analysis to build the new statement.
1356 /// Subclasses may override this routine to provide different behavior.
1357 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1358 Stmt *Body) {
1359 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1360 }
John McCall990567c2011-07-27 01:07:15 +00001361
Douglas Gregorc3203e72010-04-22 23:10:45 +00001362 /// \brief Build a new Objective-C fast enumeration statement.
1363 ///
1364 /// By default, performs semantic analysis to build the new statement.
1365 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001366 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001367 Stmt *Element,
1368 Expr *Collection,
1369 SourceLocation RParenLoc,
1370 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001371 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001372 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001373 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001374 RParenLoc);
1375 if (ForEachStmt.isInvalid())
1376 return StmtError();
1377
1378 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001379 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001380
Douglas Gregor43959a92009-08-20 07:17:43 +00001381 /// \brief Build a new C++ exception declaration.
1382 ///
1383 /// By default, performs semantic analysis to build the new decaration.
1384 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001385 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001386 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001387 SourceLocation StartLoc,
1388 SourceLocation IdLoc,
1389 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001390 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1391 StartLoc, IdLoc, Id);
1392 if (Var)
1393 getSema().CurContext->addDecl(Var);
1394 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001395 }
1396
1397 /// \brief Build a new C++ catch statement.
1398 ///
1399 /// By default, performs semantic analysis to build the new statement.
1400 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001401 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001402 VarDecl *ExceptionDecl,
1403 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001404 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1405 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001406 }
Mike Stump1eb44332009-09-09 15:08:12 +00001407
Douglas Gregor43959a92009-08-20 07:17:43 +00001408 /// \brief Build a new C++ try statement.
1409 ///
1410 /// By default, performs semantic analysis to build the new statement.
1411 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelm21adb0c2013-08-22 09:20:03 +00001412 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1413 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001414 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001415 }
Mike Stump1eb44332009-09-09 15:08:12 +00001416
Richard Smithad762fc2011-04-14 22:09:26 +00001417 /// \brief Build a new C++0x range-based for statement.
1418 ///
1419 /// By default, performs semantic analysis to build the new statement.
1420 /// Subclasses may override this routine to provide different behavior.
1421 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1422 SourceLocation ColonLoc,
1423 Stmt *Range, Stmt *BeginEnd,
1424 Expr *Cond, Expr *Inc,
1425 Stmt *LoopVar,
1426 SourceLocation RParenLoc) {
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001427 // If we've just learned that the range is actually an Objective-C
1428 // collection, treat this as an Objective-C fast enumeration loop.
1429 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1430 if (RangeStmt->isSingleDecl()) {
1431 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39b60dc2013-05-02 18:35:56 +00001432 if (RangeVar->isInvalidDecl())
1433 return StmtError();
1434
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001435 Expr *RangeExpr = RangeVar->getInit();
1436 if (!RangeExpr->isTypeDependent() &&
1437 RangeExpr->getType()->isObjCObjectPointerType())
1438 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1439 RParenLoc);
1440 }
1441 }
1442 }
1443
Richard Smithad762fc2011-04-14 22:09:26 +00001444 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001445 Cond, Inc, LoopVar, RParenLoc,
1446 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001447 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001448
1449 /// \brief Build a new C++0x range-based for statement.
1450 ///
1451 /// By default, performs semantic analysis to build the new statement.
1452 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001453 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001454 bool IsIfExists,
1455 NestedNameSpecifierLoc QualifierLoc,
1456 DeclarationNameInfo NameInfo,
1457 Stmt *Nested) {
1458 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1459 QualifierLoc, NameInfo, Nested);
1460 }
1461
Richard Smithad762fc2011-04-14 22:09:26 +00001462 /// \brief Attach body to a C++0x range-based for statement.
1463 ///
1464 /// By default, performs semantic analysis to finish the new statement.
1465 /// Subclasses may override this routine to provide different behavior.
1466 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1467 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1468 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001469
David Majnemerfc210492013-10-15 09:33:02 +00001470 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
1471 Stmt *TryBlock, Stmt *Handler) {
1472 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley28bbe4b2011-04-28 01:08:34 +00001473 }
1474
David Majnemerfc210492013-10-15 09:33:02 +00001475 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley28bbe4b2011-04-28 01:08:34 +00001476 Stmt *Block) {
David Majnemerfc210492013-10-15 09:33:02 +00001477 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley28bbe4b2011-04-28 01:08:34 +00001478 }
1479
David Majnemerfc210492013-10-15 09:33:02 +00001480 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
1481 return getSema().ActOnSEHFinallyBlock(Loc, Block);
John Wiegley28bbe4b2011-04-28 01:08:34 +00001482 }
1483
Douglas Gregorb98b1992009-08-11 05:31:07 +00001484 /// \brief Build a new expression that references a declaration.
1485 ///
1486 /// By default, performs semantic analysis to build the new expression.
1487 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001488 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001489 LookupResult &R,
1490 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001491 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1492 }
1493
1494
1495 /// \brief Build a new expression that references a declaration.
1496 ///
1497 /// By default, performs semantic analysis to build the new expression.
1498 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001499 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001500 ValueDecl *VD,
1501 const DeclarationNameInfo &NameInfo,
1502 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001503 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001504 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001505
1506 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001507
1508 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001509 }
Mike Stump1eb44332009-09-09 15:08:12 +00001510
Douglas Gregorb98b1992009-08-11 05:31:07 +00001511 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001512 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001513 /// By default, performs semantic analysis to build the new expression.
1514 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001515 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001516 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001517 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001518 }
1519
Douglas Gregora71d8192009-09-04 17:36:40 +00001520 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001521 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001522 /// By default, performs semantic analysis to build the new expression.
1523 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001524 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001525 SourceLocation OperatorLoc,
1526 bool isArrow,
1527 CXXScopeSpec &SS,
1528 TypeSourceInfo *ScopeType,
1529 SourceLocation CCLoc,
1530 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001531 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001532
Douglas Gregorb98b1992009-08-11 05:31:07 +00001533 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001534 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001535 /// By default, performs semantic analysis to build the new expression.
1536 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001537 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001538 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001539 Expr *SubExpr) {
1540 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001541 }
Mike Stump1eb44332009-09-09 15:08:12 +00001542
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001543 /// \brief Build a new builtin offsetof expression.
1544 ///
1545 /// 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 RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001548 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001549 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001550 unsigned NumComponents,
1551 SourceLocation RParenLoc) {
1552 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1553 NumComponents, RParenLoc);
1554 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001555
1556 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001557 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001558 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001559 /// By default, performs semantic analysis to build the new expression.
1560 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001561 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1562 SourceLocation OpLoc,
1563 UnaryExprOrTypeTrait ExprKind,
1564 SourceRange R) {
1565 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001566 }
1567
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001568 /// \brief Build a new sizeof, alignof or vec step expression with an
1569 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001570 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001571 /// By default, performs semantic analysis to build the new expression.
1572 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001573 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1574 UnaryExprOrTypeTrait ExprKind,
1575 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001576 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001577 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001578 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001579 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001580
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001581 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001582 }
Mike Stump1eb44332009-09-09 15:08:12 +00001583
Douglas Gregorb98b1992009-08-11 05:31:07 +00001584 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001585 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001586 /// By default, performs semantic analysis to build the new expression.
1587 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001588 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001589 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001590 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001591 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001592 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1593 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001594 RBracketLoc);
1595 }
1596
1597 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001598 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001599 /// By default, performs semantic analysis to build the new expression.
1600 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001601 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001603 SourceLocation RParenLoc,
1604 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001605 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001606 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001607 }
1608
1609 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001610 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001611 /// By default, performs semantic analysis to build the new expression.
1612 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001613 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001614 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001615 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001616 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001617 const DeclarationNameInfo &MemberNameInfo,
1618 ValueDecl *Member,
1619 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001620 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001621 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001622 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1623 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001624 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001625 // We have a reference to an unnamed field. This is always the
1626 // base of an anonymous struct/union member access, i.e. the
1627 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001628 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001629 assert(Member->getType()->isRecordType() &&
1630 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001631
Richard Smith9138b4e2011-10-26 19:06:56 +00001632 BaseResult =
1633 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001634 QualifierLoc.getNestedNameSpecifier(),
1635 FoundDecl, Member);
1636 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001637 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001638 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001639 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001640 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001641 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001642 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001643 cast<FieldDecl>(Member)->getType(),
1644 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001645 return getSema().Owned(ME);
1646 }
Mike Stump1eb44332009-09-09 15:08:12 +00001647
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001648 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001649 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001650
John Wiegley429bb272011-04-08 18:41:53 +00001651 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001652 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001653
John McCall6bb80172010-03-30 21:47:33 +00001654 // FIXME: this involves duplicating earlier analysis in a lot of
1655 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001656 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001657 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001658 R.resolveKind();
1659
John McCall9ae2f072010-08-23 23:25:46 +00001660 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001661 SS, TemplateKWLoc,
1662 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001663 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001664 }
Mike Stump1eb44332009-09-09 15:08:12 +00001665
Douglas Gregorb98b1992009-08-11 05:31:07 +00001666 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001667 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001668 /// By default, performs semantic analysis to build the new expression.
1669 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001670 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001671 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001672 Expr *LHS, Expr *RHS) {
1673 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001674 }
1675
1676 /// \brief Build a new conditional 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 RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001681 SourceLocation QuestionLoc,
1682 Expr *LHS,
1683 SourceLocation ColonLoc,
1684 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001685 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1686 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001687 }
1688
Douglas Gregorb98b1992009-08-11 05:31:07 +00001689 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001690 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001691 /// By default, performs semantic analysis to build the new expression.
1692 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001693 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001694 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001695 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001696 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001697 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001698 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001699 }
Mike Stump1eb44332009-09-09 15:08:12 +00001700
Douglas Gregorb98b1992009-08-11 05:31:07 +00001701 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001702 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001703 /// By default, performs semantic analysis to build the new expression.
1704 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001705 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001706 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001707 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001708 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001709 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001710 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001711 }
Mike Stump1eb44332009-09-09 15:08:12 +00001712
Douglas Gregorb98b1992009-08-11 05:31:07 +00001713 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001714 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001715 /// By default, performs semantic analysis to build the new expression.
1716 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001717 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 SourceLocation OpLoc,
1719 SourceLocation AccessorLoc,
1720 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001721
John McCall129e2df2009-11-30 22:42:35 +00001722 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001723 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001724 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001725 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001726 SS, SourceLocation(),
1727 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001728 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001729 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001730 }
Mike Stump1eb44332009-09-09 15:08:12 +00001731
Douglas Gregorb98b1992009-08-11 05:31:07 +00001732 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001733 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001734 /// By default, performs semantic analysis to build the new expression.
1735 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001736 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001737 MultiExprArg Inits,
1738 SourceLocation RBraceLoc,
1739 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001740 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001741 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001742 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001743 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001744
Douglas Gregore48319a2009-11-09 17:16:50 +00001745 // Patch in the result type we were given, which may have been computed
1746 // when the initial InitListExpr was built.
1747 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1748 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001749 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001750 }
Mike Stump1eb44332009-09-09 15:08:12 +00001751
Douglas Gregorb98b1992009-08-11 05:31:07 +00001752 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001753 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001754 /// By default, performs semantic analysis to build the new expression.
1755 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001756 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001757 MultiExprArg ArrayExprs,
1758 SourceLocation EqualOrColonLoc,
1759 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001760 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001761 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001762 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001763 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001764 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001765 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001766
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001767 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001768 }
Mike Stump1eb44332009-09-09 15:08:12 +00001769
Douglas Gregorb98b1992009-08-11 05:31:07 +00001770 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001771 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001772 /// By default, builds the implicit value initialization without performing
1773 /// any semantic analysis. Subclasses may override this routine to provide
1774 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001775 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001776 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1777 }
Mike Stump1eb44332009-09-09 15:08:12 +00001778
Douglas Gregorb98b1992009-08-11 05:31:07 +00001779 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001780 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001781 /// By default, performs semantic analysis to build the new expression.
1782 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001783 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001784 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001785 SourceLocation RParenLoc) {
1786 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001787 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001788 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001789 }
1790
1791 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001792 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001793 /// By default, performs semantic analysis to build the new expression.
1794 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001795 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001796 MultiExprArg SubExprs,
1797 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001798 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001799 }
Mike Stump1eb44332009-09-09 15:08:12 +00001800
Douglas Gregorb98b1992009-08-11 05:31:07 +00001801 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001802 ///
1803 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001804 /// rather than attempting to map the label statement itself.
1805 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001806 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001807 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001808 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
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 GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001812 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001813 /// By default, performs semantic analysis to build the new expression.
1814 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001815 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001816 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001817 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001818 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
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 __builtin_choose_expr expression.
1822 ///
1823 /// 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 RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001826 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001827 SourceLocation RParenLoc) {
1828 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001829 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001830 RParenLoc);
1831 }
Mike Stump1eb44332009-09-09 15:08:12 +00001832
Peter Collingbournef111d932011-04-15 00:35:48 +00001833 /// \brief Build a new generic selection expression.
1834 ///
1835 /// By default, performs semantic analysis to build the new expression.
1836 /// Subclasses may override this routine to provide different behavior.
1837 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1838 SourceLocation DefaultLoc,
1839 SourceLocation RParenLoc,
1840 Expr *ControllingExpr,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001841 ArrayRef<TypeSourceInfo *> Types,
1842 ArrayRef<Expr *> Exprs) {
Peter Collingbournef111d932011-04-15 00:35:48 +00001843 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001844 ControllingExpr, Types, Exprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00001845 }
1846
Douglas Gregorb98b1992009-08-11 05:31:07 +00001847 /// \brief Build a new overloaded operator call expression.
1848 ///
1849 /// By default, performs semantic analysis to build the new expression.
1850 /// The semantic analysis provides the behavior of template instantiation,
1851 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001852 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001853 /// argument-dependent lookup, etc. Subclasses may override this routine to
1854 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001855 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001856 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001857 Expr *Callee,
1858 Expr *First,
1859 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001860
1861 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001862 /// reinterpret_cast.
1863 ///
1864 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001865 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001866 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001867 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001868 Stmt::StmtClass Class,
1869 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001870 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001871 SourceLocation RAngleLoc,
1872 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001873 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001874 SourceLocation RParenLoc) {
1875 switch (Class) {
1876 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001877 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001878 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001879 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001880
1881 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001882 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001883 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001884 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001885
Douglas Gregorb98b1992009-08-11 05:31:07 +00001886 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001887 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001888 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001889 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001890 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001891
Douglas Gregorb98b1992009-08-11 05:31:07 +00001892 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001893 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001894 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001895 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001896
Douglas Gregorb98b1992009-08-11 05:31:07 +00001897 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001898 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001899 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001900 }
Mike Stump1eb44332009-09-09 15:08:12 +00001901
Douglas Gregorb98b1992009-08-11 05:31:07 +00001902 /// \brief Build a new C++ static_cast expression.
1903 ///
1904 /// By default, performs semantic analysis to build the new expression.
1905 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001906 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001907 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001908 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001909 SourceLocation RAngleLoc,
1910 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001911 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001912 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001913 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001914 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001915 SourceRange(LAngleLoc, RAngleLoc),
1916 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001917 }
1918
1919 /// \brief Build a new C++ dynamic_cast expression.
1920 ///
1921 /// By default, performs semantic analysis to build the new expression.
1922 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001923 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001924 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001925 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001926 SourceLocation RAngleLoc,
1927 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001928 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001929 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001930 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001931 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001932 SourceRange(LAngleLoc, RAngleLoc),
1933 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001934 }
1935
1936 /// \brief Build a new C++ reinterpret_cast expression.
1937 ///
1938 /// By default, performs semantic analysis to build the new expression.
1939 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001940 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001941 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001942 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001943 SourceLocation RAngleLoc,
1944 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001945 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001946 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001947 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001948 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001949 SourceRange(LAngleLoc, RAngleLoc),
1950 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001951 }
1952
1953 /// \brief Build a new C++ const_cast expression.
1954 ///
1955 /// By default, performs semantic analysis to build the new expression.
1956 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001957 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001958 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001959 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001960 SourceLocation RAngleLoc,
1961 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001962 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001963 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001964 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001965 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001966 SourceRange(LAngleLoc, RAngleLoc),
1967 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001968 }
Mike Stump1eb44332009-09-09 15:08:12 +00001969
Douglas Gregorb98b1992009-08-11 05:31:07 +00001970 /// \brief Build a new C++ functional-style cast expression.
1971 ///
1972 /// By default, performs semantic analysis to build the new expression.
1973 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001974 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1975 SourceLocation LParenLoc,
1976 Expr *Sub,
1977 SourceLocation RParenLoc) {
1978 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001979 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001980 RParenLoc);
1981 }
Mike Stump1eb44332009-09-09 15:08:12 +00001982
Douglas Gregorb98b1992009-08-11 05:31:07 +00001983 /// \brief Build a new C++ typeid(type) expression.
1984 ///
1985 /// By default, performs semantic analysis to build the new expression.
1986 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001987 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001988 SourceLocation TypeidLoc,
1989 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001990 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001991 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001992 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001993 }
Mike Stump1eb44332009-09-09 15:08:12 +00001994
Francois Pichet01b7c302010-09-08 12:20:18 +00001995
Douglas Gregorb98b1992009-08-11 05:31:07 +00001996 /// \brief Build a new C++ typeid(expr) expression.
1997 ///
1998 /// By default, performs semantic analysis to build the new expression.
1999 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002000 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00002001 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00002002 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002003 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002004 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00002005 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002006 }
2007
Francois Pichet01b7c302010-09-08 12:20:18 +00002008 /// \brief Build a new C++ __uuidof(type) expression.
2009 ///
2010 /// By default, performs semantic analysis to build the new expression.
2011 /// Subclasses may override this routine to provide different behavior.
2012 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2013 SourceLocation TypeidLoc,
2014 TypeSourceInfo *Operand,
2015 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002016 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00002017 RParenLoc);
2018 }
2019
2020 /// \brief Build a new C++ __uuidof(expr) expression.
2021 ///
2022 /// By default, performs semantic analysis to build the new expression.
2023 /// Subclasses may override this routine to provide different behavior.
2024 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2025 SourceLocation TypeidLoc,
2026 Expr *Operand,
2027 SourceLocation RParenLoc) {
2028 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2029 RParenLoc);
2030 }
2031
Douglas Gregorb98b1992009-08-11 05:31:07 +00002032 /// \brief Build a new C++ "this" expression.
2033 ///
2034 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00002035 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00002036 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002037 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00002038 QualType ThisType,
2039 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00002040 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002041 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00002042 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
2043 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002044 }
2045
2046 /// \brief Build a new C++ throw expression.
2047 ///
2048 /// By default, performs semantic analysis to build the new expression.
2049 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00002050 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2051 bool IsThrownVariableInScope) {
2052 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002053 }
2054
2055 /// \brief Build a new C++ default-argument expression.
2056 ///
2057 /// By default, builds a new default-argument expression, which does not
2058 /// require any semantic analysis. Subclasses may override this routine to
2059 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002060 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00002061 ParmVarDecl *Param) {
2062 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
2063 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002064 }
2065
Richard Smithc3bf52c2013-04-20 22:23:05 +00002066 /// \brief Build a new C++11 default-initialization expression.
2067 ///
2068 /// By default, builds a new default field initialization expression, which
2069 /// does not require any semantic analysis. Subclasses may override this
2070 /// routine to provide different behavior.
2071 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2072 FieldDecl *Field) {
2073 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2074 Field));
2075 }
2076
Douglas Gregorb98b1992009-08-11 05:31:07 +00002077 /// \brief Build a new C++ zero-initialization expression.
2078 ///
2079 /// By default, performs semantic analysis to build the new expression.
2080 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002081 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2082 SourceLocation LParenLoc,
2083 SourceLocation RParenLoc) {
2084 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002085 None, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002086 }
Mike Stump1eb44332009-09-09 15:08:12 +00002087
Douglas Gregorb98b1992009-08-11 05:31:07 +00002088 /// \brief Build a new C++ "new" expression.
2089 ///
2090 /// By default, performs semantic analysis to build the new expression.
2091 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002092 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002093 bool UseGlobal,
2094 SourceLocation PlacementLParen,
2095 MultiExprArg PlacementArgs,
2096 SourceLocation PlacementRParen,
2097 SourceRange TypeIdParens,
2098 QualType AllocatedType,
2099 TypeSourceInfo *AllocatedTypeInfo,
2100 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002101 SourceRange DirectInitRange,
2102 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00002103 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002104 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002105 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002106 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002107 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002108 AllocatedType,
2109 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002110 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002111 DirectInitRange,
2112 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002113 }
Mike Stump1eb44332009-09-09 15:08:12 +00002114
Douglas Gregorb98b1992009-08-11 05:31:07 +00002115 /// \brief Build a new C++ "delete" expression.
2116 ///
2117 /// By default, performs semantic analysis to build the new expression.
2118 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002119 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002120 bool IsGlobalDelete,
2121 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002122 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002123 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002124 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002125 }
Mike Stump1eb44332009-09-09 15:08:12 +00002126
Douglas Gregorb98b1992009-08-11 05:31:07 +00002127 /// \brief Build a new unary type trait expression.
2128 ///
2129 /// By default, performs semantic analysis to build the new expression.
2130 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002131 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002132 SourceLocation StartLoc,
2133 TypeSourceInfo *T,
2134 SourceLocation RParenLoc) {
2135 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002136 }
2137
Francois Pichet6ad6f282010-12-07 00:08:36 +00002138 /// \brief Build a new binary type trait expression.
2139 ///
2140 /// By default, performs semantic analysis to build the new expression.
2141 /// Subclasses may override this routine to provide different behavior.
2142 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2143 SourceLocation StartLoc,
2144 TypeSourceInfo *LhsT,
2145 TypeSourceInfo *RhsT,
2146 SourceLocation RParenLoc) {
2147 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2148 }
2149
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002150 /// \brief Build a new type trait expression.
2151 ///
2152 /// By default, performs semantic analysis to build the new expression.
2153 /// Subclasses may override this routine to provide different behavior.
2154 ExprResult RebuildTypeTrait(TypeTrait Trait,
2155 SourceLocation StartLoc,
2156 ArrayRef<TypeSourceInfo *> Args,
2157 SourceLocation RParenLoc) {
2158 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2159 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002160
John Wiegley21ff2e52011-04-28 00:16:57 +00002161 /// \brief Build a new array type trait expression.
2162 ///
2163 /// By default, performs semantic analysis to build the new expression.
2164 /// Subclasses may override this routine to provide different behavior.
2165 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2166 SourceLocation StartLoc,
2167 TypeSourceInfo *TSInfo,
2168 Expr *DimExpr,
2169 SourceLocation RParenLoc) {
2170 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2171 }
2172
John Wiegley55262202011-04-25 06:54:41 +00002173 /// \brief Build a new expression trait expression.
2174 ///
2175 /// By default, performs semantic analysis to build the new expression.
2176 /// Subclasses may override this routine to provide different behavior.
2177 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2178 SourceLocation StartLoc,
2179 Expr *Queried,
2180 SourceLocation RParenLoc) {
2181 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2182 }
2183
Mike Stump1eb44332009-09-09 15:08:12 +00002184 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002185 /// expression.
2186 ///
2187 /// By default, performs semantic analysis to build the new expression.
2188 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002189 ExprResult RebuildDependentScopeDeclRefExpr(
2190 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002191 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002192 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002193 const TemplateArgumentListInfo *TemplateArgs,
2194 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002195 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002196 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002197
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002198 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002199 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002200 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002201
Richard Smithefeeccf2012-10-21 03:28:35 +00002202 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2203 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002204 }
2205
2206 /// \brief Build a new template-id expression.
2207 ///
2208 /// By default, performs semantic analysis to build the new expression.
2209 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002210 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002211 SourceLocation TemplateKWLoc,
2212 LookupResult &R,
2213 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002214 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002215 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2216 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002217 }
2218
2219 /// \brief Build a new object-construction expression.
2220 ///
2221 /// By default, performs semantic analysis to build the new expression.
2222 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002223 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002224 SourceLocation Loc,
2225 CXXConstructorDecl *Constructor,
2226 bool IsElidable,
2227 MultiExprArg Args,
2228 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002229 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002230 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002231 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002232 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002233 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002234 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002235 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002236 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002237
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002238 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002239 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002240 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002241 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002242 RequiresZeroInit, ConstructKind,
2243 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002244 }
2245
2246 /// \brief Build a new object-construction expression.
2247 ///
2248 /// By default, performs semantic analysis to build the new expression.
2249 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002250 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2251 SourceLocation LParenLoc,
2252 MultiExprArg Args,
2253 SourceLocation RParenLoc) {
2254 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002255 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002256 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002257 RParenLoc);
2258 }
2259
2260 /// \brief Build a new object-construction expression.
2261 ///
2262 /// By default, performs semantic analysis to build the new expression.
2263 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002264 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2265 SourceLocation LParenLoc,
2266 MultiExprArg Args,
2267 SourceLocation RParenLoc) {
2268 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002269 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002270 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002271 RParenLoc);
2272 }
Mike Stump1eb44332009-09-09 15:08:12 +00002273
Douglas Gregorb98b1992009-08-11 05:31:07 +00002274 /// \brief Build a new member reference expression.
2275 ///
2276 /// By default, performs semantic analysis to build the new expression.
2277 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002278 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002279 QualType BaseType,
2280 bool IsArrow,
2281 SourceLocation OperatorLoc,
2282 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002283 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002284 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002285 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002286 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002287 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002288 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002289
John McCall9ae2f072010-08-23 23:25:46 +00002290 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002291 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002292 SS, TemplateKWLoc,
2293 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002294 MemberNameInfo,
2295 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002296 }
2297
John McCall129e2df2009-11-30 22:42:35 +00002298 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002299 ///
2300 /// By default, performs semantic analysis to build the new expression.
2301 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002302 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2303 SourceLocation OperatorLoc,
2304 bool IsArrow,
2305 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002306 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002307 NamedDecl *FirstQualifierInScope,
2308 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002309 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002310 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002311 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002312
John McCall9ae2f072010-08-23 23:25:46 +00002313 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002314 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002315 SS, TemplateKWLoc,
2316 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002317 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002318 }
Mike Stump1eb44332009-09-09 15:08:12 +00002319
Sebastian Redl2e156222010-09-10 20:55:43 +00002320 /// \brief Build a new noexcept expression.
2321 ///
2322 /// By default, performs semantic analysis to build the new expression.
2323 /// Subclasses may override this routine to provide different behavior.
2324 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2325 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2326 }
2327
Douglas Gregoree8aff02011-01-04 17:33:58 +00002328 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002329 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2330 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002331 SourceLocation RParenLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002332 Optional<unsigned> Length) {
Douglas Gregor089e8932011-10-10 18:59:29 +00002333 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002334 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2335 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002336 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002337
2338 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2339 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002340 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002341 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002342
Patrick Beardeb382ec2012-04-19 00:25:12 +00002343 /// \brief Build a new Objective-C boxed expression.
2344 ///
2345 /// By default, performs semantic analysis to build the new expression.
2346 /// Subclasses may override this routine to provide different behavior.
2347 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2348 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2349 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002350
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002351 /// \brief Build a new Objective-C array literal.
2352 ///
2353 /// By default, performs semantic analysis to build the new expression.
2354 /// Subclasses may override this routine to provide different behavior.
2355 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2356 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002357 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002358 MultiExprArg(Elements, NumElements));
2359 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002360
2361 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002362 Expr *Base, Expr *Key,
2363 ObjCMethodDecl *getterMethod,
2364 ObjCMethodDecl *setterMethod) {
2365 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2366 getterMethod, setterMethod);
2367 }
2368
2369 /// \brief Build a new Objective-C dictionary literal.
2370 ///
2371 /// By default, performs semantic analysis to build the new expression.
2372 /// Subclasses may override this routine to provide different behavior.
2373 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2374 ObjCDictionaryElement *Elements,
2375 unsigned NumElements) {
2376 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2377 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002378
James Dennett699c9042012-06-15 07:13:21 +00002379 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002380 ///
2381 /// By default, performs semantic analysis to build the new expression.
2382 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002383 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002384 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002385 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002386 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002387 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002388 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002389
Douglas Gregor92e986e2010-04-22 16:44:27 +00002390 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002391 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002392 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002393 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002394 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002395 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002396 MultiExprArg Args,
2397 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002398 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2399 ReceiverTypeInfo->getType(),
2400 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002401 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002402 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002403 }
2404
2405 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002406 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002407 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002408 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002409 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002410 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002411 MultiExprArg Args,
2412 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002413 return SemaRef.BuildInstanceMessage(Receiver,
2414 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002415 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002416 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002417 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002418 }
2419
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002420 /// \brief Build a new Objective-C ivar reference expression.
2421 ///
2422 /// By default, performs semantic analysis to build the new expression.
2423 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002424 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002425 SourceLocation IvarLoc,
2426 bool IsArrow, bool IsFreeIvar) {
2427 // FIXME: We lose track of the IsFreeIvar bit.
2428 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002429 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002430 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2431 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002432 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002433 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002434 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002435 false);
John Wiegley429bb272011-04-08 18:41:53 +00002436 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002437 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002438
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002439 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002440 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002441
John Wiegley429bb272011-04-08 18:41:53 +00002442 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002443 /*FIXME:*/IvarLoc, IsArrow,
2444 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002445 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002446 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002447 /*TemplateArgs=*/0);
2448 }
Douglas Gregore3303542010-04-26 20:47:02 +00002449
2450 /// \brief Build a new Objective-C property reference expression.
2451 ///
2452 /// By default, performs semantic analysis to build the new expression.
2453 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002454 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002455 ObjCPropertyDecl *Property,
2456 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002457 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002458 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002459 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2460 Sema::LookupMemberName);
2461 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002462 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002463 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002464 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002465 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002466 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002467
Douglas Gregore3303542010-04-26 20:47:02 +00002468 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002469 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002470
John Wiegley429bb272011-04-08 18:41:53 +00002471 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002472 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002473 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002474 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002475 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002476 /*TemplateArgs=*/0);
2477 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002478
John McCall12f78a62010-12-02 01:19:52 +00002479 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002480 ///
2481 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002482 /// Subclasses may override this routine to provide different behavior.
2483 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2484 ObjCMethodDecl *Getter,
2485 ObjCMethodDecl *Setter,
2486 SourceLocation PropertyLoc) {
2487 // Since these expressions can only be value-dependent, we do not
2488 // need to perform semantic analysis again.
2489 return Owned(
2490 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2491 VK_LValue, OK_ObjCProperty,
2492 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002493 }
2494
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002495 /// \brief Build a new Objective-C "isa" expression.
2496 ///
2497 /// By default, performs semantic analysis to build the new expression.
2498 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002499 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002500 SourceLocation OpLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002501 bool IsArrow) {
2502 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002503 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002504 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2505 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002506 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002507 OpLoc,
John McCalld226f652010-08-21 09:40:31 +00002508 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002509 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002510 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002511
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002512 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002513 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002514
John Wiegley429bb272011-04-08 18:41:53 +00002515 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002516 OpLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002517 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002518 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002519 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002520 /*TemplateArgs=*/0);
2521 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002522
Douglas Gregorb98b1992009-08-11 05:31:07 +00002523 /// \brief Build a new shuffle vector expression.
2524 ///
2525 /// By default, performs semantic analysis to build the new expression.
2526 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002527 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002528 MultiExprArg SubExprs,
2529 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002530 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002531 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002532 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2533 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2534 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002535 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002536
Douglas Gregorb98b1992009-08-11 05:31:07 +00002537 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002538 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002539 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2540 SemaRef.Context.BuiltinFnTy,
2541 VK_RValue, BuiltinLoc);
2542 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2543 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2544 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002545
2546 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002547 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002548 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002549 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002550 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002551 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002552
Douglas Gregorb98b1992009-08-11 05:31:07 +00002553 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002554 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002555 }
John McCall43fed0d2010-11-12 08:19:04 +00002556
Hal Finkel414a1bd2013-09-18 03:29:45 +00002557 /// \brief Build a new convert vector expression.
2558 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2559 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2560 SourceLocation RParenLoc) {
2561 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2562 BuiltinLoc, RParenLoc);
2563 }
2564
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002565 /// \brief Build a new template argument pack expansion.
2566 ///
2567 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002568 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002569 /// different behavior.
2570 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002571 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002572 Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002573 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002574 case TemplateArgument::Expression: {
2575 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002576 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2577 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002578 if (Result.isInvalid())
2579 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002580
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002581 return TemplateArgumentLoc(Result.get(), Result.get());
2582 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002583
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002584 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002585 return TemplateArgumentLoc(TemplateArgument(
2586 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002587 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002588 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002589 Pattern.getTemplateNameLoc(),
2590 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002591
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002592 case TemplateArgument::Null:
2593 case TemplateArgument::Integral:
2594 case TemplateArgument::Declaration:
2595 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002596 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002597 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002598 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002599
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002600 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002601 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002602 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002603 EllipsisLoc,
2604 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002605 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2606 Expansion);
2607 break;
2608 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002609
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002610 return TemplateArgumentLoc();
2611 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002612
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002613 /// \brief Build a new expression pack expansion.
2614 ///
2615 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002616 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002617 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002618 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002619 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002620 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002621 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002622
2623 /// \brief Build a new atomic operation expression.
2624 ///
2625 /// By default, performs semantic analysis to build the new expression.
2626 /// Subclasses may override this routine to provide different behavior.
2627 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2628 MultiExprArg SubExprs,
2629 QualType RetTy,
2630 AtomicExpr::AtomicOp Op,
2631 SourceLocation RParenLoc) {
2632 // Just create the expression; there is not any interesting semantic
2633 // analysis here because we can't actually build an AtomicExpr until
2634 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002635 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002636 RParenLoc);
2637 }
2638
John McCall43fed0d2010-11-12 08:19:04 +00002639private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002640 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2641 QualType ObjectType,
2642 NamedDecl *FirstQualifierInScope,
2643 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002644
2645 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2646 QualType ObjectType,
2647 NamedDecl *FirstQualifierInScope,
2648 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002649};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002650
Douglas Gregor43959a92009-08-20 07:17:43 +00002651template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002652StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002653 if (!S)
2654 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002655
Douglas Gregor43959a92009-08-20 07:17:43 +00002656 switch (S->getStmtClass()) {
2657 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002658
Douglas Gregor43959a92009-08-20 07:17:43 +00002659 // Transform individual statement nodes
2660#define STMT(Node, Parent) \
2661 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002662#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002663#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002664#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002665
Douglas Gregor43959a92009-08-20 07:17:43 +00002666 // Transform expressions by calling TransformExpr.
2667#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002668#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002669#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002670#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002671 {
John McCall60d7b3a2010-08-24 06:29:42 +00002672 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002673 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002674 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002675
Richard Smith41956372013-01-14 22:39:08 +00002676 return getSema().ActOnExprStmt(E);
Douglas Gregor43959a92009-08-20 07:17:43 +00002677 }
Mike Stump1eb44332009-09-09 15:08:12 +00002678 }
2679
John McCall3fa5cae2010-10-26 07:05:15 +00002680 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002681}
Mike Stump1eb44332009-09-09 15:08:12 +00002682
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00002683template<typename Derived>
2684OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2685 if (!S)
2686 return S;
2687
2688 switch (S->getClauseKind()) {
2689 default: break;
2690 // Transform individual clause nodes
2691#define OPENMP_CLAUSE(Name, Class) \
2692 case OMPC_ ## Name : \
2693 return getDerived().Transform ## Class(cast<Class>(S));
2694#include "clang/Basic/OpenMPKinds.def"
2695 }
2696
2697 return S;
2698}
2699
Mike Stump1eb44332009-09-09 15:08:12 +00002700
Douglas Gregor670444e2009-08-04 22:27:00 +00002701template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002702ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002703 if (!E)
2704 return SemaRef.Owned(E);
2705
2706 switch (E->getStmtClass()) {
2707 case Stmt::NoStmtClass: break;
2708#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002709#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002710#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002711 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002712#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002713 }
2714
John McCall3fa5cae2010-10-26 07:05:15 +00002715 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002716}
2717
2718template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002719ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2720 bool CXXDirectInit) {
2721 // Initializers are instantiated like expressions, except that various outer
2722 // layers are stripped.
2723 if (!Init)
2724 return SemaRef.Owned(Init);
2725
2726 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2727 Init = ExprTemp->getSubExpr();
2728
Richard Smith858c2c32013-05-30 22:40:16 +00002729 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2730 Init = MTE->GetTemporaryExpr();
2731
Richard Smithc83c2302012-12-19 01:39:02 +00002732 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2733 Init = Binder->getSubExpr();
2734
2735 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2736 Init = ICE->getSubExprAsWritten();
2737
Richard Smith7c3e6152013-06-12 22:31:48 +00002738 if (CXXStdInitializerListExpr *ILE =
2739 dyn_cast<CXXStdInitializerListExpr>(Init))
2740 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2741
Richard Smith5cf15892012-12-21 08:13:35 +00002742 // If this is not a direct-initializer, we only need to reconstruct
2743 // InitListExprs. Other forms of copy-initialization will be a no-op if
2744 // the initializer is already the right type.
2745 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2746 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2747 return getDerived().TransformExpr(Init);
2748
2749 // Revert value-initialization back to empty parens.
2750 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2751 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002752 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002753 Parens.getEnd());
2754 }
2755
2756 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2757 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002758 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002759 SourceLocation());
2760
2761 // Revert initialization by constructor back to a parenthesized or braced list
2762 // of expressions. Any other form of initializer can just be reused directly.
2763 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002764 return getDerived().TransformExpr(Init);
2765
2766 SmallVector<Expr*, 8> NewArgs;
2767 bool ArgChanged = false;
2768 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2769 /*IsCall*/true, NewArgs, &ArgChanged))
2770 return ExprError();
2771
2772 // If this was list initialization, revert to list form.
2773 if (Construct->isListInitialization())
2774 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2775 Construct->getLocEnd(),
2776 Construct->getType());
2777
Richard Smithc83c2302012-12-19 01:39:02 +00002778 // Build a ParenListExpr to represent anything else.
Enea Zaffanella1245a542013-09-07 05:49:53 +00002779 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smithc83c2302012-12-19 01:39:02 +00002780 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2781 Parens.getEnd());
2782}
2783
2784template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002785bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2786 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002787 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002788 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002789 bool *ArgChanged) {
2790 for (unsigned I = 0; I != NumInputs; ++I) {
2791 // If requested, drop call arguments that need to be dropped.
2792 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2793 if (ArgChanged)
2794 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002795
Douglas Gregoraa165f82011-01-03 19:04:46 +00002796 break;
2797 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002798
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002799 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2800 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002801
Chris Lattner686775d2011-07-20 06:58:45 +00002802 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002803 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2804 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002805
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002806 // Determine whether the set of unexpanded parameter packs can and should
2807 // be expanded.
2808 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002809 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00002810 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2811 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002812 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2813 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002814 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002815 Expand, RetainExpansion,
2816 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002817 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002818
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002819 if (!Expand) {
2820 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002821 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002822 // expansion.
2823 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2824 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2825 if (OutPattern.isInvalid())
2826 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002827
2828 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002829 Expansion->getEllipsisLoc(),
2830 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002831 if (Out.isInvalid())
2832 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002833
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002834 if (ArgChanged)
2835 *ArgChanged = true;
2836 Outputs.push_back(Out.get());
2837 continue;
2838 }
John McCallc8fc90a2011-07-06 07:30:07 +00002839
2840 // Record right away that the argument was changed. This needs
2841 // to happen even if the array expands to nothing.
2842 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002843
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002844 // The transform has determined that we should perform an elementwise
2845 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002846 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002847 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2848 ExprResult Out = getDerived().TransformExpr(Pattern);
2849 if (Out.isInvalid())
2850 return true;
2851
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002852 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002853 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2854 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002855 if (Out.isInvalid())
2856 return true;
2857 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002858
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002859 Outputs.push_back(Out.get());
2860 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002861
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002862 continue;
2863 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002864
Richard Smithc83c2302012-12-19 01:39:02 +00002865 ExprResult Result =
2866 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2867 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002868 if (Result.isInvalid())
2869 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002870
Douglas Gregoraa165f82011-01-03 19:04:46 +00002871 if (Result.get() != Inputs[I] && ArgChanged)
2872 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002873
2874 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002875 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002876
Douglas Gregoraa165f82011-01-03 19:04:46 +00002877 return false;
2878}
2879
2880template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002881NestedNameSpecifierLoc
2882TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2883 NestedNameSpecifierLoc NNS,
2884 QualType ObjectType,
2885 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002886 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002887 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002888 Qualifier = Qualifier.getPrefix())
2889 Qualifiers.push_back(Qualifier);
2890
2891 CXXScopeSpec SS;
2892 while (!Qualifiers.empty()) {
2893 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2894 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002895
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002896 switch (QNNS->getKind()) {
2897 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002898 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002899 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002900 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002901 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002902 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002903 FirstQualifierInScope, false))
2904 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002905
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002906 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002907
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002908 case NestedNameSpecifier::Namespace: {
2909 NamespaceDecl *NS
2910 = cast_or_null<NamespaceDecl>(
2911 getDerived().TransformDecl(
2912 Q.getLocalBeginLoc(),
2913 QNNS->getAsNamespace()));
2914 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2915 break;
2916 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002917
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002918 case NestedNameSpecifier::NamespaceAlias: {
2919 NamespaceAliasDecl *Alias
2920 = cast_or_null<NamespaceAliasDecl>(
2921 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2922 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002923 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002924 Q.getLocalEndLoc());
2925 break;
2926 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002927
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002928 case NestedNameSpecifier::Global:
2929 // There is no meaningful transformation that one could perform on the
2930 // global scope.
2931 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2932 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002933
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002934 case NestedNameSpecifier::TypeSpecWithTemplate:
2935 case NestedNameSpecifier::TypeSpec: {
2936 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2937 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002938
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002939 if (!TL)
2940 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002941
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002942 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002943 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002944 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002945 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002946 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002947 if (TL.getType()->isEnumeralType())
2948 SemaRef.Diag(TL.getBeginLoc(),
2949 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002950 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2951 Q.getLocalEndLoc());
2952 break;
2953 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002954 // If the nested-name-specifier is an invalid type def, don't emit an
2955 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002956 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2957 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002958 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002959 << TL.getType() << SS.getRange();
2960 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002961 return NestedNameSpecifierLoc();
2962 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002963 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002964
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002965 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002966 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002967 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002968 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002969
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002970 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002971 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002972 !getDerived().AlwaysRebuild())
2973 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002974
2975 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002976 // nested-name-specifier, do so.
2977 if (SS.location_size() == NNS.getDataLength() &&
2978 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2979 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2980
2981 // Allocate new nested-name-specifier location information.
2982 return SS.getWithLocInContext(SemaRef.Context);
2983}
2984
2985template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002986DeclarationNameInfo
2987TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002988::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002989 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002990 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002991 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002992
2993 switch (Name.getNameKind()) {
2994 case DeclarationName::Identifier:
2995 case DeclarationName::ObjCZeroArgSelector:
2996 case DeclarationName::ObjCOneArgSelector:
2997 case DeclarationName::ObjCMultiArgSelector:
2998 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002999 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00003000 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00003001 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00003002
Douglas Gregor81499bb2009-09-03 22:13:48 +00003003 case DeclarationName::CXXConstructorName:
3004 case DeclarationName::CXXDestructorName:
3005 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00003006 TypeSourceInfo *NewTInfo;
3007 CanQualType NewCanTy;
3008 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00003009 NewTInfo = getDerived().TransformType(OldTInfo);
3010 if (!NewTInfo)
3011 return DeclarationNameInfo();
3012 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00003013 }
3014 else {
3015 NewTInfo = 0;
3016 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00003017 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00003018 if (NewT.isNull())
3019 return DeclarationNameInfo();
3020 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3021 }
Mike Stump1eb44332009-09-09 15:08:12 +00003022
Abramo Bagnara25777432010-08-11 22:01:17 +00003023 DeclarationName NewName
3024 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3025 NewCanTy);
3026 DeclarationNameInfo NewNameInfo(NameInfo);
3027 NewNameInfo.setName(NewName);
3028 NewNameInfo.setNamedTypeInfo(NewTInfo);
3029 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00003030 }
Mike Stump1eb44332009-09-09 15:08:12 +00003031 }
3032
David Blaikieb219cfc2011-09-23 05:06:16 +00003033 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00003034}
3035
3036template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003037TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003038TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3039 TemplateName Name,
3040 SourceLocation NameLoc,
3041 QualType ObjectType,
3042 NamedDecl *FirstQualifierInScope) {
3043 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3044 TemplateDecl *Template = QTN->getTemplateDecl();
3045 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003046
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003047 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003048 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003049 Template));
3050 if (!TransTemplate)
3051 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003052
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003053 if (!getDerived().AlwaysRebuild() &&
3054 SS.getScopeRep() == QTN->getQualifier() &&
3055 TransTemplate == Template)
3056 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003057
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003058 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3059 TransTemplate);
3060 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003061
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003062 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3063 if (SS.getScopeRep()) {
3064 // These apply to the scope specifier, not the template.
3065 ObjectType = QualType();
3066 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003067 }
3068
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003069 if (!getDerived().AlwaysRebuild() &&
3070 SS.getScopeRep() == DTN->getQualifier() &&
3071 ObjectType.isNull())
3072 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003073
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003074 if (DTN->isIdentifier()) {
3075 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003076 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003077 NameLoc,
3078 ObjectType,
3079 FirstQualifierInScope);
3080 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003081
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003082 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3083 ObjectType);
3084 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003085
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003086 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3087 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00003088 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003089 Template));
3090 if (!TransTemplate)
3091 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003092
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003093 if (!getDerived().AlwaysRebuild() &&
3094 TransTemplate == Template)
3095 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003096
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003097 return TemplateName(TransTemplate);
3098 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003099
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003100 if (SubstTemplateTemplateParmPackStorage *SubstPack
3101 = Name.getAsSubstTemplateTemplateParmPack()) {
3102 TemplateTemplateParmDecl *TransParam
3103 = cast_or_null<TemplateTemplateParmDecl>(
3104 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3105 if (!TransParam)
3106 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003107
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003108 if (!getDerived().AlwaysRebuild() &&
3109 TransParam == SubstPack->getParameterPack())
3110 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003111
3112 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003113 SubstPack->getArgumentPack());
3114 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003115
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003116 // These should be getting filtered out before they reach the AST.
3117 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003118}
3119
3120template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003121void TreeTransform<Derived>::InventTemplateArgumentLoc(
3122 const TemplateArgument &Arg,
3123 TemplateArgumentLoc &Output) {
3124 SourceLocation Loc = getDerived().getBaseLocation();
3125 switch (Arg.getKind()) {
3126 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003127 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00003128 break;
3129
3130 case TemplateArgument::Type:
3131 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00003132 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00003133
John McCall833ca992009-10-29 08:12:44 +00003134 break;
3135
Douglas Gregor788cd062009-11-11 01:00:40 +00003136 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003137 case TemplateArgument::TemplateExpansion: {
3138 NestedNameSpecifierLocBuilder Builder;
3139 TemplateName Template = Arg.getAsTemplate();
3140 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3141 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3142 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3143 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003144
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003145 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003146 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003147 Builder.getWithLocInContext(SemaRef.Context),
3148 Loc);
3149 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003150 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003151 Builder.getWithLocInContext(SemaRef.Context),
3152 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003153
Douglas Gregor788cd062009-11-11 01:00:40 +00003154 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003155 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003156
John McCall833ca992009-10-29 08:12:44 +00003157 case TemplateArgument::Expression:
3158 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3159 break;
3160
3161 case TemplateArgument::Declaration:
3162 case TemplateArgument::Integral:
3163 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003164 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003165 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003166 break;
3167 }
3168}
3169
3170template<typename Derived>
3171bool TreeTransform<Derived>::TransformTemplateArgument(
3172 const TemplateArgumentLoc &Input,
3173 TemplateArgumentLoc &Output) {
3174 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003175 switch (Arg.getKind()) {
3176 case TemplateArgument::Null:
3177 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003178 case TemplateArgument::Pack:
3179 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003180 case TemplateArgument::NullPtr:
3181 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003182
Douglas Gregor670444e2009-08-04 22:27:00 +00003183 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003184 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003185 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003186 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003187
3188 DI = getDerived().TransformType(DI);
3189 if (!DI) return true;
3190
3191 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3192 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003193 }
Mike Stump1eb44332009-09-09 15:08:12 +00003194
Douglas Gregor788cd062009-11-11 01:00:40 +00003195 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003196 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3197 if (QualifierLoc) {
3198 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3199 if (!QualifierLoc)
3200 return true;
3201 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003202
Douglas Gregor1d752d72011-03-02 18:46:51 +00003203 CXXScopeSpec SS;
3204 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003205 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003206 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3207 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003208 if (Template.isNull())
3209 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003210
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003211 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003212 Input.getTemplateNameLoc());
3213 return false;
3214 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003215
3216 case TemplateArgument::TemplateExpansion:
3217 llvm_unreachable("Caller should expand pack expansions");
3218
Douglas Gregor670444e2009-08-04 22:27:00 +00003219 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003220 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003221 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003222 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003223
John McCall833ca992009-10-29 08:12:44 +00003224 Expr *InputExpr = Input.getSourceExpression();
3225 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3226
Chris Lattner223de242011-04-25 20:37:58 +00003227 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003228 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003229 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003230 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003231 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003232 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003233 }
Mike Stump1eb44332009-09-09 15:08:12 +00003234
Douglas Gregor670444e2009-08-04 22:27:00 +00003235 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003236 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003237}
3238
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003239/// \brief Iterator adaptor that invents template argument location information
3240/// for each of the template arguments in its underlying iterator.
3241template<typename Derived, typename InputIterator>
3242class TemplateArgumentLocInventIterator {
3243 TreeTransform<Derived> &Self;
3244 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003245
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003246public:
3247 typedef TemplateArgumentLoc value_type;
3248 typedef TemplateArgumentLoc reference;
3249 typedef typename std::iterator_traits<InputIterator>::difference_type
3250 difference_type;
3251 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003252
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003253 class pointer {
3254 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003255
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003256 public:
3257 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003258
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003259 const TemplateArgumentLoc *operator->() const { return &Arg; }
3260 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003261
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003262 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003263
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003264 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3265 InputIterator Iter)
3266 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003267
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003268 TemplateArgumentLocInventIterator &operator++() {
3269 ++Iter;
3270 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003271 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003272
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003273 TemplateArgumentLocInventIterator operator++(int) {
3274 TemplateArgumentLocInventIterator Old(*this);
3275 ++(*this);
3276 return Old;
3277 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003278
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003279 reference operator*() const {
3280 TemplateArgumentLoc Result;
3281 Self.InventTemplateArgumentLoc(*Iter, Result);
3282 return Result;
3283 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003284
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003285 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003286
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003287 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3288 const TemplateArgumentLocInventIterator &Y) {
3289 return X.Iter == Y.Iter;
3290 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003291
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003292 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3293 const TemplateArgumentLocInventIterator &Y) {
3294 return X.Iter != Y.Iter;
3295 }
3296};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003297
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003298template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003299template<typename InputIterator>
3300bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3301 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003302 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003303 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003304 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003305 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003306
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003307 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3308 // Unpack argument packs, which we translate them into separate
3309 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003310 // FIXME: We could do much better if we could guarantee that the
3311 // TemplateArgumentLocInfo for the pack expansion would be usable for
3312 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003313 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003314 TemplateArgument::pack_iterator>
3315 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003316 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003317 In.getArgument().pack_begin()),
3318 PackLocIterator(*this,
3319 In.getArgument().pack_end()),
3320 Outputs))
3321 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003322
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003323 continue;
3324 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003325
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003326 if (In.getArgument().isPackExpansion()) {
3327 // We have a pack expansion, for which we will be substituting into
3328 // the pattern.
3329 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003330 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003331 TemplateArgumentLoc Pattern
Eli Friedman850cf512013-06-20 04:11:21 +00003332 = getSema().getTemplateArgumentPackExpansionPattern(
3333 In, Ellipsis, OrigNumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003334
Chris Lattner686775d2011-07-20 06:58:45 +00003335 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003336 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3337 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003338
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003339 // Determine whether the set of unexpanded parameter packs can and should
3340 // be expanded.
3341 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003342 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003343 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003344 if (getDerived().TryExpandParameterPacks(Ellipsis,
3345 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003346 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003347 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003348 RetainExpansion,
3349 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003350 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003351
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003352 if (!Expand) {
3353 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003354 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003355 // expansion.
3356 TemplateArgumentLoc OutPattern;
3357 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3358 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3359 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003360
Douglas Gregorcded4f62011-01-14 17:04:44 +00003361 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3362 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003363 if (Out.getArgument().isNull())
3364 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003365
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003366 Outputs.addArgument(Out);
3367 continue;
3368 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003369
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003370 // The transform has determined that we should perform an elementwise
3371 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003372 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003373 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3374
3375 if (getDerived().TransformTemplateArgument(Pattern, Out))
3376 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003377
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003378 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003379 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3380 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003381 if (Out.getArgument().isNull())
3382 return true;
3383 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003384
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003385 Outputs.addArgument(Out);
3386 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003387
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003388 // If we're supposed to retain a pack expansion, do so by temporarily
3389 // forgetting the partially-substituted parameter pack.
3390 if (RetainExpansion) {
3391 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003392
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003393 if (getDerived().TransformTemplateArgument(Pattern, Out))
3394 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003395
Douglas Gregorcded4f62011-01-14 17:04:44 +00003396 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3397 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003398 if (Out.getArgument().isNull())
3399 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003400
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003401 Outputs.addArgument(Out);
3402 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003403
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003404 continue;
3405 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003406
3407 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003408 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003409 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003410
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003411 Outputs.addArgument(Out);
3412 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003413
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003414 return false;
3415
3416}
3417
Douglas Gregor577f75a2009-08-04 16:50:30 +00003418//===----------------------------------------------------------------------===//
3419// Type transformation
3420//===----------------------------------------------------------------------===//
3421
3422template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003423QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003424 if (getDerived().AlreadyTransformed(T))
3425 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003426
John McCalla2becad2009-10-21 00:40:46 +00003427 // Temporary workaround. All of these transformations should
3428 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003429 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3430 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003431
John McCall43fed0d2010-11-12 08:19:04 +00003432 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003433
John McCalla2becad2009-10-21 00:40:46 +00003434 if (!NewDI)
3435 return QualType();
3436
3437 return NewDI->getType();
3438}
3439
3440template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003441TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003442 // Refine the base location to the type's location.
3443 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3444 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003445 if (getDerived().AlreadyTransformed(DI->getType()))
3446 return DI;
3447
3448 TypeLocBuilder TLB;
3449
3450 TypeLoc TL = DI->getTypeLoc();
3451 TLB.reserve(TL.getFullDataSize());
3452
John McCall43fed0d2010-11-12 08:19:04 +00003453 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003454 if (Result.isNull())
3455 return 0;
3456
John McCalla93c9342009-12-07 02:54:59 +00003457 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003458}
3459
3460template<typename Derived>
3461QualType
John McCall43fed0d2010-11-12 08:19:04 +00003462TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003463 switch (T.getTypeLocClass()) {
3464#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003465#define TYPELOC(CLASS, PARENT) \
3466 case TypeLoc::CLASS: \
3467 return getDerived().Transform##CLASS##Type(TLB, \
3468 T.castAs<CLASS##TypeLoc>());
John McCalla2becad2009-10-21 00:40:46 +00003469#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003470 }
Mike Stump1eb44332009-09-09 15:08:12 +00003471
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003472 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003473}
3474
3475/// FIXME: By default, this routine adds type qualifiers only to types
3476/// that can have qualifiers, and silently suppresses those qualifiers
3477/// that are not permitted (e.g., qualifiers on reference or function
3478/// types). This is the right thing for template instantiation, but
3479/// probably not for other clients.
3480template<typename Derived>
3481QualType
3482TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003483 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003484 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003485
John McCall43fed0d2010-11-12 08:19:04 +00003486 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003487 if (Result.isNull())
3488 return QualType();
3489
3490 // Silently suppress qualifiers if the result type can't be qualified.
3491 // FIXME: this is the right thing for template instantiation, but
3492 // probably not for other clients.
3493 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003494 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003495
John McCallf85e1932011-06-15 23:02:42 +00003496 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003497 // resulting type.
3498 if (Quals.hasObjCLifetime()) {
3499 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3500 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003501 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003502 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003503 // A lifetime qualifier applied to a substituted template parameter
3504 // overrides the lifetime qualifier from the template argument.
Douglas Gregor92d13872013-01-17 23:59:28 +00003505 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003506 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003507 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3508 QualType Replacement = SubstTypeParam->getReplacementType();
3509 Qualifiers Qs = Replacement.getQualifiers();
3510 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003511 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003512 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3513 Qs);
3514 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003515 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003516 Replacement);
3517 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003518 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3519 // 'auto' types behave the same way as template parameters.
3520 QualType Deduced = AutoTy->getDeducedType();
3521 Qualifiers Qs = Deduced.getQualifiers();
3522 Qs.removeObjCLifetime();
3523 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3524 Qs);
Faisal Valifad9e132013-09-26 19:54:12 +00003525 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3526 AutoTy->isDependentType());
Douglas Gregor92d13872013-01-17 23:59:28 +00003527 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003528 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003529 // Otherwise, complain about the addition of a qualifier to an
3530 // already-qualified type.
Eli Friedman44ee0a72013-06-07 20:31:48 +00003531 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003532 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003533 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003534
Douglas Gregore559ca12011-06-17 22:11:49 +00003535 Quals.removeObjCLifetime();
3536 }
3537 }
3538 }
John McCall28654742010-06-05 06:41:15 +00003539 if (!Quals.empty()) {
3540 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smith9807a2e2013-03-27 23:36:39 +00003541 // BuildQualifiedType might not add qualifiers if they are invalid.
3542 if (Result.hasLocalQualifiers())
3543 TLB.push<QualifiedTypeLoc>(Result);
John McCall28654742010-06-05 06:41:15 +00003544 // No location information to preserve.
3545 }
John McCalla2becad2009-10-21 00:40:46 +00003546
3547 return Result;
3548}
3549
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003550template<typename Derived>
3551TypeLoc
3552TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3553 QualType ObjectType,
3554 NamedDecl *UnqualLookup,
3555 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003556 QualType T = TL.getType();
3557 if (getDerived().AlreadyTransformed(T))
3558 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003559
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003560 TypeLocBuilder TLB;
3561 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003562
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003563 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003564 TemplateSpecializationTypeLoc SpecTL =
3565 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003566
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003567 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003568 getDerived().TransformTemplateName(SS,
3569 SpecTL.getTypePtr()->getTemplateName(),
3570 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003571 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003572 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003573 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003574
3575 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003576 Template);
3577 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003578 DependentTemplateSpecializationTypeLoc SpecTL =
3579 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003580
Douglas Gregora88f09f2011-02-28 17:23:35 +00003581 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003582 = getDerived().RebuildTemplateName(SS,
3583 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003584 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003585 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003586 if (Template.isNull())
3587 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003588
3589 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003590 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003591 Template,
3592 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003593 } else {
3594 // Nothing special needs to be done for these.
3595 Result = getDerived().TransformType(TLB, TL);
3596 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003597
3598 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003599 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003600
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003601 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3602}
3603
Douglas Gregorb71d8212011-03-02 18:32:08 +00003604template<typename Derived>
3605TypeSourceInfo *
3606TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3607 QualType ObjectType,
3608 NamedDecl *UnqualLookup,
3609 CXXScopeSpec &SS) {
3610 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003611
Douglas Gregorb71d8212011-03-02 18:32:08 +00003612 QualType T = TSInfo->getType();
3613 if (getDerived().AlreadyTransformed(T))
3614 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003615
Douglas Gregorb71d8212011-03-02 18:32:08 +00003616 TypeLocBuilder TLB;
3617 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003618
Douglas Gregorb71d8212011-03-02 18:32:08 +00003619 TypeLoc TL = TSInfo->getTypeLoc();
3620 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003621 TemplateSpecializationTypeLoc SpecTL =
3622 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003623
Douglas Gregorb71d8212011-03-02 18:32:08 +00003624 TemplateName Template
3625 = getDerived().TransformTemplateName(SS,
3626 SpecTL.getTypePtr()->getTemplateName(),
3627 SpecTL.getTemplateNameLoc(),
3628 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003629 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003630 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003631
3632 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003633 Template);
3634 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003635 DependentTemplateSpecializationTypeLoc SpecTL =
3636 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003637
Douglas Gregorb71d8212011-03-02 18:32:08 +00003638 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003639 = getDerived().RebuildTemplateName(SS,
3640 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003641 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003642 ObjectType, UnqualLookup);
3643 if (Template.isNull())
3644 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003645
3646 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003647 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003648 Template,
3649 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003650 } else {
3651 // Nothing special needs to be done for these.
3652 Result = getDerived().TransformType(TLB, TL);
3653 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003654
3655 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003656 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003657
Douglas Gregorb71d8212011-03-02 18:32:08 +00003658 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3659}
3660
John McCalla2becad2009-10-21 00:40:46 +00003661template <class TyLoc> static inline
3662QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3663 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3664 NewT.setNameLoc(T.getNameLoc());
3665 return T.getType();
3666}
3667
John McCalla2becad2009-10-21 00:40:46 +00003668template<typename Derived>
3669QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003670 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003671 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3672 NewT.setBuiltinLoc(T.getBuiltinLoc());
3673 if (T.needsExtraLocalData())
3674 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3675 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003676}
Mike Stump1eb44332009-09-09 15:08:12 +00003677
Douglas Gregor577f75a2009-08-04 16:50:30 +00003678template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003679QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003680 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003681 // FIXME: recurse?
3682 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003683}
Mike Stump1eb44332009-09-09 15:08:12 +00003684
Douglas Gregor577f75a2009-08-04 16:50:30 +00003685template<typename Derived>
Reid Kleckner12df2462013-06-24 17:51:48 +00003686QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3687 DecayedTypeLoc TL) {
3688 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3689 if (OriginalType.isNull())
3690 return QualType();
3691
3692 QualType Result = TL.getType();
3693 if (getDerived().AlwaysRebuild() ||
3694 OriginalType != TL.getOriginalLoc().getType())
3695 Result = SemaRef.Context.getDecayedType(OriginalType);
3696 TLB.push<DecayedTypeLoc>(Result);
3697 // Nothing to set for DecayedTypeLoc.
3698 return Result;
3699}
3700
3701template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003702QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003703 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003704 QualType PointeeType
3705 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003706 if (PointeeType.isNull())
3707 return QualType();
3708
3709 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003710 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003711 // A dependent pointer type 'T *' has is being transformed such
3712 // that an Objective-C class type is being replaced for 'T'. The
3713 // resulting pointer type is an ObjCObjectPointerType, not a
3714 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003715 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003716
John McCallc12c5bb2010-05-15 11:32:37 +00003717 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3718 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003719 return Result;
3720 }
John McCall43fed0d2010-11-12 08:19:04 +00003721
Douglas Gregor92e986e2010-04-22 16:44:27 +00003722 if (getDerived().AlwaysRebuild() ||
3723 PointeeType != TL.getPointeeLoc().getType()) {
3724 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3725 if (Result.isNull())
3726 return QualType();
3727 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003728
John McCallf85e1932011-06-15 23:02:42 +00003729 // Objective-C ARC can add lifetime qualifiers to the type that we're
3730 // pointing to.
3731 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003732
Douglas Gregor92e986e2010-04-22 16:44:27 +00003733 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3734 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003735 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003736}
Mike Stump1eb44332009-09-09 15:08:12 +00003737
3738template<typename Derived>
3739QualType
John McCalla2becad2009-10-21 00:40:46 +00003740TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003741 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003742 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003743 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3744 if (PointeeType.isNull())
3745 return QualType();
3746
3747 QualType Result = TL.getType();
3748 if (getDerived().AlwaysRebuild() ||
3749 PointeeType != TL.getPointeeLoc().getType()) {
3750 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003751 TL.getSigilLoc());
3752 if (Result.isNull())
3753 return QualType();
3754 }
3755
Douglas Gregor39968ad2010-04-22 16:50:51 +00003756 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003757 NewT.setSigilLoc(TL.getSigilLoc());
3758 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003759}
3760
John McCall85737a72009-10-30 00:06:24 +00003761/// Transforms a reference type. Note that somewhat paradoxically we
3762/// don't care whether the type itself is an l-value type or an r-value
3763/// type; we only care if the type was *written* as an l-value type
3764/// or an r-value type.
3765template<typename Derived>
3766QualType
3767TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003768 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003769 const ReferenceType *T = TL.getTypePtr();
3770
3771 // Note that this works with the pointee-as-written.
3772 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3773 if (PointeeType.isNull())
3774 return QualType();
3775
3776 QualType Result = TL.getType();
3777 if (getDerived().AlwaysRebuild() ||
3778 PointeeType != T->getPointeeTypeAsWritten()) {
3779 Result = getDerived().RebuildReferenceType(PointeeType,
3780 T->isSpelledAsLValue(),
3781 TL.getSigilLoc());
3782 if (Result.isNull())
3783 return QualType();
3784 }
3785
John McCallf85e1932011-06-15 23:02:42 +00003786 // Objective-C ARC can add lifetime qualifiers to the type that we're
3787 // referring to.
3788 TLB.TypeWasModifiedSafely(
3789 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3790
John McCall85737a72009-10-30 00:06:24 +00003791 // r-value references can be rebuilt as l-value references.
3792 ReferenceTypeLoc NewTL;
3793 if (isa<LValueReferenceType>(Result))
3794 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3795 else
3796 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3797 NewTL.setSigilLoc(TL.getSigilLoc());
3798
3799 return Result;
3800}
3801
Mike Stump1eb44332009-09-09 15:08:12 +00003802template<typename Derived>
3803QualType
John McCalla2becad2009-10-21 00:40:46 +00003804TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003805 LValueReferenceTypeLoc TL) {
3806 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003807}
3808
Mike Stump1eb44332009-09-09 15:08:12 +00003809template<typename Derived>
3810QualType
John McCalla2becad2009-10-21 00:40:46 +00003811TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003812 RValueReferenceTypeLoc TL) {
3813 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003814}
Mike Stump1eb44332009-09-09 15:08:12 +00003815
Douglas Gregor577f75a2009-08-04 16:50:30 +00003816template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003817QualType
John McCalla2becad2009-10-21 00:40:46 +00003818TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003819 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003820 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003821 if (PointeeType.isNull())
3822 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003823
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003824 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3825 TypeSourceInfo* NewClsTInfo = 0;
3826 if (OldClsTInfo) {
3827 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3828 if (!NewClsTInfo)
3829 return QualType();
3830 }
3831
3832 const MemberPointerType *T = TL.getTypePtr();
3833 QualType OldClsType = QualType(T->getClass(), 0);
3834 QualType NewClsType;
3835 if (NewClsTInfo)
3836 NewClsType = NewClsTInfo->getType();
3837 else {
3838 NewClsType = getDerived().TransformType(OldClsType);
3839 if (NewClsType.isNull())
3840 return QualType();
3841 }
Mike Stump1eb44332009-09-09 15:08:12 +00003842
John McCalla2becad2009-10-21 00:40:46 +00003843 QualType Result = TL.getType();
3844 if (getDerived().AlwaysRebuild() ||
3845 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003846 NewClsType != OldClsType) {
3847 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003848 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003849 if (Result.isNull())
3850 return QualType();
3851 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003852
John McCalla2becad2009-10-21 00:40:46 +00003853 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3854 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003855 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003856
3857 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003858}
3859
Mike Stump1eb44332009-09-09 15:08:12 +00003860template<typename Derived>
3861QualType
John McCalla2becad2009-10-21 00:40:46 +00003862TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003863 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003864 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003865 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003866 if (ElementType.isNull())
3867 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003868
John McCalla2becad2009-10-21 00:40:46 +00003869 QualType Result = TL.getType();
3870 if (getDerived().AlwaysRebuild() ||
3871 ElementType != T->getElementType()) {
3872 Result = getDerived().RebuildConstantArrayType(ElementType,
3873 T->getSizeModifier(),
3874 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003875 T->getIndexTypeCVRQualifiers(),
3876 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003877 if (Result.isNull())
3878 return QualType();
3879 }
Eli Friedman457a3772012-01-25 22:19:07 +00003880
3881 // We might have either a ConstantArrayType or a VariableArrayType now:
3882 // a ConstantArrayType is allowed to have an element type which is a
3883 // VariableArrayType if the type is dependent. Fortunately, all array
3884 // types have the same location layout.
3885 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003886 NewTL.setLBracketLoc(TL.getLBracketLoc());
3887 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003888
John McCalla2becad2009-10-21 00:40:46 +00003889 Expr *Size = TL.getSizeExpr();
3890 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003891 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3892 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003893 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003894 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003895 }
3896 NewTL.setSizeExpr(Size);
3897
3898 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003899}
Mike Stump1eb44332009-09-09 15:08:12 +00003900
Douglas Gregor577f75a2009-08-04 16:50:30 +00003901template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003902QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003903 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003904 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003905 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003906 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003907 if (ElementType.isNull())
3908 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003909
John McCalla2becad2009-10-21 00:40:46 +00003910 QualType Result = TL.getType();
3911 if (getDerived().AlwaysRebuild() ||
3912 ElementType != T->getElementType()) {
3913 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003914 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003915 T->getIndexTypeCVRQualifiers(),
3916 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003917 if (Result.isNull())
3918 return QualType();
3919 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003920
John McCalla2becad2009-10-21 00:40:46 +00003921 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3922 NewTL.setLBracketLoc(TL.getLBracketLoc());
3923 NewTL.setRBracketLoc(TL.getRBracketLoc());
3924 NewTL.setSizeExpr(0);
3925
3926 return Result;
3927}
3928
3929template<typename Derived>
3930QualType
3931TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003932 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003933 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003934 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3935 if (ElementType.isNull())
3936 return QualType();
3937
John McCall60d7b3a2010-08-24 06:29:42 +00003938 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003939 = getDerived().TransformExpr(T->getSizeExpr());
3940 if (SizeResult.isInvalid())
3941 return QualType();
3942
John McCall9ae2f072010-08-23 23:25:46 +00003943 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003944
3945 QualType Result = TL.getType();
3946 if (getDerived().AlwaysRebuild() ||
3947 ElementType != T->getElementType() ||
3948 Size != T->getSizeExpr()) {
3949 Result = getDerived().RebuildVariableArrayType(ElementType,
3950 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003951 Size,
John McCalla2becad2009-10-21 00:40:46 +00003952 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003953 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003954 if (Result.isNull())
3955 return QualType();
3956 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003957
John McCalla2becad2009-10-21 00:40:46 +00003958 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3959 NewTL.setLBracketLoc(TL.getLBracketLoc());
3960 NewTL.setRBracketLoc(TL.getRBracketLoc());
3961 NewTL.setSizeExpr(Size);
3962
3963 return Result;
3964}
3965
3966template<typename Derived>
3967QualType
3968TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003969 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003970 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003971 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3972 if (ElementType.isNull())
3973 return QualType();
3974
Richard Smithf6702a32011-12-20 02:08:33 +00003975 // Array bounds are constant expressions.
3976 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3977 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003978
John McCall3b657512011-01-19 10:06:00 +00003979 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3980 Expr *origSize = TL.getSizeExpr();
3981 if (!origSize) origSize = T->getSizeExpr();
3982
3983 ExprResult sizeResult
3984 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003985 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003986 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003987 return QualType();
3988
John McCall3b657512011-01-19 10:06:00 +00003989 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003990
3991 QualType Result = TL.getType();
3992 if (getDerived().AlwaysRebuild() ||
3993 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003994 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003995 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3996 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003997 size,
John McCalla2becad2009-10-21 00:40:46 +00003998 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003999 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00004000 if (Result.isNull())
4001 return QualType();
4002 }
John McCalla2becad2009-10-21 00:40:46 +00004003
4004 // We might have any sort of array type now, but fortunately they
4005 // all have the same location layout.
4006 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4007 NewTL.setLBracketLoc(TL.getLBracketLoc());
4008 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00004009 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00004010
4011 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004012}
Mike Stump1eb44332009-09-09 15:08:12 +00004013
4014template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00004015QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00004016 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004017 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004018 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004019
4020 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00004021 QualType ElementType = getDerived().TransformType(T->getElementType());
4022 if (ElementType.isNull())
4023 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004024
Richard Smithf6702a32011-12-20 02:08:33 +00004025 // Vector sizes are constant expressions.
4026 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4027 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00004028
John McCall60d7b3a2010-08-24 06:29:42 +00004029 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00004030 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004031 if (Size.isInvalid())
4032 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004033
John McCalla2becad2009-10-21 00:40:46 +00004034 QualType Result = TL.getType();
4035 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00004036 ElementType != T->getElementType() ||
4037 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00004038 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00004039 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00004040 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00004041 if (Result.isNull())
4042 return QualType();
4043 }
John McCalla2becad2009-10-21 00:40:46 +00004044
4045 // Result might be dependent or not.
4046 if (isa<DependentSizedExtVectorType>(Result)) {
4047 DependentSizedExtVectorTypeLoc NewTL
4048 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4049 NewTL.setNameLoc(TL.getNameLoc());
4050 } else {
4051 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4052 NewTL.setNameLoc(TL.getNameLoc());
4053 }
4054
4055 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004056}
Mike Stump1eb44332009-09-09 15:08:12 +00004057
4058template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004059QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004060 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004061 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004062 QualType ElementType = getDerived().TransformType(T->getElementType());
4063 if (ElementType.isNull())
4064 return QualType();
4065
John McCalla2becad2009-10-21 00:40:46 +00004066 QualType Result = TL.getType();
4067 if (getDerived().AlwaysRebuild() ||
4068 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00004069 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00004070 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00004071 if (Result.isNull())
4072 return QualType();
4073 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004074
John McCalla2becad2009-10-21 00:40:46 +00004075 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4076 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00004077
John McCalla2becad2009-10-21 00:40:46 +00004078 return Result;
4079}
4080
4081template<typename Derived>
4082QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004083 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004084 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004085 QualType ElementType = getDerived().TransformType(T->getElementType());
4086 if (ElementType.isNull())
4087 return QualType();
4088
4089 QualType Result = TL.getType();
4090 if (getDerived().AlwaysRebuild() ||
4091 ElementType != T->getElementType()) {
4092 Result = getDerived().RebuildExtVectorType(ElementType,
4093 T->getNumElements(),
4094 /*FIXME*/ SourceLocation());
4095 if (Result.isNull())
4096 return QualType();
4097 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004098
John McCalla2becad2009-10-21 00:40:46 +00004099 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4100 NewTL.setNameLoc(TL.getNameLoc());
4101
4102 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004103}
Mike Stump1eb44332009-09-09 15:08:12 +00004104
David Blaikiedc84cd52013-02-20 22:23:23 +00004105template <typename Derived>
4106ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4107 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4108 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00004109 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004110 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004111
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004112 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004113 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004114 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004115 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004116 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004117
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004118 TypeLocBuilder TLB;
4119 TypeLoc NewTL = OldDI->getTypeLoc();
4120 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004121
4122 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004123 OldExpansionTL.getPatternLoc());
4124 if (Result.isNull())
4125 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004126
4127 Result = RebuildPackExpansionType(Result,
4128 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004129 OldExpansionTL.getEllipsisLoc(),
4130 NumExpansions);
4131 if (Result.isNull())
4132 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004133
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004134 PackExpansionTypeLoc NewExpansionTL
4135 = TLB.push<PackExpansionTypeLoc>(Result);
4136 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4137 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4138 } else
4139 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00004140 if (!NewDI)
4141 return 0;
4142
John McCallfb44de92011-05-01 22:35:37 +00004143 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00004144 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00004145
4146 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4147 OldParm->getDeclContext(),
4148 OldParm->getInnerLocStart(),
4149 OldParm->getLocation(),
4150 OldParm->getIdentifier(),
4151 NewDI->getType(),
4152 NewDI,
4153 OldParm->getStorageClass(),
John McCallfb44de92011-05-01 22:35:37 +00004154 /* DefArg */ NULL);
4155 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4156 OldParm->getFunctionScopeIndex() + indexAdjustment);
4157 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004158}
4159
4160template<typename Derived>
4161bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004162 TransformFunctionTypeParams(SourceLocation Loc,
4163 ParmVarDecl **Params, unsigned NumParams,
4164 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004165 SmallVectorImpl<QualType> &OutParamTypes,
4166 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004167 int indexAdjustment = 0;
4168
Douglas Gregora009b592011-01-07 00:20:55 +00004169 for (unsigned i = 0; i != NumParams; ++i) {
4170 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004171 assert(OldParm->getFunctionScopeIndex() == i);
4172
David Blaikiedc84cd52013-02-20 22:23:23 +00004173 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004174 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004175 if (OldParm->isParameterPack()) {
4176 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004177 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004178
Douglas Gregor603cfb42011-01-05 23:12:31 +00004179 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004180 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004181 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004182 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4183 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004184 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4185
Douglas Gregor603cfb42011-01-05 23:12:31 +00004186 // Determine whether we should expand the parameter packs.
4187 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004188 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004189 Optional<unsigned> OrigNumExpansions =
4190 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004191 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004192 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4193 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004194 Unexpanded,
4195 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004196 RetainExpansion,
4197 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004198 return true;
4199 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004200
Douglas Gregor603cfb42011-01-05 23:12:31 +00004201 if (ShouldExpand) {
4202 // Expand the function parameter pack into multiple, separate
4203 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004204 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004205 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004206 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004207 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004208 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004209 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004210 OrigNumExpansions,
4211 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004212 if (!NewParm)
4213 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004214
Douglas Gregora009b592011-01-07 00:20:55 +00004215 OutParamTypes.push_back(NewParm->getType());
4216 if (PVars)
4217 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004218 }
Douglas Gregord3731192011-01-10 07:32:04 +00004219
4220 // If we're supposed to retain a pack expansion, do so by temporarily
4221 // forgetting the partially-substituted parameter pack.
4222 if (RetainExpansion) {
4223 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004224 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004225 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004226 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004227 OrigNumExpansions,
4228 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004229 if (!NewParm)
4230 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004231
Douglas Gregord3731192011-01-10 07:32:04 +00004232 OutParamTypes.push_back(NewParm->getType());
4233 if (PVars)
4234 PVars->push_back(NewParm);
4235 }
4236
John McCallfb44de92011-05-01 22:35:37 +00004237 // The next parameter should have the same adjustment as the
4238 // last thing we pushed, but we post-incremented indexAdjustment
4239 // on every push. Also, if we push nothing, the adjustment should
4240 // go down by one.
4241 indexAdjustment--;
4242
Douglas Gregor603cfb42011-01-05 23:12:31 +00004243 // We're done with the pack expansion.
4244 continue;
4245 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004246
4247 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004248 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004249 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4250 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004251 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004252 NumExpansions,
4253 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004254 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004255 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004256 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004257 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004258
John McCall21ef0fa2010-03-11 09:03:00 +00004259 if (!NewParm)
4260 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004261
Douglas Gregora009b592011-01-07 00:20:55 +00004262 OutParamTypes.push_back(NewParm->getType());
4263 if (PVars)
4264 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004265 continue;
4266 }
John McCall21ef0fa2010-03-11 09:03:00 +00004267
4268 // Deal with the possibility that we don't have a parameter
4269 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004270 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004271 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004272 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004273 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004274 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004275 = dyn_cast<PackExpansionType>(OldType)) {
4276 // We have a function parameter pack that may need to be expanded.
4277 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004278 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004279 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004280
Douglas Gregor603cfb42011-01-05 23:12:31 +00004281 // Determine whether we should expand the parameter packs.
4282 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004283 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004284 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004285 Unexpanded,
4286 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004287 RetainExpansion,
4288 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004289 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004290 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004291
Douglas Gregor603cfb42011-01-05 23:12:31 +00004292 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004293 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004294 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004295 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004296 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4297 QualType NewType = getDerived().TransformType(Pattern);
4298 if (NewType.isNull())
4299 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004300
Douglas Gregora009b592011-01-07 00:20:55 +00004301 OutParamTypes.push_back(NewType);
4302 if (PVars)
4303 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004304 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004305
Douglas Gregor603cfb42011-01-05 23:12:31 +00004306 // We're done with the pack expansion.
4307 continue;
4308 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004309
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004310 // If we're supposed to retain a pack expansion, do so by temporarily
4311 // forgetting the partially-substituted parameter pack.
4312 if (RetainExpansion) {
4313 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4314 QualType NewType = getDerived().TransformType(Pattern);
4315 if (NewType.isNull())
4316 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004317
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004318 OutParamTypes.push_back(NewType);
4319 if (PVars)
4320 PVars->push_back(0);
4321 }
Douglas Gregord3731192011-01-10 07:32:04 +00004322
Chad Rosier4a9d7952012-08-08 18:46:20 +00004323 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004324 // expansion.
4325 OldType = Expansion->getPattern();
4326 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004327 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4328 NewType = getDerived().TransformType(OldType);
4329 } else {
4330 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004331 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004332
Douglas Gregor603cfb42011-01-05 23:12:31 +00004333 if (NewType.isNull())
4334 return true;
4335
4336 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004337 NewType = getSema().Context.getPackExpansionType(NewType,
4338 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004339
Douglas Gregora009b592011-01-07 00:20:55 +00004340 OutParamTypes.push_back(NewType);
4341 if (PVars)
4342 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004343 }
4344
John McCallfb44de92011-05-01 22:35:37 +00004345#ifndef NDEBUG
4346 if (PVars) {
4347 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4348 if (ParmVarDecl *parm = (*PVars)[i])
4349 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004350 }
John McCallfb44de92011-05-01 22:35:37 +00004351#endif
4352
4353 return false;
4354}
John McCall21ef0fa2010-03-11 09:03:00 +00004355
4356template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004357QualType
John McCalla2becad2009-10-21 00:40:46 +00004358TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004359 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004360 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4361}
4362
4363template<typename Derived>
4364QualType
4365TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4366 FunctionProtoTypeLoc TL,
4367 CXXRecordDecl *ThisContext,
4368 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004369 // Transform the parameters and return type.
4370 //
Richard Smithe6975e92012-04-17 00:58:00 +00004371 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004372 // When the function has a trailing return type, we instantiate the
4373 // parameters before the return type, since the return type can then refer
4374 // to the parameters themselves (via decltype, sizeof, etc.).
4375 //
Chris Lattner686775d2011-07-20 06:58:45 +00004376 SmallVector<QualType, 4> ParamTypes;
4377 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004378 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004379
Douglas Gregordab60ad2010-10-01 18:44:50 +00004380 QualType ResultType;
4381
Richard Smith9fbf3272012-08-14 22:51:13 +00004382 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004383 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004384 TL.getParmArray(),
4385 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004386 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004387 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004388 return QualType();
4389
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004390 {
4391 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004392 // If a declaration declares a member function or member function
4393 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004394 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004395 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004396 // declarator.
4397 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004398
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004399 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4400 if (ResultType.isNull())
4401 return QualType();
4402 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004403 }
4404 else {
4405 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4406 if (ResultType.isNull())
4407 return QualType();
4408
Chad Rosier4a9d7952012-08-08 18:46:20 +00004409 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004410 TL.getParmArray(),
4411 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004412 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004413 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004414 return QualType();
4415 }
4416
Richard Smithe6975e92012-04-17 00:58:00 +00004417 // FIXME: Need to transform the exception-specification too.
4418
John McCalla2becad2009-10-21 00:40:46 +00004419 QualType Result = TL.getType();
4420 if (getDerived().AlwaysRebuild() ||
4421 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004422 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004423 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004424 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004425 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004426 if (Result.isNull())
4427 return QualType();
4428 }
Mike Stump1eb44332009-09-09 15:08:12 +00004429
John McCalla2becad2009-10-21 00:40:46 +00004430 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004431 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004432 NewTL.setLParenLoc(TL.getLParenLoc());
4433 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004434 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004435 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4436 NewTL.setArg(i, ParamDecls[i]);
4437
4438 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004439}
Mike Stump1eb44332009-09-09 15:08:12 +00004440
Douglas Gregor577f75a2009-08-04 16:50:30 +00004441template<typename Derived>
4442QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004443 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004444 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004445 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004446 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4447 if (ResultType.isNull())
4448 return QualType();
4449
4450 QualType Result = TL.getType();
4451 if (getDerived().AlwaysRebuild() ||
4452 ResultType != T->getResultType())
4453 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4454
4455 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004456 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004457 NewTL.setLParenLoc(TL.getLParenLoc());
4458 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004459 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004460
4461 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004462}
Mike Stump1eb44332009-09-09 15:08:12 +00004463
John McCalled976492009-12-04 22:46:56 +00004464template<typename Derived> QualType
4465TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004466 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004467 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004468 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004469 if (!D)
4470 return QualType();
4471
4472 QualType Result = TL.getType();
4473 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4474 Result = getDerived().RebuildUnresolvedUsingType(D);
4475 if (Result.isNull())
4476 return QualType();
4477 }
4478
4479 // We might get an arbitrary type spec type back. We should at
4480 // least always get a type spec type, though.
4481 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4482 NewTL.setNameLoc(TL.getNameLoc());
4483
4484 return Result;
4485}
4486
Douglas Gregor577f75a2009-08-04 16:50:30 +00004487template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004488QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004489 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004490 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004491 TypedefNameDecl *Typedef
4492 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4493 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004494 if (!Typedef)
4495 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004496
John McCalla2becad2009-10-21 00:40:46 +00004497 QualType Result = TL.getType();
4498 if (getDerived().AlwaysRebuild() ||
4499 Typedef != T->getDecl()) {
4500 Result = getDerived().RebuildTypedefType(Typedef);
4501 if (Result.isNull())
4502 return QualType();
4503 }
Mike Stump1eb44332009-09-09 15:08:12 +00004504
John McCalla2becad2009-10-21 00:40:46 +00004505 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4506 NewTL.setNameLoc(TL.getNameLoc());
4507
4508 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004509}
Mike Stump1eb44332009-09-09 15:08:12 +00004510
Douglas Gregor577f75a2009-08-04 16:50:30 +00004511template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004512QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004513 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004514 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004515 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4516 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004517
John McCall60d7b3a2010-08-24 06:29:42 +00004518 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004519 if (E.isInvalid())
4520 return QualType();
4521
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004522 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4523 if (E.isInvalid())
4524 return QualType();
4525
John McCalla2becad2009-10-21 00:40:46 +00004526 QualType Result = TL.getType();
4527 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004528 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004529 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004530 if (Result.isNull())
4531 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004532 }
John McCalla2becad2009-10-21 00:40:46 +00004533 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004534
John McCalla2becad2009-10-21 00:40:46 +00004535 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004536 NewTL.setTypeofLoc(TL.getTypeofLoc());
4537 NewTL.setLParenLoc(TL.getLParenLoc());
4538 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004539
4540 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004541}
Mike Stump1eb44332009-09-09 15:08:12 +00004542
4543template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004544QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004545 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004546 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4547 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4548 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004549 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004550
John McCalla2becad2009-10-21 00:40:46 +00004551 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004552 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4553 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004554 if (Result.isNull())
4555 return QualType();
4556 }
Mike Stump1eb44332009-09-09 15:08:12 +00004557
John McCalla2becad2009-10-21 00:40:46 +00004558 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004559 NewTL.setTypeofLoc(TL.getTypeofLoc());
4560 NewTL.setLParenLoc(TL.getLParenLoc());
4561 NewTL.setRParenLoc(TL.getRParenLoc());
4562 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004563
4564 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004565}
Mike Stump1eb44332009-09-09 15:08:12 +00004566
4567template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004568QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004569 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004570 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004571
Douglas Gregor670444e2009-08-04 22:27:00 +00004572 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004573 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4574 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004575
John McCall60d7b3a2010-08-24 06:29:42 +00004576 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004577 if (E.isInvalid())
4578 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004579
Richard Smith76f3f692012-02-22 02:04:18 +00004580 E = getSema().ActOnDecltypeExpression(E.take());
4581 if (E.isInvalid())
4582 return QualType();
4583
John McCalla2becad2009-10-21 00:40:46 +00004584 QualType Result = TL.getType();
4585 if (getDerived().AlwaysRebuild() ||
4586 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004587 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004588 if (Result.isNull())
4589 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004590 }
John McCalla2becad2009-10-21 00:40:46 +00004591 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004592
John McCalla2becad2009-10-21 00:40:46 +00004593 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4594 NewTL.setNameLoc(TL.getNameLoc());
4595
4596 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004597}
4598
4599template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004600QualType TreeTransform<Derived>::TransformUnaryTransformType(
4601 TypeLocBuilder &TLB,
4602 UnaryTransformTypeLoc TL) {
4603 QualType Result = TL.getType();
4604 if (Result->isDependentType()) {
4605 const UnaryTransformType *T = TL.getTypePtr();
4606 QualType NewBase =
4607 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4608 Result = getDerived().RebuildUnaryTransformType(NewBase,
4609 T->getUTTKind(),
4610 TL.getKWLoc());
4611 if (Result.isNull())
4612 return QualType();
4613 }
4614
4615 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4616 NewTL.setKWLoc(TL.getKWLoc());
4617 NewTL.setParensRange(TL.getParensRange());
4618 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4619 return Result;
4620}
4621
4622template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004623QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4624 AutoTypeLoc TL) {
4625 const AutoType *T = TL.getTypePtr();
4626 QualType OldDeduced = T->getDeducedType();
4627 QualType NewDeduced;
4628 if (!OldDeduced.isNull()) {
4629 NewDeduced = getDerived().TransformType(OldDeduced);
4630 if (NewDeduced.isNull())
4631 return QualType();
4632 }
4633
4634 QualType Result = TL.getType();
Richard Smithdc7a4f52013-04-30 13:56:41 +00004635 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4636 T->isDependentType()) {
Richard Smitha2c36462013-04-26 16:15:35 +00004637 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith34b41d92011-02-20 03:19:35 +00004638 if (Result.isNull())
4639 return QualType();
4640 }
4641
4642 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4643 NewTL.setNameLoc(TL.getNameLoc());
4644
4645 return Result;
4646}
4647
4648template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004649QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004650 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004651 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004652 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004653 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4654 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004655 if (!Record)
4656 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004657
John McCalla2becad2009-10-21 00:40:46 +00004658 QualType Result = TL.getType();
4659 if (getDerived().AlwaysRebuild() ||
4660 Record != T->getDecl()) {
4661 Result = getDerived().RebuildRecordType(Record);
4662 if (Result.isNull())
4663 return QualType();
4664 }
Mike Stump1eb44332009-09-09 15:08:12 +00004665
John McCalla2becad2009-10-21 00:40:46 +00004666 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4667 NewTL.setNameLoc(TL.getNameLoc());
4668
4669 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004670}
Mike Stump1eb44332009-09-09 15:08:12 +00004671
4672template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004673QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004674 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004675 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004676 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004677 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4678 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004679 if (!Enum)
4680 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004681
John McCalla2becad2009-10-21 00:40:46 +00004682 QualType Result = TL.getType();
4683 if (getDerived().AlwaysRebuild() ||
4684 Enum != T->getDecl()) {
4685 Result = getDerived().RebuildEnumType(Enum);
4686 if (Result.isNull())
4687 return QualType();
4688 }
Mike Stump1eb44332009-09-09 15:08:12 +00004689
John McCalla2becad2009-10-21 00:40:46 +00004690 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4691 NewTL.setNameLoc(TL.getNameLoc());
4692
4693 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004694}
John McCall7da24312009-09-05 00:15:47 +00004695
John McCall3cb0ebd2010-03-10 03:28:59 +00004696template<typename Derived>
4697QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4698 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004699 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004700 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4701 TL.getTypePtr()->getDecl());
4702 if (!D) return QualType();
4703
4704 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4705 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4706 return T;
4707}
4708
Douglas Gregor577f75a2009-08-04 16:50:30 +00004709template<typename Derived>
4710QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004711 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004712 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004713 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004714}
4715
Mike Stump1eb44332009-09-09 15:08:12 +00004716template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004717QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004718 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004719 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004720 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004721
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004722 // Substitute into the replacement type, which itself might involve something
4723 // that needs to be transformed. This only tends to occur with default
4724 // template arguments of template template parameters.
4725 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4726 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4727 if (Replacement.isNull())
4728 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004729
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004730 // Always canonicalize the replacement type.
4731 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4732 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004733 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004734 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004735
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004736 // Propagate type-source information.
4737 SubstTemplateTypeParmTypeLoc NewTL
4738 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4739 NewTL.setNameLoc(TL.getNameLoc());
4740 return Result;
4741
John McCall49a832b2009-10-18 09:09:24 +00004742}
4743
4744template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004745QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4746 TypeLocBuilder &TLB,
4747 SubstTemplateTypeParmPackTypeLoc TL) {
4748 return TransformTypeSpecType(TLB, TL);
4749}
4750
4751template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004752QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004753 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004754 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004755 const TemplateSpecializationType *T = TL.getTypePtr();
4756
Douglas Gregor1d752d72011-03-02 18:46:51 +00004757 // The nested-name-specifier never matters in a TemplateSpecializationType,
4758 // because we can't have a dependent nested-name-specifier anyway.
4759 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004760 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004761 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4762 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004763 if (Template.isNull())
4764 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004765
John McCall43fed0d2010-11-12 08:19:04 +00004766 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4767}
4768
Eli Friedmanb001de72011-10-06 23:00:33 +00004769template<typename Derived>
4770QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4771 AtomicTypeLoc TL) {
4772 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4773 if (ValueType.isNull())
4774 return QualType();
4775
4776 QualType Result = TL.getType();
4777 if (getDerived().AlwaysRebuild() ||
4778 ValueType != TL.getValueLoc().getType()) {
4779 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4780 if (Result.isNull())
4781 return QualType();
4782 }
4783
4784 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4785 NewTL.setKWLoc(TL.getKWLoc());
4786 NewTL.setLParenLoc(TL.getLParenLoc());
4787 NewTL.setRParenLoc(TL.getRParenLoc());
4788
4789 return Result;
4790}
4791
Chad Rosier4a9d7952012-08-08 18:46:20 +00004792 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004793 /// container that provides a \c getArgLoc() member function.
4794 ///
4795 /// This iterator is intended to be used with the iterator form of
4796 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4797 template<typename ArgLocContainer>
4798 class TemplateArgumentLocContainerIterator {
4799 ArgLocContainer *Container;
4800 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004801
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004802 public:
4803 typedef TemplateArgumentLoc value_type;
4804 typedef TemplateArgumentLoc reference;
4805 typedef int difference_type;
4806 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004807
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004808 class pointer {
4809 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004810
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004811 public:
4812 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004813
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004814 const TemplateArgumentLoc *operator->() const {
4815 return &Arg;
4816 }
4817 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004818
4819
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004820 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004821
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004822 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4823 unsigned Index)
4824 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004825
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004826 TemplateArgumentLocContainerIterator &operator++() {
4827 ++Index;
4828 return *this;
4829 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004830
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004831 TemplateArgumentLocContainerIterator operator++(int) {
4832 TemplateArgumentLocContainerIterator Old(*this);
4833 ++(*this);
4834 return Old;
4835 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004836
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004837 TemplateArgumentLoc operator*() const {
4838 return Container->getArgLoc(Index);
4839 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004840
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004841 pointer operator->() const {
4842 return pointer(Container->getArgLoc(Index));
4843 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004844
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004845 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004846 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004847 return X.Container == Y.Container && X.Index == Y.Index;
4848 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004849
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004850 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004851 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004852 return !(X == Y);
4853 }
4854 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004855
4856
John McCall43fed0d2010-11-12 08:19:04 +00004857template <typename Derived>
4858QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4859 TypeLocBuilder &TLB,
4860 TemplateSpecializationTypeLoc TL,
4861 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004862 TemplateArgumentListInfo NewTemplateArgs;
4863 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4864 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004865 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4866 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004867 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004868 ArgIterator(TL, TL.getNumArgs()),
4869 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004870 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004871
John McCall833ca992009-10-29 08:12:44 +00004872 // FIXME: maybe don't rebuild if all the template arguments are the same.
4873
4874 QualType Result =
4875 getDerived().RebuildTemplateSpecializationType(Template,
4876 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004877 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004878
4879 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004880 // Specializations of template template parameters are represented as
4881 // TemplateSpecializationTypes, and substitution of type alias templates
4882 // within a dependent context can transform them into
4883 // DependentTemplateSpecializationTypes.
4884 if (isa<DependentTemplateSpecializationType>(Result)) {
4885 DependentTemplateSpecializationTypeLoc NewTL
4886 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004887 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004888 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004889 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004890 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004891 NewTL.setLAngleLoc(TL.getLAngleLoc());
4892 NewTL.setRAngleLoc(TL.getRAngleLoc());
4893 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4894 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4895 return Result;
4896 }
4897
John McCall833ca992009-10-29 08:12:44 +00004898 TemplateSpecializationTypeLoc NewTL
4899 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004900 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004901 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4902 NewTL.setLAngleLoc(TL.getLAngleLoc());
4903 NewTL.setRAngleLoc(TL.getRAngleLoc());
4904 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4905 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004906 }
Mike Stump1eb44332009-09-09 15:08:12 +00004907
John McCall833ca992009-10-29 08:12:44 +00004908 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004909}
Mike Stump1eb44332009-09-09 15:08:12 +00004910
Douglas Gregora88f09f2011-02-28 17:23:35 +00004911template <typename Derived>
4912QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4913 TypeLocBuilder &TLB,
4914 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004915 TemplateName Template,
4916 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004917 TemplateArgumentListInfo NewTemplateArgs;
4918 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4919 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4920 typedef TemplateArgumentLocContainerIterator<
4921 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004922 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004923 ArgIterator(TL, TL.getNumArgs()),
4924 NewTemplateArgs))
4925 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004926
Douglas Gregora88f09f2011-02-28 17:23:35 +00004927 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004928
Douglas Gregora88f09f2011-02-28 17:23:35 +00004929 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4930 QualType Result
4931 = getSema().Context.getDependentTemplateSpecializationType(
4932 TL.getTypePtr()->getKeyword(),
4933 DTN->getQualifier(),
4934 DTN->getIdentifier(),
4935 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004936
Douglas Gregora88f09f2011-02-28 17:23:35 +00004937 DependentTemplateSpecializationTypeLoc NewTL
4938 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004939 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004940 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004941 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004942 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004943 NewTL.setLAngleLoc(TL.getLAngleLoc());
4944 NewTL.setRAngleLoc(TL.getRAngleLoc());
4945 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4946 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4947 return Result;
4948 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004949
4950 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004951 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004952 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004953 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004954
Douglas Gregora88f09f2011-02-28 17:23:35 +00004955 if (!Result.isNull()) {
4956 /// FIXME: Wrap this in an elaborated-type-specifier?
4957 TemplateSpecializationTypeLoc NewTL
4958 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004959 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004960 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004961 NewTL.setLAngleLoc(TL.getLAngleLoc());
4962 NewTL.setRAngleLoc(TL.getRAngleLoc());
4963 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4964 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4965 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004966
Douglas Gregora88f09f2011-02-28 17:23:35 +00004967 return Result;
4968}
4969
Mike Stump1eb44332009-09-09 15:08:12 +00004970template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004971QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004972TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004973 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004974 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004975
Douglas Gregor9e876872011-03-01 18:12:44 +00004976 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004977 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004978 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004979 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004980 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4981 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004982 return QualType();
4983 }
Mike Stump1eb44332009-09-09 15:08:12 +00004984
John McCall43fed0d2010-11-12 08:19:04 +00004985 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4986 if (NamedT.isNull())
4987 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004988
Richard Smith3e4c6c42011-05-05 21:57:07 +00004989 // C++0x [dcl.type.elab]p2:
4990 // If the identifier resolves to a typedef-name or the simple-template-id
4991 // resolves to an alias template specialization, the
4992 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004993 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4994 if (const TemplateSpecializationType *TST =
4995 NamedT->getAs<TemplateSpecializationType>()) {
4996 TemplateName Template = TST->getTemplateName();
4997 if (TypeAliasTemplateDecl *TAT =
4998 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4999 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5000 diag::err_tag_reference_non_tag) << 4;
5001 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5002 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00005003 }
5004 }
5005
John McCalla2becad2009-10-21 00:40:46 +00005006 QualType Result = TL.getType();
5007 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00005008 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005009 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00005010 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00005011 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00005012 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00005013 if (Result.isNull())
5014 return QualType();
5015 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00005016
Abramo Bagnara465d41b2010-05-11 21:36:43 +00005017 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005018 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00005019 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00005020 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00005021}
Mike Stump1eb44332009-09-09 15:08:12 +00005022
5023template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00005024QualType TreeTransform<Derived>::TransformAttributedType(
5025 TypeLocBuilder &TLB,
5026 AttributedTypeLoc TL) {
5027 const AttributedType *oldType = TL.getTypePtr();
5028 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5029 if (modifiedType.isNull())
5030 return QualType();
5031
5032 QualType result = TL.getType();
5033
5034 // FIXME: dependent operand expressions?
5035 if (getDerived().AlwaysRebuild() ||
5036 modifiedType != oldType->getModifiedType()) {
5037 // TODO: this is really lame; we should really be rebuilding the
5038 // equivalent type from first principles.
5039 QualType equivalentType
5040 = getDerived().TransformType(oldType->getEquivalentType());
5041 if (equivalentType.isNull())
5042 return QualType();
5043 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5044 modifiedType,
5045 equivalentType);
5046 }
5047
5048 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5049 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5050 if (TL.hasAttrOperand())
5051 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5052 if (TL.hasAttrExprOperand())
5053 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5054 else if (TL.hasAttrEnumOperand())
5055 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5056
5057 return result;
5058}
5059
5060template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00005061QualType
5062TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5063 ParenTypeLoc TL) {
5064 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5065 if (Inner.isNull())
5066 return QualType();
5067
5068 QualType Result = TL.getType();
5069 if (getDerived().AlwaysRebuild() ||
5070 Inner != TL.getInnerLoc().getType()) {
5071 Result = getDerived().RebuildParenType(Inner);
5072 if (Result.isNull())
5073 return QualType();
5074 }
5075
5076 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5077 NewTL.setLParenLoc(TL.getLParenLoc());
5078 NewTL.setRParenLoc(TL.getRParenLoc());
5079 return Result;
5080}
5081
5082template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00005083QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005084 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00005085 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00005086
Douglas Gregor2494dd02011-03-01 01:34:45 +00005087 NestedNameSpecifierLoc QualifierLoc
5088 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5089 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00005090 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00005091
John McCall33500952010-06-11 00:33:02 +00005092 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00005093 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00005094 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00005095 QualifierLoc,
5096 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00005097 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00005098 if (Result.isNull())
5099 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005100
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005101 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5102 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00005103 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5104
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005105 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005106 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00005107 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00005108 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005109 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005110 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00005111 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005112 NewTL.setNameLoc(TL.getNameLoc());
5113 }
John McCalla2becad2009-10-21 00:40:46 +00005114 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00005115}
Mike Stump1eb44332009-09-09 15:08:12 +00005116
Douglas Gregor577f75a2009-08-04 16:50:30 +00005117template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00005118QualType TreeTransform<Derived>::
5119 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005120 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005121 NestedNameSpecifierLoc QualifierLoc;
5122 if (TL.getQualifierLoc()) {
5123 QualifierLoc
5124 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5125 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00005126 return QualType();
5127 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005128
John McCall43fed0d2010-11-12 08:19:04 +00005129 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005130 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00005131}
5132
5133template<typename Derived>
5134QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005135TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5136 DependentTemplateSpecializationTypeLoc TL,
5137 NestedNameSpecifierLoc QualifierLoc) {
5138 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005139
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005140 TemplateArgumentListInfo NewTemplateArgs;
5141 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5142 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005143
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005144 typedef TemplateArgumentLocContainerIterator<
5145 DependentTemplateSpecializationTypeLoc> ArgIterator;
5146 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5147 ArgIterator(TL, TL.getNumArgs()),
5148 NewTemplateArgs))
5149 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005150
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005151 QualType Result
5152 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5153 QualifierLoc,
5154 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005155 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005156 NewTemplateArgs);
5157 if (Result.isNull())
5158 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005159
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005160 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5161 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005162
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005163 // Copy information relevant to the template specialization.
5164 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005165 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005166 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005167 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005168 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5169 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005170 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005171 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005172
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005173 // Copy information relevant to the elaborated type.
5174 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005175 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005176 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005177 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5178 DependentTemplateSpecializationTypeLoc SpecTL
5179 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005180 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005181 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005182 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005183 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005184 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5185 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005186 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005187 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005188 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005189 TemplateSpecializationTypeLoc SpecTL
5190 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005191 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005192 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005193 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5194 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005195 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005196 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005197 }
5198 return Result;
5199}
5200
5201template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005202QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5203 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005204 QualType Pattern
5205 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005206 if (Pattern.isNull())
5207 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005208
5209 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005210 if (getDerived().AlwaysRebuild() ||
5211 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005212 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005213 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005214 TL.getEllipsisLoc(),
5215 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005216 if (Result.isNull())
5217 return QualType();
5218 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005219
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005220 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5221 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5222 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005223}
5224
5225template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005226QualType
5227TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005228 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005229 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005230 TLB.pushFullCopy(TL);
5231 return TL.getType();
5232}
5233
5234template<typename Derived>
5235QualType
5236TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005237 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005238 // ObjCObjectType is never dependent.
5239 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005240 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005241}
Mike Stump1eb44332009-09-09 15:08:12 +00005242
5243template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005244QualType
5245TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005246 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005247 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005248 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005249 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005250}
5251
Douglas Gregor577f75a2009-08-04 16:50:30 +00005252//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005253// Statement transformation
5254//===----------------------------------------------------------------------===//
5255template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005256StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005257TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005258 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005259}
5260
5261template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005262StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005263TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5264 return getDerived().TransformCompoundStmt(S, false);
5265}
5266
5267template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005268StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005269TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005270 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005271 Sema::CompoundScopeRAII CompoundScope(getSema());
5272
John McCall7114cba2010-08-27 19:56:05 +00005273 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005274 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005275 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005276 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5277 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005278 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005279 if (Result.isInvalid()) {
5280 // Immediately fail if this was a DeclStmt, since it's very
5281 // likely that this will cause problems for future statements.
5282 if (isa<DeclStmt>(*B))
5283 return StmtError();
5284
5285 // Otherwise, just keep processing substatements and fail later.
5286 SubStmtInvalid = true;
5287 continue;
5288 }
Mike Stump1eb44332009-09-09 15:08:12 +00005289
Douglas Gregor43959a92009-08-20 07:17:43 +00005290 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5291 Statements.push_back(Result.takeAs<Stmt>());
5292 }
Mike Stump1eb44332009-09-09 15:08:12 +00005293
John McCall7114cba2010-08-27 19:56:05 +00005294 if (SubStmtInvalid)
5295 return StmtError();
5296
Douglas Gregor43959a92009-08-20 07:17:43 +00005297 if (!getDerived().AlwaysRebuild() &&
5298 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005299 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005300
5301 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005302 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005303 S->getRBracLoc(),
5304 IsStmtExpr);
5305}
Mike Stump1eb44332009-09-09 15:08:12 +00005306
Douglas Gregor43959a92009-08-20 07:17:43 +00005307template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005308StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005309TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005310 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005311 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005312 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5313 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005314
Eli Friedman264c1f82009-11-19 03:14:00 +00005315 // Transform the left-hand case value.
5316 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005317 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005318 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005319 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005320
Eli Friedman264c1f82009-11-19 03:14:00 +00005321 // Transform the right-hand case value (for the GNU case-range extension).
5322 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005323 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005324 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005325 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005326 }
Mike Stump1eb44332009-09-09 15:08:12 +00005327
Douglas Gregor43959a92009-08-20 07:17:43 +00005328 // Build the case statement.
5329 // Case statements are always rebuilt so that they will attached to their
5330 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005331 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005332 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005333 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005334 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005335 S->getColonLoc());
5336 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005337 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005338
Douglas Gregor43959a92009-08-20 07:17:43 +00005339 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005340 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005341 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005342 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005343
Douglas Gregor43959a92009-08-20 07:17:43 +00005344 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005345 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005346}
5347
5348template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005349StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005350TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005351 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005352 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005353 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005354 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005355
Douglas Gregor43959a92009-08-20 07:17:43 +00005356 // Default statements are always rebuilt
5357 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005358 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005359}
Mike Stump1eb44332009-09-09 15:08:12 +00005360
Douglas Gregor43959a92009-08-20 07:17:43 +00005361template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005362StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005363TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005364 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005365 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005366 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005367
Chris Lattner57ad3782011-02-17 20:34:02 +00005368 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5369 S->getDecl());
5370 if (!LD)
5371 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005372
5373
Douglas Gregor43959a92009-08-20 07:17:43 +00005374 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005375 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005376 cast<LabelDecl>(LD), SourceLocation(),
5377 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005378}
Mike Stump1eb44332009-09-09 15:08:12 +00005379
Douglas Gregor43959a92009-08-20 07:17:43 +00005380template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005381StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005382TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5383 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5384 if (SubStmt.isInvalid())
5385 return StmtError();
5386
5387 // TODO: transform attributes
5388 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5389 return S;
5390
5391 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5392 S->getAttrs(),
5393 SubStmt.get());
5394}
5395
5396template<typename Derived>
5397StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005398TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005399 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005400 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005401 VarDecl *ConditionVar = 0;
5402 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005403 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005404 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005405 getDerived().TransformDefinition(
5406 S->getConditionVariable()->getLocation(),
5407 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005408 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005409 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005410 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005411 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005412
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005413 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005414 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005415
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005416 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005417 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005418 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005419 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005420 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005421 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005422
John McCall9ae2f072010-08-23 23:25:46 +00005423 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005424 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005425 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005426
John McCall9ae2f072010-08-23 23:25:46 +00005427 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5428 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005429 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005430
Douglas Gregor43959a92009-08-20 07:17:43 +00005431 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005432 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005433 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005434 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005435
Douglas Gregor43959a92009-08-20 07:17:43 +00005436 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005437 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005438 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005439 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005440
Douglas Gregor43959a92009-08-20 07:17:43 +00005441 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005442 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005443 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005444 Then.get() == S->getThen() &&
5445 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005446 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005447
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005448 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005449 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005450 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005451}
5452
5453template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005454StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005455TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005456 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005457 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005458 VarDecl *ConditionVar = 0;
5459 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005460 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005461 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005462 getDerived().TransformDefinition(
5463 S->getConditionVariable()->getLocation(),
5464 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005465 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005466 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005467 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005468 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005469
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005470 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005471 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005472 }
Mike Stump1eb44332009-09-09 15:08:12 +00005473
Douglas Gregor43959a92009-08-20 07:17:43 +00005474 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005475 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005476 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005477 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005478 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005479 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005480
Douglas Gregor43959a92009-08-20 07:17:43 +00005481 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005482 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005483 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005484 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005485
Douglas Gregor43959a92009-08-20 07:17:43 +00005486 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005487 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5488 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005489}
Mike Stump1eb44332009-09-09 15:08:12 +00005490
Douglas Gregor43959a92009-08-20 07:17:43 +00005491template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005492StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005493TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005494 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005495 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005496 VarDecl *ConditionVar = 0;
5497 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005498 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005499 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005500 getDerived().TransformDefinition(
5501 S->getConditionVariable()->getLocation(),
5502 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005503 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005504 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005505 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005506 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005507
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005508 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005509 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005510
5511 if (S->getCond()) {
5512 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005513 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005514 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005515 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005516 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005517 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005518 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005519 }
Mike Stump1eb44332009-09-09 15:08:12 +00005520
John McCall9ae2f072010-08-23 23:25:46 +00005521 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5522 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005523 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005524
Douglas Gregor43959a92009-08-20 07:17:43 +00005525 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005526 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005527 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005528 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005529
Douglas Gregor43959a92009-08-20 07:17:43 +00005530 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005531 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005532 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005533 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005534 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005535
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005536 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005537 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005538}
Mike Stump1eb44332009-09-09 15:08:12 +00005539
Douglas Gregor43959a92009-08-20 07:17:43 +00005540template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005541StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005542TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005543 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005544 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005545 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005546 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005547
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005548 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005549 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005550 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005551 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005552
Douglas Gregor43959a92009-08-20 07:17:43 +00005553 if (!getDerived().AlwaysRebuild() &&
5554 Cond.get() == S->getCond() &&
5555 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005556 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005557
John McCall9ae2f072010-08-23 23:25:46 +00005558 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5559 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005560 S->getRParenLoc());
5561}
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
Mike Stump1eb44332009-09-09 15:08:12 +00005565TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005566 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005567 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005568 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005569 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005570
Douglas Gregor43959a92009-08-20 07:17:43 +00005571 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005572 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005573 VarDecl *ConditionVar = 0;
5574 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005575 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005576 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005577 getDerived().TransformDefinition(
5578 S->getConditionVariable()->getLocation(),
5579 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005580 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005581 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005582 } else {
5583 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005584
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005585 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005586 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005587
5588 if (S->getCond()) {
5589 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005590 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005591 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005592 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005593 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005594
John McCall9ae2f072010-08-23 23:25:46 +00005595 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005596 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005597 }
Mike Stump1eb44332009-09-09 15:08:12 +00005598
Chad Rosier4a9d7952012-08-08 18:46:20 +00005599 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005600 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005601 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005602
Douglas Gregor43959a92009-08-20 07:17:43 +00005603 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005604 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005605 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005606 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005607
Richard Smith41956372013-01-14 22:39:08 +00005608 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005609 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005610 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005611
Douglas Gregor43959a92009-08-20 07:17:43 +00005612 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005613 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005614 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005615 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005616
Douglas Gregor43959a92009-08-20 07:17:43 +00005617 if (!getDerived().AlwaysRebuild() &&
5618 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005619 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005620 Inc.get() == S->getInc() &&
5621 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005622 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005623
Douglas Gregor43959a92009-08-20 07:17:43 +00005624 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005625 Init.get(), FullCond, ConditionVar,
5626 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005627}
5628
5629template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005630StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005631TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005632 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5633 S->getLabel());
5634 if (!LD)
5635 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005636
Douglas Gregor43959a92009-08-20 07:17:43 +00005637 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005638 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005639 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005640}
5641
5642template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005643StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005644TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005645 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005646 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005647 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005648 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005649
Douglas Gregor43959a92009-08-20 07:17:43 +00005650 if (!getDerived().AlwaysRebuild() &&
5651 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005652 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005653
5654 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005655 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005656}
5657
5658template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005659StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005660TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005661 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005662}
Mike Stump1eb44332009-09-09 15:08:12 +00005663
Douglas Gregor43959a92009-08-20 07:17:43 +00005664template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005665StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005666TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005667 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005668}
Mike Stump1eb44332009-09-09 15:08:12 +00005669
Douglas Gregor43959a92009-08-20 07:17:43 +00005670template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005671StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005672TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005673 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005674 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005675 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005676
Mike Stump1eb44332009-09-09 15:08:12 +00005677 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005678 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005679 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005680}
Mike Stump1eb44332009-09-09 15:08:12 +00005681
Douglas Gregor43959a92009-08-20 07:17:43 +00005682template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005683StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005684TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005685 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005686 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005687 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5688 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005689 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5690 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005691 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005692 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005693
Douglas Gregor43959a92009-08-20 07:17:43 +00005694 if (Transformed != *D)
5695 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005696
Douglas Gregor43959a92009-08-20 07:17:43 +00005697 Decls.push_back(Transformed);
5698 }
Mike Stump1eb44332009-09-09 15:08:12 +00005699
Douglas Gregor43959a92009-08-20 07:17:43 +00005700 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005701 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005702
Rafael Espindola4549d7f2013-07-09 12:05:01 +00005703 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005704}
Mike Stump1eb44332009-09-09 15:08:12 +00005705
Douglas Gregor43959a92009-08-20 07:17:43 +00005706template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005707StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005708TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005709
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005710 SmallVector<Expr*, 8> Constraints;
5711 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005712 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005713
John McCall60d7b3a2010-08-24 06:29:42 +00005714 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005715 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005716
5717 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005718
Anders Carlsson703e3942010-01-24 05:50:09 +00005719 // Go through the outputs.
5720 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005721 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005722
Anders Carlsson703e3942010-01-24 05:50:09 +00005723 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005724 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005725
Anders Carlsson703e3942010-01-24 05:50:09 +00005726 // Transform the output expr.
5727 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005728 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005729 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005730 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005731
Anders Carlsson703e3942010-01-24 05:50:09 +00005732 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005733
John McCall9ae2f072010-08-23 23:25:46 +00005734 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005735 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005736
Anders Carlsson703e3942010-01-24 05:50:09 +00005737 // Go through the inputs.
5738 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005739 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005740
Anders Carlsson703e3942010-01-24 05:50:09 +00005741 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005742 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005743
Anders Carlsson703e3942010-01-24 05:50:09 +00005744 // Transform the input expr.
5745 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005746 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005747 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005748 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005749
Anders Carlsson703e3942010-01-24 05:50:09 +00005750 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005751
John McCall9ae2f072010-08-23 23:25:46 +00005752 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005753 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005754
Anders Carlsson703e3942010-01-24 05:50:09 +00005755 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005756 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005757
5758 // Go through the clobbers.
5759 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005760 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005761
5762 // No need to transform the asm string literal.
5763 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005764 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5765 S->isVolatile(), S->getNumOutputs(),
5766 S->getNumInputs(), Names.data(),
5767 Constraints, Exprs, AsmString.get(),
5768 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005769}
5770
Chad Rosier8cd64b42012-06-11 20:47:18 +00005771template<typename Derived>
5772StmtResult
5773TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005774 ArrayRef<Token> AsmToks =
5775 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005776
John McCallaeeacf72013-05-03 00:10:13 +00005777 bool HadError = false, HadChange = false;
5778
5779 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5780 SmallVector<Expr*, 8> TransformedExprs;
5781 TransformedExprs.reserve(SrcExprs.size());
5782 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5783 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5784 if (!Result.isUsable()) {
5785 HadError = true;
5786 } else {
5787 HadChange |= (Result.get() != SrcExprs[i]);
5788 TransformedExprs.push_back(Result.take());
5789 }
5790 }
5791
5792 if (HadError) return StmtError();
5793 if (!HadChange && !getDerived().AlwaysRebuild())
5794 return Owned(S);
5795
Chad Rosier7bd092b2012-08-15 16:53:30 +00005796 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallaeeacf72013-05-03 00:10:13 +00005797 AsmToks, S->getAsmString(),
5798 S->getNumOutputs(), S->getNumInputs(),
5799 S->getAllConstraints(), S->getClobbers(),
5800 TransformedExprs, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005801}
Douglas Gregor43959a92009-08-20 07:17:43 +00005802
5803template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005804StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005805TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005806 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005807 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005808 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005809 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005810
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005811 // Transform the @catch statements (if present).
5812 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005813 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005814 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005815 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005816 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005817 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005818 if (Catch.get() != S->getCatchStmt(I))
5819 AnyCatchChanged = true;
5820 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005821 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005822
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005823 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005824 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005825 if (S->getFinallyStmt()) {
5826 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5827 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005828 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005829 }
5830
5831 // If nothing changed, just retain this statement.
5832 if (!getDerived().AlwaysRebuild() &&
5833 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005834 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005835 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005836 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005837
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005838 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005839 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005840 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005841}
Mike Stump1eb44332009-09-09 15:08:12 +00005842
Douglas Gregor43959a92009-08-20 07:17:43 +00005843template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005844StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005845TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005846 // Transform the @catch parameter, if there is one.
5847 VarDecl *Var = 0;
5848 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5849 TypeSourceInfo *TSInfo = 0;
5850 if (FromVar->getTypeSourceInfo()) {
5851 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5852 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005853 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005854 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005855
Douglas Gregorbe270a02010-04-26 17:57:08 +00005856 QualType T;
5857 if (TSInfo)
5858 T = TSInfo->getType();
5859 else {
5860 T = getDerived().TransformType(FromVar->getType());
5861 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005862 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005863 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005864
Douglas Gregorbe270a02010-04-26 17:57:08 +00005865 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5866 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005867 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005868 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005869
John McCall60d7b3a2010-08-24 06:29:42 +00005870 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005871 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005872 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005873
5874 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005875 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005876 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005877}
Mike Stump1eb44332009-09-09 15:08:12 +00005878
Douglas Gregor43959a92009-08-20 07:17:43 +00005879template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005880StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005881TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005882 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005883 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005884 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005885 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005886
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005887 // If nothing changed, just retain this statement.
5888 if (!getDerived().AlwaysRebuild() &&
5889 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005890 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005891
5892 // Build a new statement.
5893 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005894 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005895}
Mike Stump1eb44332009-09-09 15:08:12 +00005896
Douglas Gregor43959a92009-08-20 07:17:43 +00005897template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005898StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005899TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005900 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005901 if (S->getThrowExpr()) {
5902 Operand = getDerived().TransformExpr(S->getThrowExpr());
5903 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005904 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005905 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005906
Douglas Gregord1377b22010-04-22 21:44:01 +00005907 if (!getDerived().AlwaysRebuild() &&
5908 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005909 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005910
John McCall9ae2f072010-08-23 23:25:46 +00005911 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005912}
Mike Stump1eb44332009-09-09 15:08:12 +00005913
Douglas Gregor43959a92009-08-20 07:17:43 +00005914template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005915StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005916TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005917 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005918 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005919 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005920 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005921 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005922 Object =
5923 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5924 Object.get());
5925 if (Object.isInvalid())
5926 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005927
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005928 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005929 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005930 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005931 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005932
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005933 // If nothing change, just retain the current statement.
5934 if (!getDerived().AlwaysRebuild() &&
5935 Object.get() == S->getSynchExpr() &&
5936 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005937 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005938
5939 // Build a new statement.
5940 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005941 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005942}
5943
5944template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005945StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005946TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5947 ObjCAutoreleasePoolStmt *S) {
5948 // Transform the body.
5949 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5950 if (Body.isInvalid())
5951 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005952
John McCallf85e1932011-06-15 23:02:42 +00005953 // If nothing changed, just retain this statement.
5954 if (!getDerived().AlwaysRebuild() &&
5955 Body.get() == S->getSubStmt())
5956 return SemaRef.Owned(S);
5957
5958 // Build a new statement.
5959 return getDerived().RebuildObjCAutoreleasePoolStmt(
5960 S->getAtLoc(), Body.get());
5961}
5962
5963template<typename Derived>
5964StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005965TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005966 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005967 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005968 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005969 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005970 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005971
Douglas Gregorc3203e72010-04-22 23:10:45 +00005972 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005973 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005974 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005975 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005976
Douglas Gregorc3203e72010-04-22 23:10:45 +00005977 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005978 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005979 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005980 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005981
Douglas Gregorc3203e72010-04-22 23:10:45 +00005982 // If nothing changed, just retain this statement.
5983 if (!getDerived().AlwaysRebuild() &&
5984 Element.get() == S->getElement() &&
5985 Collection.get() == S->getCollection() &&
5986 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005987 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005988
Douglas Gregorc3203e72010-04-22 23:10:45 +00005989 // Build a new statement.
5990 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005991 Element.get(),
5992 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005993 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005994 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005995}
5996
5997
5998template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005999StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00006000TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
6001 // Transform the exception declaration, if any.
6002 VarDecl *Var = 0;
6003 if (S->getExceptionDecl()) {
6004 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00006005 TypeSourceInfo *T = getDerived().TransformType(
6006 ExceptionDecl->getTypeSourceInfo());
6007 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006008 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006009
Douglas Gregor83cb9422010-09-09 17:09:21 +00006010 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00006011 ExceptionDecl->getInnerLocStart(),
6012 ExceptionDecl->getLocation(),
6013 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00006014 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00006015 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00006016 }
Mike Stump1eb44332009-09-09 15:08:12 +00006017
Douglas Gregor43959a92009-08-20 07:17:43 +00006018 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00006019 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00006020 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006021 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006022
Douglas Gregor43959a92009-08-20 07:17:43 +00006023 if (!getDerived().AlwaysRebuild() &&
6024 !Var &&
6025 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00006026 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00006027
6028 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
6029 Var,
John McCall9ae2f072010-08-23 23:25:46 +00006030 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00006031}
Mike Stump1eb44332009-09-09 15:08:12 +00006032
Douglas Gregor43959a92009-08-20 07:17:43 +00006033template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006034StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00006035TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
6036 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006037 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00006038 = getDerived().TransformCompoundStmt(S->getTryBlock());
6039 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006040 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006041
Douglas Gregor43959a92009-08-20 07:17:43 +00006042 // Transform the handlers.
6043 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006044 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00006045 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00006046 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00006047 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
6048 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006049 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00006050
Douglas Gregor43959a92009-08-20 07:17:43 +00006051 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
6052 Handlers.push_back(Handler.takeAs<Stmt>());
6053 }
Mike Stump1eb44332009-09-09 15:08:12 +00006054
Douglas Gregor43959a92009-08-20 07:17:43 +00006055 if (!getDerived().AlwaysRebuild() &&
6056 TryBlock.get() == S->getTryBlock() &&
6057 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006058 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00006059
John McCall9ae2f072010-08-23 23:25:46 +00006060 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006061 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00006062}
Mike Stump1eb44332009-09-09 15:08:12 +00006063
Richard Smithad762fc2011-04-14 22:09:26 +00006064template<typename Derived>
6065StmtResult
6066TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6067 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6068 if (Range.isInvalid())
6069 return StmtError();
6070
6071 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6072 if (BeginEnd.isInvalid())
6073 return StmtError();
6074
6075 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6076 if (Cond.isInvalid())
6077 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006078 if (Cond.get())
6079 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
6080 if (Cond.isInvalid())
6081 return StmtError();
6082 if (Cond.get())
6083 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006084
6085 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6086 if (Inc.isInvalid())
6087 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00006088 if (Inc.get())
6089 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00006090
6091 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6092 if (LoopVar.isInvalid())
6093 return StmtError();
6094
6095 StmtResult NewStmt = S;
6096 if (getDerived().AlwaysRebuild() ||
6097 Range.get() != S->getRangeStmt() ||
6098 BeginEnd.get() != S->getBeginEndStmt() ||
6099 Cond.get() != S->getCond() ||
6100 Inc.get() != S->getInc() ||
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006101 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smithad762fc2011-04-14 22:09:26 +00006102 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6103 S->getColonLoc(), Range.get(),
6104 BeginEnd.get(), Cond.get(),
6105 Inc.get(), LoopVar.get(),
6106 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006107 if (NewStmt.isInvalid())
6108 return StmtError();
6109 }
Richard Smithad762fc2011-04-14 22:09:26 +00006110
6111 StmtResult Body = getDerived().TransformStmt(S->getBody());
6112 if (Body.isInvalid())
6113 return StmtError();
6114
6115 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6116 // it now so we have a new statement to attach the body to.
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006117 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smithad762fc2011-04-14 22:09:26 +00006118 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6119 S->getColonLoc(), Range.get(),
6120 BeginEnd.get(), Cond.get(),
6121 Inc.get(), LoopVar.get(),
6122 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006123 if (NewStmt.isInvalid())
6124 return StmtError();
6125 }
Richard Smithad762fc2011-04-14 22:09:26 +00006126
6127 if (NewStmt.get() == S)
6128 return SemaRef.Owned(S);
6129
6130 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6131}
6132
John Wiegley28bbe4b2011-04-28 01:08:34 +00006133template<typename Derived>
6134StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00006135TreeTransform<Derived>::TransformMSDependentExistsStmt(
6136 MSDependentExistsStmt *S) {
6137 // Transform the nested-name-specifier, if any.
6138 NestedNameSpecifierLoc QualifierLoc;
6139 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006140 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00006141 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6142 if (!QualifierLoc)
6143 return StmtError();
6144 }
6145
6146 // Transform the declaration name.
6147 DeclarationNameInfo NameInfo = S->getNameInfo();
6148 if (NameInfo.getName()) {
6149 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6150 if (!NameInfo.getName())
6151 return StmtError();
6152 }
6153
6154 // Check whether anything changed.
6155 if (!getDerived().AlwaysRebuild() &&
6156 QualifierLoc == S->getQualifierLoc() &&
6157 NameInfo.getName() == S->getNameInfo().getName())
6158 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006159
Douglas Gregorba0513d2011-10-25 01:33:02 +00006160 // Determine whether this name exists, if we can.
6161 CXXScopeSpec SS;
6162 SS.Adopt(QualifierLoc);
6163 bool Dependent = false;
6164 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6165 case Sema::IER_Exists:
6166 if (S->isIfExists())
6167 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006168
Douglas Gregorba0513d2011-10-25 01:33:02 +00006169 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6170
6171 case Sema::IER_DoesNotExist:
6172 if (S->isIfNotExists())
6173 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006174
Douglas Gregorba0513d2011-10-25 01:33:02 +00006175 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006176
Douglas Gregorba0513d2011-10-25 01:33:02 +00006177 case Sema::IER_Dependent:
6178 Dependent = true;
6179 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006180
Douglas Gregor65019ac2011-10-25 03:44:56 +00006181 case Sema::IER_Error:
6182 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006183 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006184
Douglas Gregorba0513d2011-10-25 01:33:02 +00006185 // We need to continue with the instantiation, so do so now.
6186 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6187 if (SubStmt.isInvalid())
6188 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006189
Douglas Gregorba0513d2011-10-25 01:33:02 +00006190 // If we have resolved the name, just transform to the substatement.
6191 if (!Dependent)
6192 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006193
Douglas Gregorba0513d2011-10-25 01:33:02 +00006194 // The name is still dependent, so build a dependent expression again.
6195 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6196 S->isIfExists(),
6197 QualifierLoc,
6198 NameInfo,
6199 SubStmt.get());
6200}
6201
6202template<typename Derived>
John McCall76da55d2013-04-16 07:28:30 +00006203ExprResult
6204TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6205 NestedNameSpecifierLoc QualifierLoc;
6206 if (E->getQualifierLoc()) {
6207 QualifierLoc
6208 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6209 if (!QualifierLoc)
6210 return ExprError();
6211 }
6212
6213 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6214 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6215 if (!PD)
6216 return ExprError();
6217
6218 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6219 if (Base.isInvalid())
6220 return ExprError();
6221
6222 return new (SemaRef.getASTContext())
6223 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6224 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6225 QualifierLoc, E->getMemberLoc());
6226}
6227
David Majnemerfc210492013-10-15 09:33:02 +00006228template <typename Derived>
6229StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7752a742013-10-15 09:30:14 +00006230 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfc210492013-10-15 09:33:02 +00006231 if (TryBlock.isInvalid())
6232 return StmtError();
John Wiegley28bbe4b2011-04-28 01:08:34 +00006233
6234 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7752a742013-10-15 09:30:14 +00006235 if (Handler.isInvalid())
6236 return StmtError();
6237
David Majnemerfc210492013-10-15 09:33:02 +00006238 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6239 Handler.get() == S->getHandler())
John Wiegley28bbe4b2011-04-28 01:08:34 +00006240 return SemaRef.Owned(S);
6241
David Majnemerfc210492013-10-15 09:33:02 +00006242 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6243 TryBlock.take(), Handler.take());
John Wiegley28bbe4b2011-04-28 01:08:34 +00006244}
6245
David Majnemerfc210492013-10-15 09:33:02 +00006246template <typename Derived>
6247StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7752a742013-10-15 09:30:14 +00006248 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfc210492013-10-15 09:33:02 +00006249 if (Block.isInvalid())
6250 return StmtError();
John Wiegley28bbe4b2011-04-28 01:08:34 +00006251
David Majnemerfc210492013-10-15 09:33:02 +00006252 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.take());
John Wiegley28bbe4b2011-04-28 01:08:34 +00006253}
6254
David Majnemerfc210492013-10-15 09:33:02 +00006255template <typename Derived>
6256StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley28bbe4b2011-04-28 01:08:34 +00006257 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfc210492013-10-15 09:33:02 +00006258 if (FilterExpr.isInvalid())
6259 return StmtError();
John Wiegley28bbe4b2011-04-28 01:08:34 +00006260
David Majnemer7752a742013-10-15 09:30:14 +00006261 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfc210492013-10-15 09:33:02 +00006262 if (Block.isInvalid())
6263 return StmtError();
John Wiegley28bbe4b2011-04-28 01:08:34 +00006264
David Majnemerfc210492013-10-15 09:33:02 +00006265 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.take(),
John Wiegley28bbe4b2011-04-28 01:08:34 +00006266 Block.take());
6267}
6268
David Majnemerfc210492013-10-15 09:33:02 +00006269template <typename Derived>
6270StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6271 if (isa<SEHFinallyStmt>(Handler))
John Wiegley28bbe4b2011-04-28 01:08:34 +00006272 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6273 else
6274 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6275}
6276
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006277template<typename Derived>
6278StmtResult
6279TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
Alexey Bataev0c018352013-09-06 18:03:48 +00006280 DeclarationNameInfo DirName;
6281 getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0);
6282
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006283 // Transform the clauses
Alexey Bataev0c018352013-09-06 18:03:48 +00006284 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006285 ArrayRef<OMPClause *> Clauses = D->clauses();
6286 TClauses.reserve(Clauses.size());
6287 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6288 I != E; ++I) {
6289 if (*I) {
6290 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataev0c018352013-09-06 18:03:48 +00006291 if (!Clause) {
6292 getSema().EndOpenMPDSABlock(0);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006293 return StmtError();
Alexey Bataev0c018352013-09-06 18:03:48 +00006294 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006295 TClauses.push_back(Clause);
6296 }
6297 else {
6298 TClauses.push_back(0);
6299 }
6300 }
Alexey Bataev0c018352013-09-06 18:03:48 +00006301 if (!D->getAssociatedStmt()) {
6302 getSema().EndOpenMPDSABlock(0);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006303 return StmtError();
Alexey Bataev0c018352013-09-06 18:03:48 +00006304 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006305 StmtResult AssociatedStmt =
6306 getDerived().TransformStmt(D->getAssociatedStmt());
Alexey Bataev0c018352013-09-06 18:03:48 +00006307 if (AssociatedStmt.isInvalid()) {
6308 getSema().EndOpenMPDSABlock(0);
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006309 return StmtError();
Alexey Bataev0c018352013-09-06 18:03:48 +00006310 }
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006311
Alexey Bataev0c018352013-09-06 18:03:48 +00006312 StmtResult Res = getDerived().RebuildOMPParallelDirective(TClauses,
6313 AssociatedStmt.take(),
6314 D->getLocStart(),
6315 D->getLocEnd());
6316 getSema().EndOpenMPDSABlock(Res.get());
6317 return Res;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006318}
6319
6320template<typename Derived>
6321OMPClause *
6322TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
6323 return getDerived().RebuildOMPDefaultClause(C->getDefaultKind(),
6324 C->getDefaultKindKwLoc(),
6325 C->getLocStart(),
6326 C->getLParenLoc(),
6327 C->getLocEnd());
6328}
6329
6330template<typename Derived>
6331OMPClause *
6332TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev0c018352013-09-06 18:03:48 +00006333 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006334 Vars.reserve(C->varlist_size());
Alexey Bataev543c4ae2013-09-24 03:17:45 +00006335 for (OMPPrivateClause::varlist_iterator I = C->varlist_begin(),
6336 E = C->varlist_end();
Alexey Bataev4fa7eab2013-07-19 03:13:43 +00006337 I != E; ++I) {
6338 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6339 if (EVar.isInvalid())
6340 return 0;
6341 Vars.push_back(EVar.take());
6342 }
6343 return getDerived().RebuildOMPPrivateClause(Vars,
6344 C->getLocStart(),
6345 C->getLParenLoc(),
6346 C->getLocEnd());
6347}
6348
Alexey Bataev0c018352013-09-06 18:03:48 +00006349template<typename Derived>
6350OMPClause *
Alexey Bataevd195bc32013-10-01 05:32:34 +00006351TreeTransform<Derived>::TransformOMPFirstprivateClause(
6352 OMPFirstprivateClause *C) {
6353 llvm::SmallVector<Expr *, 16> Vars;
6354 Vars.reserve(C->varlist_size());
6355 for (OMPFirstprivateClause::varlist_iterator I = C->varlist_begin(),
6356 E = C->varlist_end();
6357 I != E; ++I) {
6358 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6359 if (EVar.isInvalid())
6360 return 0;
6361 Vars.push_back(EVar.take());
6362 }
6363 return getDerived().RebuildOMPFirstprivateClause(Vars,
6364 C->getLocStart(),
6365 C->getLParenLoc(),
6366 C->getLocEnd());
6367}
6368
6369template<typename Derived>
6370OMPClause *
Alexey Bataev0c018352013-09-06 18:03:48 +00006371TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
6372 llvm::SmallVector<Expr *, 16> Vars;
6373 Vars.reserve(C->varlist_size());
Alexey Bataev543c4ae2013-09-24 03:17:45 +00006374 for (OMPSharedClause::varlist_iterator I = C->varlist_begin(),
6375 E = C->varlist_end();
Alexey Bataev0c018352013-09-06 18:03:48 +00006376 I != E; ++I) {
6377 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(*I));
6378 if (EVar.isInvalid())
6379 return 0;
6380 Vars.push_back(EVar.take());
6381 }
6382 return getDerived().RebuildOMPSharedClause(Vars,
6383 C->getLocStart(),
6384 C->getLParenLoc(),
6385 C->getLocEnd());
6386}
6387
Douglas Gregor43959a92009-08-20 07:17:43 +00006388//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006389// Expression transformation
6390//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006391template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006392ExprResult
John McCall454feb92009-12-08 09:21:05 +00006393TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006394 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006395}
Mike Stump1eb44332009-09-09 15:08:12 +00006396
6397template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006398ExprResult
John McCall454feb92009-12-08 09:21:05 +00006399TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006400 NestedNameSpecifierLoc QualifierLoc;
6401 if (E->getQualifierLoc()) {
6402 QualifierLoc
6403 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6404 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006405 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006406 }
John McCalldbd872f2009-12-08 09:08:17 +00006407
6408 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006409 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6410 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006411 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006412 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006413
John McCallec8045d2010-08-17 21:27:17 +00006414 DeclarationNameInfo NameInfo = E->getNameInfo();
6415 if (NameInfo.getName()) {
6416 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6417 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006418 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006419 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006420
6421 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006422 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006423 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006424 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006425 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006426
6427 // Mark it referenced in the new context regardless.
6428 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006429 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006430
John McCall3fa5cae2010-10-26 07:05:15 +00006431 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006432 }
John McCalldbd872f2009-12-08 09:08:17 +00006433
6434 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006435 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006436 TemplateArgs = &TransArgs;
6437 TransArgs.setLAngleLoc(E->getLAngleLoc());
6438 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006439 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6440 E->getNumTemplateArgs(),
6441 TransArgs))
6442 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006443 }
6444
Chad Rosier4a9d7952012-08-08 18:46:20 +00006445 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006446 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006447}
Mike Stump1eb44332009-09-09 15:08:12 +00006448
Douglas Gregorb98b1992009-08-11 05:31:07 +00006449template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006450ExprResult
John McCall454feb92009-12-08 09:21:05 +00006451TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006452 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006453}
Mike Stump1eb44332009-09-09 15:08:12 +00006454
Douglas Gregorb98b1992009-08-11 05:31:07 +00006455template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006456ExprResult
John McCall454feb92009-12-08 09:21:05 +00006457TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006458 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006459}
Mike Stump1eb44332009-09-09 15:08:12 +00006460
Douglas Gregorb98b1992009-08-11 05:31:07 +00006461template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006462ExprResult
John McCall454feb92009-12-08 09:21:05 +00006463TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006464 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006465}
Mike Stump1eb44332009-09-09 15:08:12 +00006466
Douglas Gregorb98b1992009-08-11 05:31:07 +00006467template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006468ExprResult
John McCall454feb92009-12-08 09:21:05 +00006469TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006470 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006471}
Mike Stump1eb44332009-09-09 15:08:12 +00006472
Douglas Gregorb98b1992009-08-11 05:31:07 +00006473template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006474ExprResult
John McCall454feb92009-12-08 09:21:05 +00006475TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006476 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006477}
6478
6479template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006480ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006481TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis391ca9f2013-04-09 01:17:02 +00006482 if (FunctionDecl *FD = E->getDirectCallee())
6483 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smith9fcce652012-03-07 08:35:16 +00006484 return SemaRef.MaybeBindToTemporary(E);
6485}
6486
6487template<typename Derived>
6488ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006489TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6490 ExprResult ControllingExpr =
6491 getDerived().TransformExpr(E->getControllingExpr());
6492 if (ControllingExpr.isInvalid())
6493 return ExprError();
6494
Chris Lattner686775d2011-07-20 06:58:45 +00006495 SmallVector<Expr *, 4> AssocExprs;
6496 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006497 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6498 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6499 if (TS) {
6500 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6501 if (!AssocType)
6502 return ExprError();
6503 AssocTypes.push_back(AssocType);
6504 } else {
6505 AssocTypes.push_back(0);
6506 }
6507
6508 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6509 if (AssocExpr.isInvalid())
6510 return ExprError();
6511 AssocExprs.push_back(AssocExpr.release());
6512 }
6513
6514 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6515 E->getDefaultLoc(),
6516 E->getRParenLoc(),
6517 ControllingExpr.release(),
Dmitri Gribenko80613222013-05-10 13:06:58 +00006518 AssocTypes,
6519 AssocExprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00006520}
6521
6522template<typename Derived>
6523ExprResult
John McCall454feb92009-12-08 09:21:05 +00006524TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006525 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006526 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006527 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006528
Douglas Gregorb98b1992009-08-11 05:31:07 +00006529 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006530 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006531
John McCall9ae2f072010-08-23 23:25:46 +00006532 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006533 E->getRParen());
6534}
6535
Richard Smithefeeccf2012-10-21 03:28:35 +00006536/// \brief The operand of a unary address-of operator has special rules: it's
6537/// allowed to refer to a non-static member of a class even if there's no 'this'
6538/// object available.
6539template<typename Derived>
6540ExprResult
6541TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6542 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6543 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6544 else
6545 return getDerived().TransformExpr(E);
6546}
6547
Mike Stump1eb44332009-09-09 15:08:12 +00006548template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006549ExprResult
John McCall454feb92009-12-08 09:21:05 +00006550TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smith82b00012013-05-21 23:29:46 +00006551 ExprResult SubExpr;
6552 if (E->getOpcode() == UO_AddrOf)
6553 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6554 else
6555 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006556 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006557 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006558
Douglas Gregorb98b1992009-08-11 05:31:07 +00006559 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006560 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006561
Douglas Gregorb98b1992009-08-11 05:31:07 +00006562 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6563 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006564 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006565}
Mike Stump1eb44332009-09-09 15:08:12 +00006566
Douglas Gregorb98b1992009-08-11 05:31:07 +00006567template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006568ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006569TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6570 // Transform the type.
6571 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6572 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006573 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006574
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006575 // Transform all of the components into components similar to what the
6576 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006577 // FIXME: It would be slightly more efficient in the non-dependent case to
6578 // just map FieldDecls, rather than requiring the rebuilder to look for
6579 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006580 // template code that we don't care.
6581 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006582 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006583 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006584 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006585 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6586 const Node &ON = E->getComponent(I);
6587 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006588 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006589 Comp.LocStart = ON.getSourceRange().getBegin();
6590 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006591 switch (ON.getKind()) {
6592 case Node::Array: {
6593 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006594 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006595 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006596 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006597
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006598 ExprChanged = ExprChanged || Index.get() != FromIndex;
6599 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006600 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006601 break;
6602 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006603
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006604 case Node::Field:
6605 case Node::Identifier:
6606 Comp.isBrackets = false;
6607 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006608 if (!Comp.U.IdentInfo)
6609 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006610
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006611 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006612
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006613 case Node::Base:
6614 // Will be recomputed during the rebuild.
6615 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006616 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006617
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006618 Components.push_back(Comp);
6619 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006620
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006621 // If nothing changed, retain the existing expression.
6622 if (!getDerived().AlwaysRebuild() &&
6623 Type == E->getTypeSourceInfo() &&
6624 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006625 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006626
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006627 // Build a new offsetof expression.
6628 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6629 Components.data(), Components.size(),
6630 E->getRParenLoc());
6631}
6632
6633template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006634ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006635TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6636 assert(getDerived().AlreadyTransformed(E->getType()) &&
6637 "opaque value expression requires transformation");
6638 return SemaRef.Owned(E);
6639}
6640
6641template<typename Derived>
6642ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006643TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006644 // Rebuild the syntactic form. The original syntactic form has
6645 // opaque-value expressions in it, so strip those away and rebuild
6646 // the result. This is a really awful way of doing this, but the
6647 // better solution (rebuilding the semantic expressions and
6648 // rebinding OVEs as necessary) doesn't work; we'd need
6649 // TreeTransform to not strip away implicit conversions.
6650 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6651 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006652 if (result.isInvalid()) return ExprError();
6653
6654 // If that gives us a pseudo-object result back, the pseudo-object
6655 // expression must have been an lvalue-to-rvalue conversion which we
6656 // should reapply.
6657 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6658 result = SemaRef.checkPseudoObjectRValue(result.take());
6659
6660 return result;
6661}
6662
6663template<typename Derived>
6664ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006665TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6666 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006667 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006668 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006669
John McCalla93c9342009-12-07 02:54:59 +00006670 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006671 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006672 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006673
John McCall5ab75172009-11-04 07:28:41 +00006674 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006675 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006676
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006677 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6678 E->getKind(),
6679 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006680 }
Mike Stump1eb44332009-09-09 15:08:12 +00006681
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006682 // C++0x [expr.sizeof]p1:
6683 // The operand is either an expression, which is an unevaluated operand
6684 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006685 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6686 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006687
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006688 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6689 if (SubExpr.isInvalid())
6690 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006691
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006692 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6693 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006694
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006695 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6696 E->getOperatorLoc(),
6697 E->getKind(),
6698 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006699}
Mike Stump1eb44332009-09-09 15:08:12 +00006700
Douglas Gregorb98b1992009-08-11 05:31:07 +00006701template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006702ExprResult
John McCall454feb92009-12-08 09:21:05 +00006703TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006704 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006705 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006706 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006707
John McCall60d7b3a2010-08-24 06:29:42 +00006708 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006709 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006710 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006711
6712
Douglas Gregorb98b1992009-08-11 05:31:07 +00006713 if (!getDerived().AlwaysRebuild() &&
6714 LHS.get() == E->getLHS() &&
6715 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006716 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006717
John McCall9ae2f072010-08-23 23:25:46 +00006718 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006719 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006720 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006721 E->getRBracketLoc());
6722}
Mike Stump1eb44332009-09-09 15:08:12 +00006723
6724template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006725ExprResult
John McCall454feb92009-12-08 09:21:05 +00006726TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006727 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006728 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006729 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006730 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006731
6732 // Transform arguments.
6733 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006734 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006735 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006736 &ArgChanged))
6737 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006738
Douglas Gregorb98b1992009-08-11 05:31:07 +00006739 if (!getDerived().AlwaysRebuild() &&
6740 Callee.get() == E->getCallee() &&
6741 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006742 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006743
Douglas Gregorb98b1992009-08-11 05:31:07 +00006744 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006745 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006746 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006747 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006748 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006749 E->getRParenLoc());
6750}
Mike Stump1eb44332009-09-09 15:08:12 +00006751
6752template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006753ExprResult
John McCall454feb92009-12-08 09:21:05 +00006754TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006755 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006756 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006757 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006758
Douglas Gregor40d96a62011-02-28 21:54:11 +00006759 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006760 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006761 QualifierLoc
6762 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006763
Douglas Gregor40d96a62011-02-28 21:54:11 +00006764 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006765 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006766 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006767 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006768
Eli Friedmanf595cc42009-12-04 06:40:45 +00006769 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006770 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6771 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006772 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006773 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006774
John McCall6bb80172010-03-30 21:47:33 +00006775 NamedDecl *FoundDecl = E->getFoundDecl();
6776 if (FoundDecl == E->getMemberDecl()) {
6777 FoundDecl = Member;
6778 } else {
6779 FoundDecl = cast_or_null<NamedDecl>(
6780 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6781 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006782 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006783 }
6784
Douglas Gregorb98b1992009-08-11 05:31:07 +00006785 if (!getDerived().AlwaysRebuild() &&
6786 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006787 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006788 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006789 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006790 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006791
Anders Carlsson1f240322009-12-22 05:24:09 +00006792 // Mark it referenced in the new context regardless.
6793 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006794 SemaRef.MarkMemberReferenced(E);
6795
John McCall3fa5cae2010-10-26 07:05:15 +00006796 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006797 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006798
John McCalld5532b62009-11-23 01:53:49 +00006799 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006800 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006801 TransArgs.setLAngleLoc(E->getLAngleLoc());
6802 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006803 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6804 E->getNumTemplateArgs(),
6805 TransArgs))
6806 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006807 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006808
Douglas Gregorb98b1992009-08-11 05:31:07 +00006809 // FIXME: Bogus source location for the operator
6810 SourceLocation FakeOperatorLoc
6811 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6812
John McCallc2233c52010-01-15 08:34:02 +00006813 // FIXME: to do this check properly, we will need to preserve the
6814 // first-qualifier-in-scope here, just in case we had a dependent
6815 // base (and therefore couldn't do the check) and a
6816 // nested-name-qualifier (and therefore could do the lookup).
6817 NamedDecl *FirstQualifierInScope = 0;
6818
John McCall9ae2f072010-08-23 23:25:46 +00006819 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006820 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006821 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006822 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006823 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006824 Member,
John McCall6bb80172010-03-30 21:47:33 +00006825 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006826 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006827 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006828 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006829}
Mike Stump1eb44332009-09-09 15:08:12 +00006830
Douglas Gregorb98b1992009-08-11 05:31:07 +00006831template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006832ExprResult
John McCall454feb92009-12-08 09:21:05 +00006833TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006834 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006835 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006836 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006837
John McCall60d7b3a2010-08-24 06:29:42 +00006838 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006839 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006840 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006841
Douglas Gregorb98b1992009-08-11 05:31:07 +00006842 if (!getDerived().AlwaysRebuild() &&
6843 LHS.get() == E->getLHS() &&
6844 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006845 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006846
Lang Hamesbe9af122012-10-02 04:45:10 +00006847 Sema::FPContractStateRAII FPContractState(getSema());
6848 getSema().FPFeatures.fp_contract = E->isFPContractable();
6849
Douglas Gregorb98b1992009-08-11 05:31:07 +00006850 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006851 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006852}
6853
Mike Stump1eb44332009-09-09 15:08:12 +00006854template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006855ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006856TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006857 CompoundAssignOperator *E) {
6858 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006859}
Mike Stump1eb44332009-09-09 15:08:12 +00006860
Douglas Gregorb98b1992009-08-11 05:31:07 +00006861template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006862ExprResult TreeTransform<Derived>::
6863TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6864 // Just rebuild the common and RHS expressions and see whether we
6865 // get any changes.
6866
6867 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6868 if (commonExpr.isInvalid())
6869 return ExprError();
6870
6871 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6872 if (rhs.isInvalid())
6873 return ExprError();
6874
6875 if (!getDerived().AlwaysRebuild() &&
6876 commonExpr.get() == e->getCommon() &&
6877 rhs.get() == e->getFalseExpr())
6878 return SemaRef.Owned(e);
6879
6880 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6881 e->getQuestionLoc(),
6882 0,
6883 e->getColonLoc(),
6884 rhs.get());
6885}
6886
6887template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006888ExprResult
John McCall454feb92009-12-08 09:21:05 +00006889TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006890 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006891 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006892 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006893
John McCall60d7b3a2010-08-24 06:29:42 +00006894 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006895 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006896 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006897
John McCall60d7b3a2010-08-24 06:29:42 +00006898 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006899 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006900 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006901
Douglas Gregorb98b1992009-08-11 05:31:07 +00006902 if (!getDerived().AlwaysRebuild() &&
6903 Cond.get() == E->getCond() &&
6904 LHS.get() == E->getLHS() &&
6905 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006906 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006907
John McCall9ae2f072010-08-23 23:25:46 +00006908 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006909 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006910 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006911 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006912 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006913}
Mike Stump1eb44332009-09-09 15:08:12 +00006914
6915template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006916ExprResult
John McCall454feb92009-12-08 09:21:05 +00006917TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006918 // Implicit casts are eliminated during transformation, since they
6919 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006920 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006921}
Mike Stump1eb44332009-09-09 15:08:12 +00006922
Douglas Gregorb98b1992009-08-11 05:31:07 +00006923template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006924ExprResult
John McCall454feb92009-12-08 09:21:05 +00006925TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006926 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6927 if (!Type)
6928 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006929
John McCall60d7b3a2010-08-24 06:29:42 +00006930 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006931 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006932 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006933 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006934
Douglas Gregorb98b1992009-08-11 05:31:07 +00006935 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006936 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006937 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006938 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006939
John McCall9d125032010-01-15 18:39:57 +00006940 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006941 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006942 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006943 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006944}
Mike Stump1eb44332009-09-09 15:08:12 +00006945
Douglas Gregorb98b1992009-08-11 05:31:07 +00006946template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006947ExprResult
John McCall454feb92009-12-08 09:21:05 +00006948TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006949 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6950 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6951 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006952 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006953
John McCall60d7b3a2010-08-24 06:29:42 +00006954 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006955 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006956 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006957
Douglas Gregorb98b1992009-08-11 05:31:07 +00006958 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006959 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006960 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006961 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006962
John McCall1d7d8d62010-01-19 22:33:45 +00006963 // Note: the expression type doesn't necessarily match the
6964 // type-as-written, but that's okay, because it should always be
6965 // derivable from the initializer.
6966
John McCall42f56b52010-01-18 19:35:47 +00006967 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006968 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006969 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006970}
Mike Stump1eb44332009-09-09 15:08:12 +00006971
Douglas Gregorb98b1992009-08-11 05:31:07 +00006972template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006973ExprResult
John McCall454feb92009-12-08 09:21:05 +00006974TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006975 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006976 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006977 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006978
Douglas Gregorb98b1992009-08-11 05:31:07 +00006979 if (!getDerived().AlwaysRebuild() &&
6980 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006981 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006982
Douglas Gregorb98b1992009-08-11 05:31:07 +00006983 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006984 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006985 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006986 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006987 E->getAccessorLoc(),
6988 E->getAccessor());
6989}
Mike Stump1eb44332009-09-09 15:08:12 +00006990
Douglas Gregorb98b1992009-08-11 05:31:07 +00006991template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006992ExprResult
John McCall454feb92009-12-08 09:21:05 +00006993TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006994 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006995
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006996 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006997 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006998 Inits, &InitChanged))
6999 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007000
Douglas Gregorb98b1992009-08-11 05:31:07 +00007001 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007002 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007003
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007004 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00007005 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007006}
Mike Stump1eb44332009-09-09 15:08:12 +00007007
Douglas Gregorb98b1992009-08-11 05:31:07 +00007008template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007009ExprResult
John McCall454feb92009-12-08 09:21:05 +00007010TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007011 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00007012
Douglas Gregor43959a92009-08-20 07:17:43 +00007013 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00007014 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007015 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007016 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007017
Douglas Gregor43959a92009-08-20 07:17:43 +00007018 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007019 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007020 bool ExprChanged = false;
7021 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
7022 DEnd = E->designators_end();
7023 D != DEnd; ++D) {
7024 if (D->isFieldDesignator()) {
7025 Desig.AddDesignator(Designator::getField(D->getFieldName(),
7026 D->getDotLoc(),
7027 D->getFieldLoc()));
7028 continue;
7029 }
Mike Stump1eb44332009-09-09 15:08:12 +00007030
Douglas Gregorb98b1992009-08-11 05:31:07 +00007031 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00007032 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007033 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007034 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007035
7036 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007037 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00007038
Douglas Gregorb98b1992009-08-11 05:31:07 +00007039 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
7040 ArrayExprs.push_back(Index.release());
7041 continue;
7042 }
Mike Stump1eb44332009-09-09 15:08:12 +00007043
Douglas Gregorb98b1992009-08-11 05:31:07 +00007044 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00007045 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00007046 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
7047 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007048 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007049
John McCall60d7b3a2010-08-24 06:29:42 +00007050 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007051 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007052 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007053
7054 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007055 End.get(),
7056 D->getLBracketLoc(),
7057 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00007058
Douglas Gregorb98b1992009-08-11 05:31:07 +00007059 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
7060 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00007061
Douglas Gregorb98b1992009-08-11 05:31:07 +00007062 ArrayExprs.push_back(Start.release());
7063 ArrayExprs.push_back(End.release());
7064 }
Mike Stump1eb44332009-09-09 15:08:12 +00007065
Douglas Gregorb98b1992009-08-11 05:31:07 +00007066 if (!getDerived().AlwaysRebuild() &&
7067 Init.get() == E->getInit() &&
7068 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007069 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007070
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007071 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007072 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007073 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007074}
Mike Stump1eb44332009-09-09 15:08:12 +00007075
Douglas Gregorb98b1992009-08-11 05:31:07 +00007076template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007077ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007078TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00007079 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00007080 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007081
Douglas Gregor5557b252009-10-28 00:29:27 +00007082 // FIXME: Will we ever have proper type location here? Will we actually
7083 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00007084 QualType T = getDerived().TransformType(E->getType());
7085 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007086 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007087
Douglas Gregorb98b1992009-08-11 05:31:07 +00007088 if (!getDerived().AlwaysRebuild() &&
7089 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00007090 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007091
Douglas Gregorb98b1992009-08-11 05:31:07 +00007092 return getDerived().RebuildImplicitValueInitExpr(T);
7093}
Mike Stump1eb44332009-09-09 15:08:12 +00007094
Douglas Gregorb98b1992009-08-11 05:31:07 +00007095template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007096ExprResult
John McCall454feb92009-12-08 09:21:05 +00007097TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00007098 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
7099 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007100 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007101
John McCall60d7b3a2010-08-24 06:29:42 +00007102 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007103 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007104 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007105
Douglas Gregorb98b1992009-08-11 05:31:07 +00007106 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007107 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007108 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007109 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007110
John McCall9ae2f072010-08-23 23:25:46 +00007111 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00007112 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007113}
7114
7115template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007116ExprResult
John McCall454feb92009-12-08 09:21:05 +00007117TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007118 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007119 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00007120 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
7121 &ArgumentChanged))
7122 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007123
Douglas Gregorb98b1992009-08-11 05:31:07 +00007124 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007125 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007126 E->getRParenLoc());
7127}
Mike Stump1eb44332009-09-09 15:08:12 +00007128
Douglas Gregorb98b1992009-08-11 05:31:07 +00007129/// \brief Transform an address-of-label expression.
7130///
7131/// By default, the transformation of an address-of-label expression always
7132/// rebuilds the expression, so that the label identifier can be resolved to
7133/// the corresponding label statement by semantic analysis.
7134template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007135ExprResult
John McCall454feb92009-12-08 09:21:05 +00007136TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00007137 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
7138 E->getLabel());
7139 if (!LD)
7140 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007141
Douglas Gregorb98b1992009-08-11 05:31:07 +00007142 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00007143 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007144}
Mike Stump1eb44332009-09-09 15:08:12 +00007145
7146template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00007147ExprResult
John McCall454feb92009-12-08 09:21:05 +00007148TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00007149 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00007150 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00007151 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00007152 if (SubStmt.isInvalid()) {
7153 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00007154 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00007155 }
Mike Stump1eb44332009-09-09 15:08:12 +00007156
Douglas Gregorb98b1992009-08-11 05:31:07 +00007157 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00007158 SubStmt.get() == E->getSubStmt()) {
7159 // Calling this an 'error' is unintuitive, but it does the right thing.
7160 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00007161 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00007162 }
Mike Stump1eb44332009-09-09 15:08:12 +00007163
7164 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007165 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007166 E->getRParenLoc());
7167}
Mike Stump1eb44332009-09-09 15:08:12 +00007168
Douglas Gregorb98b1992009-08-11 05:31:07 +00007169template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007170ExprResult
John McCall454feb92009-12-08 09:21:05 +00007171TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007172 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007173 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007174 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007175
John McCall60d7b3a2010-08-24 06:29:42 +00007176 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007177 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007178 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007179
John McCall60d7b3a2010-08-24 06:29:42 +00007180 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007181 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007182 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007183
Douglas Gregorb98b1992009-08-11 05:31:07 +00007184 if (!getDerived().AlwaysRebuild() &&
7185 Cond.get() == E->getCond() &&
7186 LHS.get() == E->getLHS() &&
7187 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00007188 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007189
Douglas Gregorb98b1992009-08-11 05:31:07 +00007190 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007191 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007192 E->getRParenLoc());
7193}
Mike Stump1eb44332009-09-09 15:08:12 +00007194
Douglas Gregorb98b1992009-08-11 05:31:07 +00007195template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007196ExprResult
John McCall454feb92009-12-08 09:21:05 +00007197TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007198 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007199}
7200
7201template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007202ExprResult
John McCall454feb92009-12-08 09:21:05 +00007203TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00007204 switch (E->getOperator()) {
7205 case OO_New:
7206 case OO_Delete:
7207 case OO_Array_New:
7208 case OO_Array_Delete:
7209 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00007210
Douglas Gregor668d6d92009-12-13 20:44:55 +00007211 case OO_Call: {
7212 // This is a call to an object's operator().
7213 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7214
7215 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00007216 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00007217 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007218 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007219
7220 // FIXME: Poor location information
7221 SourceLocation FakeLParenLoc
7222 = SemaRef.PP.getLocForEndOfToken(
7223 static_cast<Expr *>(Object.get())->getLocEnd());
7224
7225 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007226 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007227 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007228 Args))
7229 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007230
John McCall9ae2f072010-08-23 23:25:46 +00007231 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007232 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00007233 E->getLocEnd());
7234 }
7235
7236#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7237 case OO_##Name:
7238#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7239#include "clang/Basic/OperatorKinds.def"
7240 case OO_Subscript:
7241 // Handled below.
7242 break;
7243
7244 case OO_Conditional:
7245 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007246
7247 case OO_None:
7248 case NUM_OVERLOADED_OPERATORS:
7249 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007250 }
7251
John McCall60d7b3a2010-08-24 06:29:42 +00007252 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007253 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007254 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007255
Richard Smithefeeccf2012-10-21 03:28:35 +00007256 ExprResult First;
7257 if (E->getOperator() == OO_Amp)
7258 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7259 else
7260 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007261 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007262 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007263
John McCall60d7b3a2010-08-24 06:29:42 +00007264 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007265 if (E->getNumArgs() == 2) {
7266 Second = getDerived().TransformExpr(E->getArg(1));
7267 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007268 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007269 }
Mike Stump1eb44332009-09-09 15:08:12 +00007270
Douglas Gregorb98b1992009-08-11 05:31:07 +00007271 if (!getDerived().AlwaysRebuild() &&
7272 Callee.get() == E->getCallee() &&
7273 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00007274 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00007275 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007276
Lang Hamesbe9af122012-10-02 04:45:10 +00007277 Sema::FPContractStateRAII FPContractState(getSema());
7278 getSema().FPFeatures.fp_contract = E->isFPContractable();
7279
Douglas Gregorb98b1992009-08-11 05:31:07 +00007280 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7281 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007282 Callee.get(),
7283 First.get(),
7284 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007285}
Mike Stump1eb44332009-09-09 15:08:12 +00007286
Douglas Gregorb98b1992009-08-11 05:31:07 +00007287template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007288ExprResult
John McCall454feb92009-12-08 09:21:05 +00007289TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7290 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007291}
Mike Stump1eb44332009-09-09 15:08:12 +00007292
Douglas Gregorb98b1992009-08-11 05:31:07 +00007293template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007294ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00007295TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7296 // Transform the callee.
7297 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7298 if (Callee.isInvalid())
7299 return ExprError();
7300
7301 // Transform exec config.
7302 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7303 if (EC.isInvalid())
7304 return ExprError();
7305
7306 // Transform arguments.
7307 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007308 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007309 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007310 &ArgChanged))
7311 return ExprError();
7312
7313 if (!getDerived().AlwaysRebuild() &&
7314 Callee.get() == E->getCallee() &&
7315 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007316 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00007317
7318 // FIXME: Wrong source location information for the '('.
7319 SourceLocation FakeLParenLoc
7320 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7321 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007322 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007323 E->getRParenLoc(), EC.get());
7324}
7325
7326template<typename Derived>
7327ExprResult
John McCall454feb92009-12-08 09:21:05 +00007328TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007329 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7330 if (!Type)
7331 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007332
John McCall60d7b3a2010-08-24 06:29:42 +00007333 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007334 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007335 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007336 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007337
Douglas Gregorb98b1992009-08-11 05:31:07 +00007338 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007339 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007340 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007341 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007342 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007343 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007344 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007345 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007346 E->getAngleBrackets().getEnd(),
7347 // FIXME. this should be '(' location
7348 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007349 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007350 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007351}
Mike Stump1eb44332009-09-09 15:08:12 +00007352
Douglas Gregorb98b1992009-08-11 05:31:07 +00007353template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007354ExprResult
John McCall454feb92009-12-08 09:21:05 +00007355TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7356 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007357}
Mike Stump1eb44332009-09-09 15:08:12 +00007358
7359template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007360ExprResult
John McCall454feb92009-12-08 09:21:05 +00007361TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7362 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007363}
7364
Douglas Gregorb98b1992009-08-11 05:31:07 +00007365template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007366ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007367TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007368 CXXReinterpretCastExpr *E) {
7369 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007370}
Mike Stump1eb44332009-09-09 15:08:12 +00007371
Douglas Gregorb98b1992009-08-11 05:31:07 +00007372template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007373ExprResult
John McCall454feb92009-12-08 09:21:05 +00007374TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7375 return getDerived().TransformCXXNamedCastExpr(E);
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
Douglas Gregorb98b1992009-08-11 05:31:07 +00007380TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007381 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007382 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7383 if (!Type)
7384 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007385
John McCall60d7b3a2010-08-24 06:29:42 +00007386 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007387 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007388 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007389 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007390
Douglas Gregorb98b1992009-08-11 05:31:07 +00007391 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007392 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007393 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007394 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007395
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007396 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedmancdd4b782013-08-15 22:02:56 +00007397 E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007398 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007399 E->getRParenLoc());
7400}
Mike Stump1eb44332009-09-09 15:08:12 +00007401
Douglas Gregorb98b1992009-08-11 05:31:07 +00007402template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007403ExprResult
John McCall454feb92009-12-08 09:21:05 +00007404TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007405 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007406 TypeSourceInfo *TInfo
7407 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7408 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007409 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007410
Douglas Gregorb98b1992009-08-11 05:31:07 +00007411 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007412 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007413 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007414
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007415 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7416 E->getLocStart(),
7417 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007418 E->getLocEnd());
7419 }
Mike Stump1eb44332009-09-09 15:08:12 +00007420
Eli Friedmanef331b72012-01-20 01:26:23 +00007421 // We don't know whether the subexpression is potentially evaluated until
7422 // after we perform semantic analysis. We speculatively assume it is
7423 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007424 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007425 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7426 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007427
John McCall60d7b3a2010-08-24 06:29:42 +00007428 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007429 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007430 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007431
Douglas Gregorb98b1992009-08-11 05:31:07 +00007432 if (!getDerived().AlwaysRebuild() &&
7433 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007434 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007435
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007436 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7437 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007438 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007439 E->getLocEnd());
7440}
7441
7442template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007443ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007444TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7445 if (E->isTypeOperand()) {
7446 TypeSourceInfo *TInfo
7447 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7448 if (!TInfo)
7449 return ExprError();
7450
7451 if (!getDerived().AlwaysRebuild() &&
7452 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007453 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007454
Douglas Gregor3c52a212011-03-06 17:40:41 +00007455 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007456 E->getLocStart(),
7457 TInfo,
7458 E->getLocEnd());
7459 }
7460
Francois Pichet01b7c302010-09-08 12:20:18 +00007461 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7462
7463 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7464 if (SubExpr.isInvalid())
7465 return ExprError();
7466
7467 if (!getDerived().AlwaysRebuild() &&
7468 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007469 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007470
7471 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7472 E->getLocStart(),
7473 SubExpr.get(),
7474 E->getLocEnd());
7475}
7476
7477template<typename Derived>
7478ExprResult
John McCall454feb92009-12-08 09:21:05 +00007479TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007480 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007481}
Mike Stump1eb44332009-09-09 15:08:12 +00007482
Douglas Gregorb98b1992009-08-11 05:31:07 +00007483template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007484ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007485TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007486 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007487 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007488}
Mike Stump1eb44332009-09-09 15:08:12 +00007489
Douglas Gregorb98b1992009-08-11 05:31:07 +00007490template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007491ExprResult
John McCall454feb92009-12-08 09:21:05 +00007492TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithcafeb942013-06-07 02:33:37 +00007493 QualType T = getSema().getCurrentThisType();
Mike Stump1eb44332009-09-09 15:08:12 +00007494
Douglas Gregorec79d872012-02-24 17:41:38 +00007495 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7496 // Make sure that we capture 'this'.
7497 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007498 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007499 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007500
Douglas Gregor828a1972010-01-07 23:12:05 +00007501 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007502}
Mike Stump1eb44332009-09-09 15:08:12 +00007503
Douglas Gregorb98b1992009-08-11 05:31:07 +00007504template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007505ExprResult
John McCall454feb92009-12-08 09:21:05 +00007506TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007507 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007508 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007509 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007510
Douglas Gregorb98b1992009-08-11 05:31:07 +00007511 if (!getDerived().AlwaysRebuild() &&
7512 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007513 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007514
Douglas Gregorbca01b42011-07-06 22:04:06 +00007515 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7516 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007517}
Mike Stump1eb44332009-09-09 15:08:12 +00007518
Douglas Gregorb98b1992009-08-11 05:31:07 +00007519template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007520ExprResult
John McCall454feb92009-12-08 09:21:05 +00007521TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007522 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007523 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7524 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007525 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007526 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007527
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007528 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007529 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007530 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007531
Douglas Gregor036aed12009-12-23 23:03:06 +00007532 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007533}
Mike Stump1eb44332009-09-09 15:08:12 +00007534
Douglas Gregorb98b1992009-08-11 05:31:07 +00007535template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007536ExprResult
Richard Smithc3bf52c2013-04-20 22:23:05 +00007537TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7538 FieldDecl *Field
7539 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7540 E->getField()));
7541 if (!Field)
7542 return ExprError();
7543
7544 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7545 return SemaRef.Owned(E);
7546
7547 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7548}
7549
7550template<typename Derived>
7551ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007552TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7553 CXXScalarValueInitExpr *E) {
7554 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7555 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007556 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007557
Douglas Gregorb98b1992009-08-11 05:31:07 +00007558 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007559 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007560 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007561
Chad Rosier4a9d7952012-08-08 18:46:20 +00007562 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007563 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007564 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007565}
Mike Stump1eb44332009-09-09 15:08:12 +00007566
Douglas Gregorb98b1992009-08-11 05:31:07 +00007567template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007568ExprResult
John McCall454feb92009-12-08 09:21:05 +00007569TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007570 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007571 TypeSourceInfo *AllocTypeInfo
7572 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7573 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007574 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007575
Douglas Gregorb98b1992009-08-11 05:31:07 +00007576 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007577 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007578 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007579 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007580
Douglas Gregorb98b1992009-08-11 05:31:07 +00007581 // Transform the placement arguments (if any).
7582 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007583 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007584 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007585 E->getNumPlacementArgs(), true,
7586 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007587 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007588
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007589 // Transform the initializer (if any).
7590 Expr *OldInit = E->getInitializer();
7591 ExprResult NewInit;
7592 if (OldInit)
7593 NewInit = getDerived().TransformExpr(OldInit);
7594 if (NewInit.isInvalid())
7595 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007596
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007597 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007598 FunctionDecl *OperatorNew = 0;
7599 if (E->getOperatorNew()) {
7600 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007601 getDerived().TransformDecl(E->getLocStart(),
7602 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007603 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007604 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007605 }
7606
7607 FunctionDecl *OperatorDelete = 0;
7608 if (E->getOperatorDelete()) {
7609 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007610 getDerived().TransformDecl(E->getLocStart(),
7611 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007612 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007613 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007614 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007615
Douglas Gregorb98b1992009-08-11 05:31:07 +00007616 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007617 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007618 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007619 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007620 OperatorNew == E->getOperatorNew() &&
7621 OperatorDelete == E->getOperatorDelete() &&
7622 !ArgumentChanged) {
7623 // Mark any declarations we need as referenced.
7624 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007625 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007626 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007627 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007628 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007629
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007630 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007631 QualType ElementType
7632 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7633 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7634 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7635 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007636 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007637 }
7638 }
7639 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007640
John McCall3fa5cae2010-10-26 07:05:15 +00007641 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007642 }
Mike Stump1eb44332009-09-09 15:08:12 +00007643
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007644 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007645 if (!ArraySize.get()) {
7646 // If no array size was specified, but the new expression was
7647 // instantiated with an array type (e.g., "new T" where T is
7648 // instantiated with "int[4]"), extract the outer bound from the
7649 // array type as our array size. We do this with constant and
7650 // dependently-sized array types.
7651 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7652 if (!ArrayT) {
7653 // Do nothing
7654 } else if (const ConstantArrayType *ConsArrayT
7655 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007656 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007657 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007658 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007659 SemaRef.Context.getSizeType(),
7660 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007661 AllocType = ConsArrayT->getElementType();
7662 } else if (const DependentSizedArrayType *DepArrayT
7663 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7664 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007665 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007666 AllocType = DepArrayT->getElementType();
7667 }
7668 }
7669 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007670
Douglas Gregorb98b1992009-08-11 05:31:07 +00007671 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7672 E->isGlobalNew(),
7673 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007674 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007675 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007676 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007677 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007678 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007679 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007680 E->getDirectInitRange(),
7681 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007682}
Mike Stump1eb44332009-09-09 15:08:12 +00007683
Douglas Gregorb98b1992009-08-11 05:31:07 +00007684template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007685ExprResult
John McCall454feb92009-12-08 09:21:05 +00007686TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007687 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007688 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007689 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007690
Douglas Gregor1af74512010-02-26 00:38:10 +00007691 // Transform the delete operator, if known.
7692 FunctionDecl *OperatorDelete = 0;
7693 if (E->getOperatorDelete()) {
7694 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007695 getDerived().TransformDecl(E->getLocStart(),
7696 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007697 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007698 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007699 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007700
Douglas Gregorb98b1992009-08-11 05:31:07 +00007701 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007702 Operand.get() == E->getArgument() &&
7703 OperatorDelete == E->getOperatorDelete()) {
7704 // Mark any declarations we need as referenced.
7705 // FIXME: instantiation-specific.
7706 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007707 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007708
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007709 if (!E->getArgument()->isTypeDependent()) {
7710 QualType Destroyed = SemaRef.Context.getBaseElementType(
7711 E->getDestroyedType());
7712 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7713 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007714 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007715 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007716 }
7717 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007718
John McCall3fa5cae2010-10-26 07:05:15 +00007719 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007720 }
Mike Stump1eb44332009-09-09 15:08:12 +00007721
Douglas Gregorb98b1992009-08-11 05:31:07 +00007722 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7723 E->isGlobalDelete(),
7724 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007725 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007726}
Mike Stump1eb44332009-09-09 15:08:12 +00007727
Douglas Gregorb98b1992009-08-11 05:31:07 +00007728template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007729ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007730TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007731 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007732 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007733 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007734 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007735
John McCallb3d87482010-08-24 05:47:05 +00007736 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007737 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007738 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007739 E->getOperatorLoc(),
7740 E->isArrow()? tok::arrow : tok::period,
7741 ObjectTypePtr,
7742 MayBePseudoDestructor);
7743 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007744 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007745
John McCallb3d87482010-08-24 05:47:05 +00007746 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007747 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7748 if (QualifierLoc) {
7749 QualifierLoc
7750 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7751 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007752 return ExprError();
7753 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007754 CXXScopeSpec SS;
7755 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007756
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007757 PseudoDestructorTypeStorage Destroyed;
7758 if (E->getDestroyedTypeInfo()) {
7759 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007760 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007761 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007762 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007763 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007764 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007765 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007766 // We aren't likely to be able to resolve the identifier down to a type
7767 // now anyway, so just retain the identifier.
7768 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7769 E->getDestroyedTypeLoc());
7770 } else {
7771 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007772 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007773 *E->getDestroyedTypeIdentifier(),
7774 E->getDestroyedTypeLoc(),
7775 /*Scope=*/0,
7776 SS, ObjectTypePtr,
7777 false);
7778 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007779 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007780
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007781 Destroyed
7782 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7783 E->getDestroyedTypeLoc());
7784 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007785
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007786 TypeSourceInfo *ScopeTypeInfo = 0;
7787 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007788 CXXScopeSpec EmptySS;
7789 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7790 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007791 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007792 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007793 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007794
John McCall9ae2f072010-08-23 23:25:46 +00007795 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007796 E->getOperatorLoc(),
7797 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007798 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007799 ScopeTypeInfo,
7800 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007801 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007802 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007803}
Mike Stump1eb44332009-09-09 15:08:12 +00007804
Douglas Gregora71d8192009-09-04 17:36:40 +00007805template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007806ExprResult
John McCallba135432009-11-21 08:51:07 +00007807TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007808 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007809 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7810 Sema::LookupOrdinaryName);
7811
7812 // Transform all the decls.
7813 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7814 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007815 NamedDecl *InstD = static_cast<NamedDecl*>(
7816 getDerived().TransformDecl(Old->getNameLoc(),
7817 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007818 if (!InstD) {
7819 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7820 // This can happen because of dependent hiding.
7821 if (isa<UsingShadowDecl>(*I))
7822 continue;
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007823 else {
7824 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007825 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007826 }
John McCall9f54ad42009-12-10 09:41:52 +00007827 }
John McCallf7a1a742009-11-24 19:00:30 +00007828
7829 // Expand using declarations.
7830 if (isa<UsingDecl>(InstD)) {
7831 UsingDecl *UD = cast<UsingDecl>(InstD);
7832 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7833 E = UD->shadow_end(); I != E; ++I)
7834 R.addDecl(*I);
7835 continue;
7836 }
7837
7838 R.addDecl(InstD);
7839 }
7840
7841 // Resolve a kind, but don't do any further analysis. If it's
7842 // ambiguous, the callee needs to deal with it.
7843 R.resolveKind();
7844
7845 // Rebuild the nested-name qualifier, if present.
7846 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007847 if (Old->getQualifierLoc()) {
7848 NestedNameSpecifierLoc QualifierLoc
7849 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7850 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007851 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007852
Douglas Gregor4c9be892011-02-28 20:01:57 +00007853 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007854 }
7855
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007856 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007857 CXXRecordDecl *NamingClass
7858 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7859 Old->getNameLoc(),
7860 Old->getNamingClass()));
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007861 if (!NamingClass) {
7862 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007863 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007864 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007865
Douglas Gregor66c45152010-04-27 16:10:10 +00007866 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007867 }
7868
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007869 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7870
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007871 // If we have neither explicit template arguments, nor the template keyword,
7872 // it's a normal declaration name.
7873 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007874 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7875
7876 // If we have template arguments, rebuild them, then rebuild the
7877 // templateid expression.
7878 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007879 if (Old->hasExplicitTemplateArgs() &&
7880 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007881 Old->getNumTemplateArgs(),
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007882 TransArgs)) {
7883 R.clear();
Douglas Gregorfcc12532010-12-20 17:31:10 +00007884 return ExprError();
Serge Pavlov1e75a1a2013-09-04 04:50:29 +00007885 }
John McCallf7a1a742009-11-24 19:00:30 +00007886
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007887 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007888 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007889}
Mike Stump1eb44332009-09-09 15:08:12 +00007890
Douglas Gregorb98b1992009-08-11 05:31:07 +00007891template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007892ExprResult
John McCall454feb92009-12-08 09:21:05 +00007893TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007894 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7895 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007896 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007897
Douglas Gregorb98b1992009-08-11 05:31:07 +00007898 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007899 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007900 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007901
Mike Stump1eb44332009-09-09 15:08:12 +00007902 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007903 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007904 T,
7905 E->getLocEnd());
7906}
Mike Stump1eb44332009-09-09 15:08:12 +00007907
Douglas Gregorb98b1992009-08-11 05:31:07 +00007908template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007909ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007910TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7911 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7912 if (!LhsT)
7913 return ExprError();
7914
7915 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7916 if (!RhsT)
7917 return ExprError();
7918
7919 if (!getDerived().AlwaysRebuild() &&
7920 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7921 return SemaRef.Owned(E);
7922
7923 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7924 E->getLocStart(),
7925 LhsT, RhsT,
7926 E->getLocEnd());
7927}
7928
7929template<typename Derived>
7930ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007931TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7932 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007933 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007934 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7935 TypeSourceInfo *From = E->getArg(I);
7936 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007937 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007938 TypeLocBuilder TLB;
7939 TLB.reserve(FromTL.getFullDataSize());
7940 QualType To = getDerived().TransformType(TLB, FromTL);
7941 if (To.isNull())
7942 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007943
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007944 if (To == From->getType())
7945 Args.push_back(From);
7946 else {
7947 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7948 ArgChanged = true;
7949 }
7950 continue;
7951 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007952
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007953 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007954
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007955 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007956 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007957 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7958 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7959 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007960
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007961 // Determine whether the set of unexpanded parameter packs can and should
7962 // be expanded.
7963 bool Expand = true;
7964 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007965 Optional<unsigned> OrigNumExpansions =
7966 ExpansionTL.getTypePtr()->getNumExpansions();
7967 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007968 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7969 PatternTL.getSourceRange(),
7970 Unexpanded,
7971 Expand, RetainExpansion,
7972 NumExpansions))
7973 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007974
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007975 if (!Expand) {
7976 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007977 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007978 // expansion.
7979 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007980
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007981 TypeLocBuilder TLB;
7982 TLB.reserve(From->getTypeLoc().getFullDataSize());
7983
7984 QualType To = getDerived().TransformType(TLB, PatternTL);
7985 if (To.isNull())
7986 return ExprError();
7987
Chad Rosier4a9d7952012-08-08 18:46:20 +00007988 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007989 PatternTL.getSourceRange(),
7990 ExpansionTL.getEllipsisLoc(),
7991 NumExpansions);
7992 if (To.isNull())
7993 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007994
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007995 PackExpansionTypeLoc ToExpansionTL
7996 = TLB.push<PackExpansionTypeLoc>(To);
7997 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7998 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7999 continue;
8000 }
8001
8002 // Expand the pack expansion by substituting for each argument in the
8003 // pack(s).
8004 for (unsigned I = 0; I != *NumExpansions; ++I) {
8005 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
8006 TypeLocBuilder TLB;
8007 TLB.reserve(PatternTL.getFullDataSize());
8008 QualType To = getDerived().TransformType(TLB, PatternTL);
8009 if (To.isNull())
8010 return ExprError();
8011
Eli Friedman20cfeca2013-07-19 21:49:32 +00008012 if (To->containsUnexpandedParameterPack()) {
8013 To = getDerived().RebuildPackExpansionType(To,
8014 PatternTL.getSourceRange(),
8015 ExpansionTL.getEllipsisLoc(),
8016 NumExpansions);
8017 if (To.isNull())
8018 return ExprError();
8019
8020 PackExpansionTypeLoc ToExpansionTL
8021 = TLB.push<PackExpansionTypeLoc>(To);
8022 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8023 }
8024
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008025 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8026 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008027
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008028 if (!RetainExpansion)
8029 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008030
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008031 // If we're supposed to retain a pack expansion, do so by temporarily
8032 // forgetting the partially-substituted parameter pack.
8033 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
8034
8035 TypeLocBuilder TLB;
8036 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008037
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008038 QualType To = getDerived().TransformType(TLB, PatternTL);
8039 if (To.isNull())
8040 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008041
8042 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008043 PatternTL.getSourceRange(),
8044 ExpansionTL.getEllipsisLoc(),
8045 NumExpansions);
8046 if (To.isNull())
8047 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008048
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008049 PackExpansionTypeLoc ToExpansionTL
8050 = TLB.push<PackExpansionTypeLoc>(To);
8051 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
8052 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
8053 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008054
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00008055 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8056 return SemaRef.Owned(E);
8057
8058 return getDerived().RebuildTypeTrait(E->getTrait(),
8059 E->getLocStart(),
8060 Args,
8061 E->getLocEnd());
8062}
8063
8064template<typename Derived>
8065ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00008066TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
8067 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
8068 if (!T)
8069 return ExprError();
8070
8071 if (!getDerived().AlwaysRebuild() &&
8072 T == E->getQueriedTypeSourceInfo())
8073 return SemaRef.Owned(E);
8074
8075 ExprResult SubExpr;
8076 {
8077 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8078 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
8079 if (SubExpr.isInvalid())
8080 return ExprError();
8081
8082 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
8083 return SemaRef.Owned(E);
8084 }
8085
8086 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
8087 E->getLocStart(),
8088 T,
8089 SubExpr.get(),
8090 E->getLocEnd());
8091}
8092
8093template<typename Derived>
8094ExprResult
John Wiegley55262202011-04-25 06:54:41 +00008095TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
8096 ExprResult SubExpr;
8097 {
8098 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8099 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
8100 if (SubExpr.isInvalid())
8101 return ExprError();
8102
8103 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
8104 return SemaRef.Owned(E);
8105 }
8106
8107 return getDerived().RebuildExpressionTrait(
8108 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
8109}
8110
8111template<typename Derived>
8112ExprResult
John McCall865d4472009-11-19 22:55:06 +00008113TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008114 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00008115 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
8116}
8117
8118template<typename Derived>
8119ExprResult
8120TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
8121 DependentScopeDeclRefExpr *E,
8122 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008123 NestedNameSpecifierLoc QualifierLoc
8124 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8125 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008126 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008127 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00008128
John McCall43fed0d2010-11-12 08:19:04 +00008129 // TODO: If this is a conversion-function-id, verify that the
8130 // destination type name (if present) resolves the same way after
8131 // instantiation as it did in the local scope.
8132
Abramo Bagnara25777432010-08-11 22:01:17 +00008133 DeclarationNameInfo NameInfo
8134 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
8135 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008136 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008137
John McCallf7a1a742009-11-24 19:00:30 +00008138 if (!E->hasExplicitTemplateArgs()) {
8139 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008140 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008141 // Note: it is sufficient to compare the Name component of NameInfo:
8142 // if name has not changed, DNLoc has not changed either.
8143 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00008144 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008145
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008146 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008147 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008148 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008149 /*TemplateArgs*/ 0,
8150 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00008151 }
John McCalld5532b62009-11-23 01:53:49 +00008152
8153 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008154 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8155 E->getNumTemplateArgs(),
8156 TransArgs))
8157 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008158
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00008159 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008160 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00008161 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00008162 &TransArgs,
8163 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008164}
8165
8166template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008167ExprResult
John McCall454feb92009-12-08 09:21:05 +00008168TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00008169 // CXXConstructExprs other than for list-initialization and
8170 // CXXTemporaryObjectExpr are always implicit, so when we have
8171 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00008172 if ((E->getNumArgs() == 1 ||
8173 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00008174 (!getDerived().DropCallArgument(E->getArg(0))) &&
8175 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00008176 return getDerived().TransformExpr(E->getArg(0));
8177
Douglas Gregorb98b1992009-08-11 05:31:07 +00008178 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
8179
8180 QualType T = getDerived().TransformType(E->getType());
8181 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00008182 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00008183
8184 CXXConstructorDecl *Constructor
8185 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008186 getDerived().TransformDecl(E->getLocStart(),
8187 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008188 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008189 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008190
Douglas Gregorb98b1992009-08-11 05:31:07 +00008191 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008192 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008193 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008194 &ArgumentChanged))
8195 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008196
Douglas Gregorb98b1992009-08-11 05:31:07 +00008197 if (!getDerived().AlwaysRebuild() &&
8198 T == E->getType() &&
8199 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00008200 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00008201 // Mark the constructor as referenced.
8202 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008203 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008204 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00008205 }
Mike Stump1eb44332009-09-09 15:08:12 +00008206
Douglas Gregor4411d2e2009-12-14 16:27:04 +00008207 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
8208 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008209 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00008210 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00008211 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00008212 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00008213 E->getConstructionKind(),
Enea Zaffanella1245a542013-09-07 05:49:53 +00008214 E->getParenOrBraceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008215}
Mike Stump1eb44332009-09-09 15:08:12 +00008216
Douglas Gregorb98b1992009-08-11 05:31:07 +00008217/// \brief Transform a C++ temporary-binding expression.
8218///
Douglas Gregor51326552009-12-24 18:51:59 +00008219/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
8220/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008221template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008222ExprResult
John McCall454feb92009-12-08 09:21:05 +00008223TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008224 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008225}
Mike Stump1eb44332009-09-09 15:08:12 +00008226
John McCall4765fa02010-12-06 08:20:24 +00008227/// \brief Transform a C++ expression that contains cleanups that should
8228/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008229///
John McCall4765fa02010-12-06 08:20:24 +00008230/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00008231/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008232template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008233ExprResult
John McCall4765fa02010-12-06 08:20:24 +00008234TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008235 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008236}
Mike Stump1eb44332009-09-09 15:08:12 +00008237
Douglas Gregorb98b1992009-08-11 05:31:07 +00008238template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008239ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008240TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00008241 CXXTemporaryObjectExpr *E) {
8242 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8243 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008244 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008245
Douglas Gregorb98b1992009-08-11 05:31:07 +00008246 CXXConstructorDecl *Constructor
8247 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008248 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008249 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008250 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008251 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008252
Douglas Gregorb98b1992009-08-11 05:31:07 +00008253 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008254 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00008255 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008256 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008257 &ArgumentChanged))
8258 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008259
Douglas Gregorb98b1992009-08-11 05:31:07 +00008260 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008261 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008262 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00008263 !ArgumentChanged) {
8264 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008265 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008266 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00008267 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008268
Richard Smithc83c2302012-12-19 01:39:02 +00008269 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00008270 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8271 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008272 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008273 E->getLocEnd());
8274}
Mike Stump1eb44332009-09-09 15:08:12 +00008275
Douglas Gregorb98b1992009-08-11 05:31:07 +00008276template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008277ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00008278TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Faisal Valifad9e132013-09-26 19:54:12 +00008279
Rafael Espindolaf003acd2013-10-04 14:28:51 +00008280 // FIXME: Implement nested generic lambda transformations.
8281 if (E->isGenericLambda()) {
8282 getSema().Diag(E->getIntroducerRange().getBegin(),
8283 diag::err_glambda_not_fully_implemented)
8284 << " template transformation of generic lambdas not implemented yet";
8285 return ExprError();
Faisal Valifad9e132013-09-26 19:54:12 +00008286 }
Rafael Espindolaf003acd2013-10-04 14:28:51 +00008287 // Transform the type of the lambda parameters and start the definition of
8288 // the lambda itself.
8289 TypeSourceInfo *MethodTy
8290 = TransformType(E->getCallOperator()->getTypeSourceInfo());
8291 if (!MethodTy)
Douglas Gregordfca6f52012-02-13 22:00:16 +00008292 return ExprError();
8293
Eli Friedman8da8a662012-09-19 01:18:11 +00008294 // Create the local class that will describe the lambda.
8295 CXXRecordDecl *Class
8296 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Rafael Espindolaf003acd2013-10-04 14:28:51 +00008297 MethodTy,
Eli Friedman8da8a662012-09-19 01:18:11 +00008298 /*KnownDependent=*/false);
8299 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8300
Douglas Gregorc6889e72012-02-14 22:28:59 +00008301 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008302 SmallVector<QualType, 4> ParamTypes;
8303 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00008304 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
8305 E->getCallOperator()->param_begin(),
8306 E->getCallOperator()->param_size(),
8307 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00008308 return ExprError();
Rafael Espindolaf003acd2013-10-04 14:28:51 +00008309 getSema().PushLambdaScope();
8310 LambdaScopeInfo *LSI = getSema().getCurLambda();
8311 // TODO: Fix for nested lambdas
8312 LSI->GLTemplateParameterList = 0;
Douglas Gregordfca6f52012-02-13 22:00:16 +00008313 // Build the call operator.
Rafael Espindolaf003acd2013-10-04 14:28:51 +00008314 CXXMethodDecl *CallOperator
Douglas Gregordfca6f52012-02-13 22:00:16 +00008315 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Rafael Espindolaf003acd2013-10-04 14:28:51 +00008316 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00008317 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008318 Params);
Rafael Espindolaf003acd2013-10-04 14:28:51 +00008319 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
8320
8321 return getDerived().TransformLambdaScope(E, CallOperator);
Richard Smith612409e2012-07-25 03:56:55 +00008322}
8323
8324template<typename Derived>
8325ExprResult
8326TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8327 CXXMethodDecl *CallOperator) {
Richard Smith0d8e9642013-05-16 06:20:58 +00008328 bool Invalid = false;
8329
8330 // Transform any init-capture expressions before entering the scope of the
8331 // lambda.
Robert Wilhelme7205c02013-08-10 12:33:24 +00008332 SmallVector<ExprResult, 8> InitCaptureExprs;
Richard Smith0d8e9642013-05-16 06:20:58 +00008333 InitCaptureExprs.resize(E->explicit_capture_end() -
8334 E->explicit_capture_begin());
8335 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8336 CEnd = E->capture_end();
8337 C != CEnd; ++C) {
8338 if (!C->isInitCapture())
8339 continue;
8340 InitCaptureExprs[C - E->capture_begin()] =
Richard Smith04fa7a32013-09-28 04:02:39 +00008341 getDerived().TransformInitializer(
8342 C->getCapturedVar()->getInit(),
8343 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith0d8e9642013-05-16 06:20:58 +00008344 }
8345
Douglas Gregord5387e82012-02-14 00:00:48 +00008346 // Introduce the context of the call operator.
8347 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8348
Faisal Valifad9e132013-09-26 19:54:12 +00008349 LambdaScopeInfo *const LSI = getSema().getCurLambda();
Douglas Gregordfca6f52012-02-13 22:00:16 +00008350 // Enter the scope of the lambda.
Faisal Valifad9e132013-09-26 19:54:12 +00008351 getSema().buildLambdaScope(LSI, CallOperator, E->getIntroducerRange(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008352 E->getCaptureDefault(),
James Dennettf68af642013-08-09 23:08:25 +00008353 E->getCaptureDefaultLoc(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008354 E->hasExplicitParameters(),
8355 E->hasExplicitResultType(),
8356 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008357
Douglas Gregordfca6f52012-02-13 22:00:16 +00008358 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00008359 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008360 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008361 CEnd = E->capture_end();
8362 C != CEnd; ++C) {
8363 // When we hit the first implicit capture, tell Sema that we've finished
8364 // the list of explicit captures.
8365 if (!FinishedExplicitCaptures && C->isImplicit()) {
8366 getSema().finishLambdaExplicitCaptures(LSI);
8367 FinishedExplicitCaptures = true;
8368 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008369
Douglas Gregordfca6f52012-02-13 22:00:16 +00008370 // Capturing 'this' is trivial.
8371 if (C->capturesThis()) {
8372 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8373 continue;
8374 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008375
Richard Smith0d8e9642013-05-16 06:20:58 +00008376 // Rebuild init-captures, including the implied field declaration.
8377 if (C->isInitCapture()) {
8378 ExprResult Init = InitCaptureExprs[C - E->capture_begin()];
8379 if (Init.isInvalid()) {
8380 Invalid = true;
8381 continue;
8382 }
Richard Smith04fa7a32013-09-28 04:02:39 +00008383 VarDecl *OldVD = C->getCapturedVar();
8384 VarDecl *NewVD = getSema().checkInitCapture(
8385 C->getLocation(), OldVD->getType()->isReferenceType(),
8386 OldVD->getIdentifier(), Init.take());
8387 if (!NewVD)
Richard Smith0d8e9642013-05-16 06:20:58 +00008388 Invalid = true;
8389 else
Richard Smith04fa7a32013-09-28 04:02:39 +00008390 getDerived().transformedLocalDecl(OldVD, NewVD);
8391 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smith0d8e9642013-05-16 06:20:58 +00008392 continue;
8393 }
8394
8395 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8396
Douglas Gregora7365242012-02-14 19:27:52 +00008397 // Determine the capture kind for Sema.
8398 Sema::TryCaptureKind Kind
8399 = C->isImplicit()? Sema::TryCapture_Implicit
8400 : C->getCaptureKind() == LCK_ByCopy
8401 ? Sema::TryCapture_ExplicitByVal
8402 : Sema::TryCapture_ExplicitByRef;
8403 SourceLocation EllipsisLoc;
8404 if (C->isPackExpansion()) {
8405 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8406 bool ShouldExpand = false;
8407 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008408 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008409 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8410 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008411 Unexpanded,
8412 ShouldExpand, RetainExpansion,
Richard Smith0d8e9642013-05-16 06:20:58 +00008413 NumExpansions)) {
8414 Invalid = true;
8415 continue;
8416 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008417
Douglas Gregora7365242012-02-14 19:27:52 +00008418 if (ShouldExpand) {
8419 // The transform has determined that we should perform an expansion;
8420 // transform and capture each of the arguments.
8421 // expansion of the pattern. Do so.
8422 VarDecl *Pack = C->getCapturedVar();
8423 for (unsigned I = 0; I != *NumExpansions; ++I) {
8424 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8425 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008426 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008427 Pack));
8428 if (!CapturedVar) {
8429 Invalid = true;
8430 continue;
8431 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008432
Douglas Gregora7365242012-02-14 19:27:52 +00008433 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008434 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8435 }
Douglas Gregora7365242012-02-14 19:27:52 +00008436 continue;
8437 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008438
Douglas Gregora7365242012-02-14 19:27:52 +00008439 EllipsisLoc = C->getEllipsisLoc();
8440 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008441
Douglas Gregordfca6f52012-02-13 22:00:16 +00008442 // Transform the captured variable.
8443 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008444 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008445 C->getCapturedVar()));
8446 if (!CapturedVar) {
8447 Invalid = true;
8448 continue;
8449 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008450
Douglas Gregordfca6f52012-02-13 22:00:16 +00008451 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008452 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008453 }
8454 if (!FinishedExplicitCaptures)
8455 getSema().finishLambdaExplicitCaptures(LSI);
8456
Douglas Gregordfca6f52012-02-13 22:00:16 +00008457
8458 // Enter a new evaluation context to insulate the lambda from any
8459 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008460 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008461
8462 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008463 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008464 /*IsInstantiation=*/true);
8465 return ExprError();
8466 }
8467
8468 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008469 StmtResult Body = getDerived().TransformStmt(E->getBody());
8470 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008471 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008472 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008473 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008474 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008475
Chad Rosier4a9d7952012-08-08 18:46:20 +00008476 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008477 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008478}
8479
8480template<typename Derived>
8481ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008482TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008483 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008484 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8485 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008486 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008487
Douglas Gregorb98b1992009-08-11 05:31:07 +00008488 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008489 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008490 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008491 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008492 &ArgumentChanged))
8493 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008494
Douglas Gregorb98b1992009-08-11 05:31:07 +00008495 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008496 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008497 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008498 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008499
Douglas Gregorb98b1992009-08-11 05:31:07 +00008500 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008501 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008502 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008503 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008504 E->getRParenLoc());
8505}
Mike Stump1eb44332009-09-09 15:08:12 +00008506
Douglas Gregorb98b1992009-08-11 05:31:07 +00008507template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008508ExprResult
John McCall865d4472009-11-19 22:55:06 +00008509TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008510 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008511 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008512 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008513 Expr *OldBase;
8514 QualType BaseType;
8515 QualType ObjectType;
8516 if (!E->isImplicitAccess()) {
8517 OldBase = E->getBase();
8518 Base = getDerived().TransformExpr(OldBase);
8519 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008520 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008521
John McCallaa81e162009-12-01 22:10:20 +00008522 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008523 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008524 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008525 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008526 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008527 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008528 ObjectTy,
8529 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008530 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008531 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008532
John McCallb3d87482010-08-24 05:47:05 +00008533 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008534 BaseType = ((Expr*) Base.get())->getType();
8535 } else {
8536 OldBase = 0;
8537 BaseType = getDerived().TransformType(E->getBaseType());
8538 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8539 }
Mike Stump1eb44332009-09-09 15:08:12 +00008540
Douglas Gregor6cd21982009-10-20 05:58:46 +00008541 // Transform the first part of the nested-name-specifier that qualifies
8542 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008543 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008544 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008545 E->getFirstQualifierFoundInScope(),
8546 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008547
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008548 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008549 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008550 QualifierLoc
8551 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8552 ObjectType,
8553 FirstQualifierInScope);
8554 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008555 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008556 }
Mike Stump1eb44332009-09-09 15:08:12 +00008557
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008558 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8559
John McCall43fed0d2010-11-12 08:19:04 +00008560 // TODO: If this is a conversion-function-id, verify that the
8561 // destination type name (if present) resolves the same way after
8562 // instantiation as it did in the local scope.
8563
Abramo Bagnara25777432010-08-11 22:01:17 +00008564 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008565 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008566 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008567 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008568
John McCallaa81e162009-12-01 22:10:20 +00008569 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008570 // This is a reference to a member without an explicitly-specified
8571 // template argument list. Optimize for this common case.
8572 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008573 Base.get() == OldBase &&
8574 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008575 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008576 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008577 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008578 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008579
John McCall9ae2f072010-08-23 23:25:46 +00008580 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008581 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008582 E->isArrow(),
8583 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008584 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008585 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008586 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008587 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008588 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008589 }
8590
John McCalld5532b62009-11-23 01:53:49 +00008591 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008592 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8593 E->getNumTemplateArgs(),
8594 TransArgs))
8595 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008596
John McCall9ae2f072010-08-23 23:25:46 +00008597 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008598 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008599 E->isArrow(),
8600 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008601 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008602 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008603 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008604 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008605 &TransArgs);
8606}
8607
8608template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008609ExprResult
John McCall454feb92009-12-08 09:21:05 +00008610TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008611 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008612 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008613 QualType BaseType;
8614 if (!Old->isImplicitAccess()) {
8615 Base = getDerived().TransformExpr(Old->getBase());
8616 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008617 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008618 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8619 Old->isArrow());
8620 if (Base.isInvalid())
8621 return ExprError();
8622 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008623 } else {
8624 BaseType = getDerived().TransformType(Old->getBaseType());
8625 }
John McCall129e2df2009-11-30 22:42:35 +00008626
Douglas Gregor4c9be892011-02-28 20:01:57 +00008627 NestedNameSpecifierLoc QualifierLoc;
8628 if (Old->getQualifierLoc()) {
8629 QualifierLoc
8630 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8631 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008632 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008633 }
8634
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008635 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8636
Abramo Bagnara25777432010-08-11 22:01:17 +00008637 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008638 Sema::LookupOrdinaryName);
8639
8640 // Transform all the decls.
8641 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8642 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008643 NamedDecl *InstD = static_cast<NamedDecl*>(
8644 getDerived().TransformDecl(Old->getMemberLoc(),
8645 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008646 if (!InstD) {
8647 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8648 // This can happen because of dependent hiding.
8649 if (isa<UsingShadowDecl>(*I))
8650 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008651 else {
8652 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008653 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008654 }
John McCall9f54ad42009-12-10 09:41:52 +00008655 }
John McCall129e2df2009-11-30 22:42:35 +00008656
8657 // Expand using declarations.
8658 if (isa<UsingDecl>(InstD)) {
8659 UsingDecl *UD = cast<UsingDecl>(InstD);
8660 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8661 E = UD->shadow_end(); I != E; ++I)
8662 R.addDecl(*I);
8663 continue;
8664 }
8665
8666 R.addDecl(InstD);
8667 }
8668
8669 R.resolveKind();
8670
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008671 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008672 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008673 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008674 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008675 Old->getMemberLoc(),
8676 Old->getNamingClass()));
8677 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008678 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008679
Douglas Gregor66c45152010-04-27 16:10:10 +00008680 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008681 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008682
John McCall129e2df2009-11-30 22:42:35 +00008683 TemplateArgumentListInfo TransArgs;
8684 if (Old->hasExplicitTemplateArgs()) {
8685 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8686 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008687 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8688 Old->getNumTemplateArgs(),
8689 TransArgs))
8690 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008691 }
John McCallc2233c52010-01-15 08:34:02 +00008692
8693 // FIXME: to do this check properly, we will need to preserve the
8694 // first-qualifier-in-scope here, just in case we had a dependent
8695 // base (and therefore couldn't do the check) and a
8696 // nested-name-qualifier (and therefore could do the lookup).
8697 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008698
John McCall9ae2f072010-08-23 23:25:46 +00008699 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008700 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008701 Old->getOperatorLoc(),
8702 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008703 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008704 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008705 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008706 R,
8707 (Old->hasExplicitTemplateArgs()
8708 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008709}
8710
8711template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008712ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008713TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008714 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008715 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8716 if (SubExpr.isInvalid())
8717 return ExprError();
8718
8719 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008720 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008721
8722 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8723}
8724
8725template<typename Derived>
8726ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008727TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008728 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8729 if (Pattern.isInvalid())
8730 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008731
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008732 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8733 return SemaRef.Owned(E);
8734
Douglas Gregor67fd1252011-01-14 21:20:45 +00008735 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8736 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008737}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008738
8739template<typename Derived>
8740ExprResult
8741TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8742 // If E is not value-dependent, then nothing will change when we transform it.
8743 // Note: This is an instantiation-centric view.
8744 if (!E->isValueDependent())
8745 return SemaRef.Owned(E);
8746
8747 // Note: None of the implementations of TryExpandParameterPacks can ever
8748 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008749 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008750 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8751 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008752 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008753 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008754 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008755 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008756 ShouldExpand, RetainExpansion,
8757 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008758 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008759
Douglas Gregor089e8932011-10-10 18:59:29 +00008760 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008761 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008762
Douglas Gregor089e8932011-10-10 18:59:29 +00008763 NamedDecl *Pack = E->getPack();
8764 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008765 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008766 Pack));
8767 if (!Pack)
8768 return ExprError();
8769 }
8770
Chad Rosier4a9d7952012-08-08 18:46:20 +00008771
Douglas Gregoree8aff02011-01-04 17:33:58 +00008772 // We now know the length of the parameter pack, so build a new expression
8773 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008774 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8775 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008776 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008777}
8778
Douglas Gregorbe230c32011-01-03 17:17:50 +00008779template<typename Derived>
8780ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008781TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8782 SubstNonTypeTemplateParmPackExpr *E) {
8783 // Default behavior is to do nothing with this transformation.
8784 return SemaRef.Owned(E);
8785}
8786
8787template<typename Derived>
8788ExprResult
John McCall91a57552011-07-15 05:09:51 +00008789TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8790 SubstNonTypeTemplateParmExpr *E) {
8791 // Default behavior is to do nothing with this transformation.
8792 return SemaRef.Owned(E);
8793}
8794
8795template<typename Derived>
8796ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008797TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8798 // Default behavior is to do nothing with this transformation.
8799 return SemaRef.Owned(E);
8800}
8801
8802template<typename Derived>
8803ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008804TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8805 MaterializeTemporaryExpr *E) {
8806 return getDerived().TransformExpr(E->GetTemporaryExpr());
8807}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008808
Douglas Gregor03e80032011-06-21 17:03:29 +00008809template<typename Derived>
8810ExprResult
Richard Smith7c3e6152013-06-12 22:31:48 +00008811TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8812 CXXStdInitializerListExpr *E) {
8813 return getDerived().TransformExpr(E->getSubExpr());
8814}
8815
8816template<typename Derived>
8817ExprResult
John McCall454feb92009-12-08 09:21:05 +00008818TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008819 return SemaRef.MaybeBindToTemporary(E);
8820}
8821
8822template<typename Derived>
8823ExprResult
8824TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008825 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008826}
8827
8828template<typename Derived>
8829ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008830TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8831 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8832 if (SubExpr.isInvalid())
8833 return ExprError();
8834
8835 if (!getDerived().AlwaysRebuild() &&
8836 SubExpr.get() == E->getSubExpr())
8837 return SemaRef.Owned(E);
8838
8839 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008840}
8841
8842template<typename Derived>
8843ExprResult
8844TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8845 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008846 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008847 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008848 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008849 /*IsCall=*/false, Elements, &ArgChanged))
8850 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008851
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008852 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8853 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008854
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008855 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8856 Elements.data(),
8857 Elements.size());
8858}
8859
8860template<typename Derived>
8861ExprResult
8862TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008863 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008864 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008865 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008866 bool ArgChanged = false;
8867 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8868 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008869
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008870 if (OrigElement.isPackExpansion()) {
8871 // This key/value element is a pack expansion.
8872 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8873 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8874 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8875 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8876
8877 // Determine whether the set of unexpanded parameter packs can
8878 // and should be expanded.
8879 bool Expand = true;
8880 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008881 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8882 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008883 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8884 OrigElement.Value->getLocEnd());
8885 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8886 PatternRange,
8887 Unexpanded,
8888 Expand, RetainExpansion,
8889 NumExpansions))
8890 return ExprError();
8891
8892 if (!Expand) {
8893 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008894 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008895 // expansion.
8896 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8897 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8898 if (Key.isInvalid())
8899 return ExprError();
8900
8901 if (Key.get() != OrigElement.Key)
8902 ArgChanged = true;
8903
8904 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8905 if (Value.isInvalid())
8906 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008907
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008908 if (Value.get() != OrigElement.Value)
8909 ArgChanged = true;
8910
Chad Rosier4a9d7952012-08-08 18:46:20 +00008911 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008912 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8913 };
8914 Elements.push_back(Expansion);
8915 continue;
8916 }
8917
8918 // Record right away that the argument was changed. This needs
8919 // to happen even if the array expands to nothing.
8920 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008921
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008922 // The transform has determined that we should perform an elementwise
8923 // expansion of the pattern. Do so.
8924 for (unsigned I = 0; I != *NumExpansions; ++I) {
8925 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8926 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8927 if (Key.isInvalid())
8928 return ExprError();
8929
8930 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8931 if (Value.isInvalid())
8932 return ExprError();
8933
Chad Rosier4a9d7952012-08-08 18:46:20 +00008934 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008935 Key.get(), Value.get(), SourceLocation(), NumExpansions
8936 };
8937
8938 // If any unexpanded parameter packs remain, we still have a
8939 // pack expansion.
8940 if (Key.get()->containsUnexpandedParameterPack() ||
8941 Value.get()->containsUnexpandedParameterPack())
8942 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008943
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008944 Elements.push_back(Element);
8945 }
8946
8947 // We've finished with this pack expansion.
8948 continue;
8949 }
8950
8951 // Transform and check key.
8952 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8953 if (Key.isInvalid())
8954 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008955
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008956 if (Key.get() != OrigElement.Key)
8957 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008958
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008959 // Transform and check value.
8960 ExprResult Value
8961 = getDerived().TransformExpr(OrigElement.Value);
8962 if (Value.isInvalid())
8963 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008964
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008965 if (Value.get() != OrigElement.Value)
8966 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008967
8968 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00008969 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008970 };
8971 Elements.push_back(Element);
8972 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008973
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008974 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8975 return SemaRef.MaybeBindToTemporary(E);
8976
8977 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8978 Elements.data(),
8979 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008980}
8981
Mike Stump1eb44332009-09-09 15:08:12 +00008982template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008983ExprResult
John McCall454feb92009-12-08 09:21:05 +00008984TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008985 TypeSourceInfo *EncodedTypeInfo
8986 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8987 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008988 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008989
Douglas Gregorb98b1992009-08-11 05:31:07 +00008990 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008991 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008992 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008993
8994 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008995 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008996 E->getRParenLoc());
8997}
Mike Stump1eb44332009-09-09 15:08:12 +00008998
Douglas Gregorb98b1992009-08-11 05:31:07 +00008999template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00009000ExprResult TreeTransform<Derived>::
9001TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCall93b64572013-04-11 02:14:26 +00009002 // This is a kind of implicit conversion, and it needs to get dropped
9003 // and recomputed for the same general reasons that ImplicitCastExprs
9004 // do, as well a more specific one: this expression is only valid when
9005 // it appears *immediately* as an argument expression.
9006 return getDerived().TransformExpr(E->getSubExpr());
John McCallf85e1932011-06-15 23:02:42 +00009007}
9008
9009template<typename Derived>
9010ExprResult TreeTransform<Derived>::
9011TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00009012 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00009013 = getDerived().TransformType(E->getTypeInfoAsWritten());
9014 if (!TSInfo)
9015 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009016
John McCallf85e1932011-06-15 23:02:42 +00009017 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009018 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00009019 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009020
John McCallf85e1932011-06-15 23:02:42 +00009021 if (!getDerived().AlwaysRebuild() &&
9022 TSInfo == E->getTypeInfoAsWritten() &&
9023 Result.get() == E->getSubExpr())
9024 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009025
John McCallf85e1932011-06-15 23:02:42 +00009026 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00009027 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00009028 Result.get());
9029}
9030
9031template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009032ExprResult
John McCall454feb92009-12-08 09:21:05 +00009033TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00009034 // Transform arguments.
9035 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009036 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00009037 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009038 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00009039 &ArgChanged))
9040 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009041
Douglas Gregor92e986e2010-04-22 16:44:27 +00009042 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
9043 // Class message: transform the receiver type.
9044 TypeSourceInfo *ReceiverTypeInfo
9045 = getDerived().TransformType(E->getClassReceiverTypeInfo());
9046 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00009047 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009048
Douglas Gregor92e986e2010-04-22 16:44:27 +00009049 // If nothing changed, just retain the existing message send.
9050 if (!getDerived().AlwaysRebuild() &&
9051 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00009052 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00009053
9054 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009055 SmallVector<SourceLocation, 16> SelLocs;
9056 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00009057 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
9058 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009059 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009060 E->getMethodDecl(),
9061 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009062 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009063 E->getRightLoc());
9064 }
9065
9066 // Instance message: transform the receiver
9067 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
9068 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00009069 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00009070 = getDerived().TransformExpr(E->getInstanceReceiver());
9071 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009072 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00009073
9074 // If nothing changed, just retain the existing message send.
9075 if (!getDerived().AlwaysRebuild() &&
9076 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00009077 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009078
Douglas Gregor92e986e2010-04-22 16:44:27 +00009079 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009080 SmallVector<SourceLocation, 16> SelLocs;
9081 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00009082 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00009083 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00009084 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009085 E->getMethodDecl(),
9086 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009087 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00009088 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009089}
9090
Mike Stump1eb44332009-09-09 15:08:12 +00009091template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009092ExprResult
John McCall454feb92009-12-08 09:21:05 +00009093TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00009094 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009095}
9096
Mike Stump1eb44332009-09-09 15:08:12 +00009097template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009098ExprResult
John McCall454feb92009-12-08 09:21:05 +00009099TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00009100 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009101}
9102
Mike Stump1eb44332009-09-09 15:08:12 +00009103template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009104ExprResult
John McCall454feb92009-12-08 09:21:05 +00009105TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009106 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009107 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009108 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009109 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009110
9111 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009112
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009113 // If nothing changed, just retain the existing expression.
9114 if (!getDerived().AlwaysRebuild() &&
9115 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009116 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009117
John McCall9ae2f072010-08-23 23:25:46 +00009118 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009119 E->getLocation(),
9120 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009121}
9122
Mike Stump1eb44332009-09-09 15:08:12 +00009123template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009124ExprResult
John McCall454feb92009-12-08 09:21:05 +00009125TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00009126 // 'super' and types never change. Property never changes. Just
9127 // retain the existing expression.
9128 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00009129 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009130
Douglas Gregore3303542010-04-26 20:47:02 +00009131 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009132 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00009133 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009134 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009135
Douglas Gregore3303542010-04-26 20:47:02 +00009136 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00009137
Douglas Gregore3303542010-04-26 20:47:02 +00009138 // If nothing changed, just retain the existing expression.
9139 if (!getDerived().AlwaysRebuild() &&
9140 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009141 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009142
John McCall12f78a62010-12-02 01:19:52 +00009143 if (E->isExplicitProperty())
9144 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
9145 E->getExplicitProperty(),
9146 E->getLocation());
9147
9148 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00009149 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00009150 E->getImplicitPropertyGetter(),
9151 E->getImplicitPropertySetter(),
9152 E->getLocation());
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
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009157TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
9158 // Transform the base expression.
9159 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9160 if (Base.isInvalid())
9161 return ExprError();
9162
9163 // Transform the key expression.
9164 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
9165 if (Key.isInvalid())
9166 return ExprError();
9167
9168 // If nothing changed, just retain the existing expression.
9169 if (!getDerived().AlwaysRebuild() &&
9170 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
9171 return SemaRef.Owned(E);
9172
Chad Rosier4a9d7952012-08-08 18:46:20 +00009173 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00009174 Base.get(), Key.get(),
9175 E->getAtIndexMethodDecl(),
9176 E->setAtIndexMethodDecl());
9177}
9178
9179template<typename Derived>
9180ExprResult
John McCall454feb92009-12-08 09:21:05 +00009181TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009182 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00009183 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009184 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009185 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009186
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009187 // If nothing changed, just retain the existing expression.
9188 if (!getDerived().AlwaysRebuild() &&
9189 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00009190 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00009191
John McCall9ae2f072010-08-23 23:25:46 +00009192 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00009193 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00009194 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00009195}
9196
Mike Stump1eb44332009-09-09 15:08:12 +00009197template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009198ExprResult
John McCall454feb92009-12-08 09:21:05 +00009199TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009200 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009201 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00009202 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009203 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00009204 SubExprs, &ArgumentChanged))
9205 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009206
Douglas Gregorb98b1992009-08-11 05:31:07 +00009207 if (!getDerived().AlwaysRebuild() &&
9208 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00009209 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00009210
Douglas Gregorb98b1992009-08-11 05:31:07 +00009211 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009212 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00009213 E->getRParenLoc());
9214}
9215
Mike Stump1eb44332009-09-09 15:08:12 +00009216template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009217ExprResult
Hal Finkel414a1bd2013-09-18 03:29:45 +00009218TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
9219 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
9220 if (SrcExpr.isInvalid())
9221 return ExprError();
9222
9223 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9224 if (!Type)
9225 return ExprError();
9226
9227 if (!getDerived().AlwaysRebuild() &&
9228 Type == E->getTypeSourceInfo() &&
9229 SrcExpr.get() == E->getSrcExpr())
9230 return SemaRef.Owned(E);
9231
9232 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
9233 SrcExpr.get(), Type,
9234 E->getRParenLoc());
9235}
9236
9237template<typename Derived>
9238ExprResult
John McCall454feb92009-12-08 09:21:05 +00009239TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00009240 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00009241
John McCallc6ac9c32011-02-04 18:33:18 +00009242 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
9243 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
9244
9245 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00009246 blockScope->TheDecl->setBlockMissingReturnType(
9247 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009248
Chris Lattner686775d2011-07-20 06:58:45 +00009249 SmallVector<ParmVarDecl*, 4> params;
9250 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00009251
Fariborz Jahaniana729da22010-07-09 18:44:02 +00009252 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00009253 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
9254 oldBlock->param_begin(),
9255 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009256 0, paramTypes, &params)) {
9257 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00009258 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009259 }
John McCallc6ac9c32011-02-04 18:33:18 +00009260
Jordan Rose09189892013-03-08 22:25:36 +00009261 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00009262 QualType exprResultType =
9263 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00009264
Jordan Rosebea522f2013-03-08 21:51:21 +00009265 QualType functionType =
9266 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009267 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00009268 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00009269
9270 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00009271 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00009272 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00009273
9274 if (!oldBlock->blockMissingReturnType()) {
9275 blockScope->HasImplicitReturnType = false;
9276 blockScope->ReturnType = exprResultType;
9277 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00009278
John McCall711c52b2011-01-05 12:14:39 +00009279 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00009280 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009281 if (body.isInvalid()) {
9282 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00009283 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009284 }
John McCall711c52b2011-01-05 12:14:39 +00009285
John McCallc6ac9c32011-02-04 18:33:18 +00009286#ifndef NDEBUG
9287 // In builds with assertions, make sure that we captured everything we
9288 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00009289 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9290 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9291 e = oldBlock->capture_end(); i != e; ++i) {
9292 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00009293
Douglas Gregorfc921372011-05-20 15:32:55 +00009294 // Ignore parameter packs.
9295 if (isa<ParmVarDecl>(oldCapture) &&
9296 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9297 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00009298
Douglas Gregorfc921372011-05-20 15:32:55 +00009299 VarDecl *newCapture =
9300 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9301 oldCapture));
9302 assert(blockScope->CaptureMap.count(newCapture));
9303 }
Douglas Gregorec79d872012-02-24 17:41:38 +00009304 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00009305 }
9306#endif
9307
9308 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9309 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009310}
9311
Mike Stump1eb44332009-09-09 15:08:12 +00009312template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009313ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009314TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00009315 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009316}
Eli Friedman276b0612011-10-11 02:20:01 +00009317
9318template<typename Derived>
9319ExprResult
9320TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009321 QualType RetTy = getDerived().TransformType(E->getType());
9322 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009323 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009324 SubExprs.reserve(E->getNumSubExprs());
9325 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9326 SubExprs, &ArgumentChanged))
9327 return ExprError();
9328
9329 if (!getDerived().AlwaysRebuild() &&
9330 !ArgumentChanged)
9331 return SemaRef.Owned(E);
9332
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009333 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009334 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00009335}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009336
Douglas Gregorb98b1992009-08-11 05:31:07 +00009337//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00009338// Type reconstruction
9339//===----------------------------------------------------------------------===//
9340
Mike Stump1eb44332009-09-09 15:08:12 +00009341template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009342QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9343 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009344 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009345 getDerived().getBaseEntity());
9346}
9347
Mike Stump1eb44332009-09-09 15:08:12 +00009348template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009349QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9350 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009351 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009352 getDerived().getBaseEntity());
9353}
9354
Mike Stump1eb44332009-09-09 15:08:12 +00009355template<typename Derived>
9356QualType
John McCall85737a72009-10-30 00:06:24 +00009357TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9358 bool WrittenAsLValue,
9359 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009360 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00009361 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009362}
9363
9364template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009365QualType
John McCall85737a72009-10-30 00:06:24 +00009366TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9367 QualType ClassType,
9368 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009369 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00009370 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009371}
9372
9373template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009374QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00009375TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9376 ArrayType::ArraySizeModifier SizeMod,
9377 const llvm::APInt *Size,
9378 Expr *SizeExpr,
9379 unsigned IndexTypeQuals,
9380 SourceRange BracketsRange) {
9381 if (SizeExpr || !Size)
9382 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9383 IndexTypeQuals, BracketsRange,
9384 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00009385
9386 QualType Types[] = {
9387 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9388 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9389 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00009390 };
Craig Topperb9602322013-07-15 03:38:40 +00009391 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009392 QualType SizeType;
9393 for (unsigned I = 0; I != NumTypes; ++I)
9394 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9395 SizeType = Types[I];
9396 break;
9397 }
Mike Stump1eb44332009-09-09 15:08:12 +00009398
Eli Friedman01f276d2012-01-25 23:20:27 +00009399 // Note that we can return a VariableArrayType here in the case where
9400 // the element type was a dependent VariableArrayType.
9401 IntegerLiteral *ArraySize
9402 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9403 /*FIXME*/BracketsRange.getBegin());
9404 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009405 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00009406 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009407}
Mike Stump1eb44332009-09-09 15:08:12 +00009408
Douglas Gregor577f75a2009-08-04 16:50:30 +00009409template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009410QualType
9411TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009412 ArrayType::ArraySizeModifier SizeMod,
9413 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009414 unsigned IndexTypeQuals,
9415 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009416 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009417 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009418}
9419
9420template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009421QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009422TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009423 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009424 unsigned IndexTypeQuals,
9425 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009426 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009427 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009428}
Mike Stump1eb44332009-09-09 15:08:12 +00009429
Douglas Gregor577f75a2009-08-04 16:50:30 +00009430template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009431QualType
9432TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009433 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009434 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009435 unsigned IndexTypeQuals,
9436 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009437 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009438 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009439 IndexTypeQuals, BracketsRange);
9440}
9441
9442template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009443QualType
9444TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009445 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009446 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009447 unsigned IndexTypeQuals,
9448 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009449 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009450 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009451 IndexTypeQuals, BracketsRange);
9452}
9453
9454template<typename Derived>
9455QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009456 unsigned NumElements,
9457 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009458 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009459 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009460}
Mike Stump1eb44332009-09-09 15:08:12 +00009461
Douglas Gregor577f75a2009-08-04 16:50:30 +00009462template<typename Derived>
9463QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9464 unsigned NumElements,
9465 SourceLocation AttributeLoc) {
9466 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9467 NumElements, true);
9468 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009469 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9470 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009471 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009472}
Mike Stump1eb44332009-09-09 15:08:12 +00009473
Douglas Gregor577f75a2009-08-04 16:50:30 +00009474template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009475QualType
9476TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009477 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009478 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009479 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009480}
Mike Stump1eb44332009-09-09 15:08:12 +00009481
Douglas Gregor577f75a2009-08-04 16:50:30 +00009482template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009483QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9484 QualType T,
9485 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009486 const FunctionProtoType::ExtProtoInfo &EPI) {
9487 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009488 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009489 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009490 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009491}
Mike Stump1eb44332009-09-09 15:08:12 +00009492
Douglas Gregor577f75a2009-08-04 16:50:30 +00009493template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009494QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9495 return SemaRef.Context.getFunctionNoProtoType(T);
9496}
9497
9498template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009499QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9500 assert(D && "no decl found");
9501 if (D->isInvalidDecl()) return QualType();
9502
Douglas Gregor92e986e2010-04-22 16:44:27 +00009503 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009504 TypeDecl *Ty;
9505 if (isa<UsingDecl>(D)) {
9506 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanella8d030c72013-07-22 10:54:09 +00009507 assert(Using->hasTypename() &&
John McCalled976492009-12-04 22:46:56 +00009508 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9509
9510 // A valid resolved using typename decl points to exactly one type decl.
9511 assert(++Using->shadow_begin() == Using->shadow_end());
9512 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009513
John McCalled976492009-12-04 22:46:56 +00009514 } else {
9515 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9516 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9517 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9518 }
9519
9520 return SemaRef.Context.getTypeDeclType(Ty);
9521}
9522
9523template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009524QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9525 SourceLocation Loc) {
9526 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009527}
9528
9529template<typename Derived>
9530QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9531 return SemaRef.Context.getTypeOfType(Underlying);
9532}
9533
9534template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009535QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9536 SourceLocation Loc) {
9537 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009538}
9539
9540template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009541QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9542 UnaryTransformType::UTTKind UKind,
9543 SourceLocation Loc) {
9544 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9545}
9546
9547template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009548QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009549 TemplateName Template,
9550 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009551 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009552 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009553}
Mike Stump1eb44332009-09-09 15:08:12 +00009554
Douglas Gregordcee1a12009-08-06 05:28:30 +00009555template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009556QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9557 SourceLocation KWLoc) {
9558 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9559}
9560
9561template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009562TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009563TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009564 bool TemplateKW,
9565 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009566 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009567 Template);
9568}
9569
9570template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009571TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009572TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9573 const IdentifierInfo &Name,
9574 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009575 QualType ObjectType,
9576 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009577 UnqualifiedId TemplateName;
9578 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009579 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009580 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009581 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009582 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009583 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009584 /*EnteringContext=*/false,
9585 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009586 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009587}
Mike Stump1eb44332009-09-09 15:08:12 +00009588
Douglas Gregorb98b1992009-08-11 05:31:07 +00009589template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009590TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009591TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009592 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009593 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009594 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009595 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009596 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009597 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009598 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009599 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009600 Sema::TemplateTy Template;
9601 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009602 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009603 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009604 /*EnteringContext=*/false,
9605 Template);
Serge Pavlov18062392013-08-27 13:15:56 +00009606 return Template.get();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009607}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009608
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009609template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009610ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009611TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9612 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009613 Expr *OrigCallee,
9614 Expr *First,
9615 Expr *Second) {
9616 Expr *Callee = OrigCallee->IgnoreParenCasts();
9617 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009618
Douglas Gregorb98b1992009-08-11 05:31:07 +00009619 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009620 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009621 if (!First->getType()->isOverloadableType() &&
9622 !Second->getType()->isOverloadableType())
9623 return getSema().CreateBuiltinArraySubscriptExpr(First,
9624 Callee->getLocStart(),
9625 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009626 } else if (Op == OO_Arrow) {
9627 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009628 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9629 } else if (Second == 0 || isPostIncDec) {
9630 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009631 // The argument is not of overloadable type, so try to create a
9632 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009633 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009634 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009635
John McCall9ae2f072010-08-23 23:25:46 +00009636 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009637 }
9638 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009639 if (!First->getType()->isOverloadableType() &&
9640 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009641 // Neither of the arguments is an overloadable type, so try to
9642 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009643 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009644 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009645 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009646 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009647 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009648
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009649 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009650 }
9651 }
Mike Stump1eb44332009-09-09 15:08:12 +00009652
9653 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009654 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009655 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009656
John McCall9ae2f072010-08-23 23:25:46 +00009657 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009658 assert(ULE->requiresADL());
9659
9660 // FIXME: Do we have to check
9661 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009662 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009663 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009664 // If we've resolved this to a particular non-member function, just call
9665 // that function. If we resolved it to a member function,
9666 // CreateOverloaded* will find that function for us.
9667 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9668 if (!isa<CXXMethodDecl>(ND))
9669 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009670 }
Mike Stump1eb44332009-09-09 15:08:12 +00009671
Douglas Gregorb98b1992009-08-11 05:31:07 +00009672 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009673 Expr *Args[2] = { First, Second };
9674 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009675
Douglas Gregorb98b1992009-08-11 05:31:07 +00009676 // Create the overloaded operator invocation for unary operators.
9677 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009678 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009679 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009680 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009681 }
Mike Stump1eb44332009-09-09 15:08:12 +00009682
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009683 if (Op == OO_Subscript) {
9684 SourceLocation LBrace;
9685 SourceLocation RBrace;
9686
9687 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9688 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9689 LBrace = SourceLocation::getFromRawEncoding(
9690 NameLoc.CXXOperatorName.BeginOpNameLoc);
9691 RBrace = SourceLocation::getFromRawEncoding(
9692 NameLoc.CXXOperatorName.EndOpNameLoc);
9693 } else {
9694 LBrace = Callee->getLocStart();
9695 RBrace = OpLoc;
9696 }
9697
9698 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9699 First, Second);
9700 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009701
Douglas Gregorb98b1992009-08-11 05:31:07 +00009702 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009703 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009704 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009705 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9706 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009707 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009708
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009709 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009710}
Mike Stump1eb44332009-09-09 15:08:12 +00009711
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009712template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009713ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009714TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009715 SourceLocation OperatorLoc,
9716 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009717 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009718 TypeSourceInfo *ScopeType,
9719 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009720 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009721 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009722 QualType BaseType = Base->getType();
9723 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009724 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009725 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009726 !BaseType->getAs<PointerType>()->getPointeeType()
9727 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009728 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009729 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009730 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009731 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009732 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009733 /*FIXME?*/true);
9734 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009735
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009736 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009737 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9738 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9739 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9740 NameInfo.setNamedTypeInfo(DestroyedType);
9741
Richard Smith6314db92012-05-15 06:15:11 +00009742 // The scope type is now known to be a valid nested name specifier
9743 // component. Tack it on to the end of the nested name specifier.
9744 if (ScopeType)
9745 SS.Extend(SemaRef.Context, SourceLocation(),
9746 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009747
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009748 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009749 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009750 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009751 SS, TemplateKWLoc,
9752 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009753 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009754 /*TemplateArgs*/ 0);
9755}
9756
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009757template<typename Derived>
9758StmtResult
9759TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan9fd6b8f2013-05-04 03:59:06 +00009760 SourceLocation Loc = S->getLocStart();
9761 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9762 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9763 S->getCapturedRegionKind(), NumParams);
9764 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9765
9766 if (Body.isInvalid()) {
9767 getSema().ActOnCapturedRegionError();
9768 return StmtError();
9769 }
9770
9771 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009772}
9773
Douglas Gregor577f75a2009-08-04 16:50:30 +00009774} // end namespace clang
9775
9776#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H