blob: 9fbbe2cf1d51d96e7579b990b2ea8e152c4837c3 [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"
Douglas Gregorb98b1992009-08-11 05:31:07 +000027#include "clang/Lex/Preprocessor.h"
Chandler Carruth55fc8732012-12-04 09:13:33 +000028#include "clang/Sema/Designator.h"
29#include "clang/Sema/Lookup.h"
30#include "clang/Sema/Ownership.h"
31#include "clang/Sema/ParsedTemplate.h"
32#include "clang/Sema/ScopeInfo.h"
33#include "clang/Sema/SemaDiagnostic.h"
34#include "clang/Sema/SemaInternal.h"
David Blaikiea71f9d02011-09-22 02:34:54 +000035#include "llvm/ADT/ArrayRef.h"
John McCalla2becad2009-10-21 00:40:46 +000036#include "llvm/Support/ErrorHandling.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCall781472f2010-08-25 08:40:02 +000040using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000041
Douglas Gregor577f75a2009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump1eb44332009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump1eb44332009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor9151c112011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000101
Douglas Gregord3731192011-01-10 07:32:04 +0000102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000106
Douglas Gregord3731192011-01-10 07:32:04 +0000107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
Chad Rosier4a9d7952012-08-08 18:46:20 +0000111
Douglas Gregor577f75a2009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000114
Douglas Gregordfca6f52012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000119
Mike Stump1eb44332009-09-09 15:08:12 +0000120public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000123
Douglas Gregor577f75a2009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000130 }
131
John McCall60d7b3a2010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000134
Douglas Gregor577f75a2009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000138
Douglas Gregor577f75a2009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
144 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000145
Douglas Gregor577f75a2009-08-04 16:50:30 +0000146 /// \brief Returns the location of the entity being transformed, if that
147 /// information was not available elsewhere in the AST.
148 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000149 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000150 /// provide an alternative implementation that provides better location
151 /// information.
152 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000153
Douglas Gregor577f75a2009-08-04 16:50:30 +0000154 /// \brief Returns the name of the entity being transformed, if that
155 /// information was not available elsewhere in the AST.
156 ///
157 /// By default, returns an empty name. Subclasses can provide an alternative
158 /// implementation with a more precise name.
159 DeclarationName getBaseEntity() { return DeclarationName(); }
160
Douglas Gregorb98b1992009-08-11 05:31:07 +0000161 /// \brief Sets the "base" location and entity when that
162 /// information is known based on another transformation.
163 ///
164 /// By default, the source location and entity are ignored. Subclasses can
165 /// override this function to provide a customized implementation.
166 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000167
Douglas Gregorb98b1992009-08-11 05:31:07 +0000168 /// \brief RAII object that temporarily sets the base location and entity
169 /// used for reporting diagnostics in types.
170 class TemporaryBase {
171 TreeTransform &Self;
172 SourceLocation OldLocation;
173 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000174
Douglas Gregorb98b1992009-08-11 05:31:07 +0000175 public:
176 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000177 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000178 OldLocation = Self.getDerived().getBaseLocation();
179 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000180
Douglas Gregorae201f72011-01-25 17:51:48 +0000181 if (Location.isValid())
182 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000183 }
Mike Stump1eb44332009-09-09 15:08:12 +0000184
Douglas Gregorb98b1992009-08-11 05:31:07 +0000185 ~TemporaryBase() {
186 Self.getDerived().setBase(OldLocation, OldEntity);
187 }
188 };
Mike Stump1eb44332009-09-09 15:08:12 +0000189
190 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000191 /// transformed.
192 ///
193 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000194 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000195 /// not change. For example, template instantiation need not traverse
196 /// non-dependent types.
197 bool AlreadyTransformed(QualType T) {
198 return T.isNull();
199 }
200
Douglas Gregor6eef5192009-12-14 19:27:10 +0000201 /// \brief Determine whether the given call argument should be dropped, e.g.,
202 /// because it is a default argument.
203 ///
204 /// Subclasses can provide an alternative implementation of this routine to
205 /// determine which kinds of call arguments get dropped. By default,
206 /// CXXDefaultArgument nodes are dropped (prior to transformation).
207 bool DropCallArgument(Expr *E) {
208 return E->isDefaultArgument();
209 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000210
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000211 /// \brief Determine whether we should expand a pack expansion with the
212 /// given set of parameter packs into separate arguments by repeatedly
213 /// transforming the pattern.
214 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000215 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000216 /// Subclasses can override this routine to provide different behavior.
217 ///
218 /// \param EllipsisLoc The location of the ellipsis that identifies the
219 /// pack expansion.
220 ///
221 /// \param PatternRange The source range that covers the entire pattern of
222 /// the pack expansion.
223 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000224 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000225 /// pattern.
226 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000227 /// \param ShouldExpand Will be set to \c true if the transformer should
228 /// expand the corresponding pack expansions into separate arguments. When
229 /// set, \c NumExpansions must also be set.
230 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000231 /// \param RetainExpansion Whether the caller should add an unexpanded
232 /// pack expansion after all of the expanded arguments. This is used
233 /// when extending explicitly-specified template argument packs per
234 /// C++0x [temp.arg.explicit]p9.
235 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000236 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000237 /// the expanded form of the corresponding pack expansion. This is both an
238 /// input and an output parameter, which can be set by the caller if the
239 /// number of expansions is known a priori (e.g., due to a prior substitution)
240 /// and will be set by the callee when the number of expansions is known.
241 /// The callee must set this value when \c ShouldExpand is \c true; it may
242 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000243 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000244 /// \returns true if an error occurred (e.g., because the parameter packs
245 /// are to be instantiated with arguments of different lengths), false
246 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000247 /// must be set.
248 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
249 SourceRange PatternRange,
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +0000250 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000251 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000252 bool &RetainExpansion,
David Blaikiedc84cd52013-02-20 22:23:23 +0000253 Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000254 ShouldExpand = false;
255 return false;
256 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000257
Douglas Gregord3731192011-01-10 07:32:04 +0000258 /// \brief "Forget" about the partially-substituted pack template argument,
259 /// when performing an instantiation that must preserve the parameter pack
260 /// use.
261 ///
262 /// This routine is meant to be overridden by the template instantiator.
263 TemplateArgument ForgetPartiallySubstitutedPack() {
264 return TemplateArgument();
265 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000266
Douglas Gregord3731192011-01-10 07:32:04 +0000267 /// \brief "Remember" the partially-substituted pack template argument
268 /// after performing an instantiation that must preserve the parameter pack
269 /// use.
270 ///
271 /// This routine is meant to be overridden by the template instantiator.
272 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000273
Douglas Gregor12c9c002011-01-07 16:43:16 +0000274 /// \brief Note to the derived class when a function parameter pack is
275 /// being expanded.
276 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000277
Douglas Gregor577f75a2009-08-04 16:50:30 +0000278 /// \brief Transforms the given type into another type.
279 ///
John McCalla2becad2009-10-21 00:40:46 +0000280 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000281 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000282 /// function. This is expensive, but we don't mind, because
283 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000284 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000285 ///
286 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000287 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000288
John McCalla2becad2009-10-21 00:40:46 +0000289 /// \brief Transforms the given type-with-location into a new
290 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000291 ///
John McCalla2becad2009-10-21 00:40:46 +0000292 /// By default, this routine transforms a type by delegating to the
293 /// appropriate TransformXXXType to build a new type. Subclasses
294 /// may override this function (to take over all type
295 /// transformations) or some set of the TransformXXXType functions
296 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000297 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000298
299 /// \brief Transform the given type-with-location into a new
300 /// type, collecting location information in the given builder
301 /// as necessary.
302 ///
John McCall43fed0d2010-11-12 08:19:04 +0000303 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000304
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000305 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000306 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000307 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000308 /// appropriate TransformXXXStmt function to transform a specific kind of
309 /// statement or the TransformExpr() function to transform an expression.
310 /// Subclasses may override this function to transform statements using some
311 /// other mechanism.
312 ///
313 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000314 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000315
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000316 /// \brief Transform the given expression.
317 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000318 /// By default, this routine transforms an expression by delegating to the
319 /// appropriate TransformXXXExpr function to build a new expression.
320 /// Subclasses may override this function to transform expressions using some
321 /// other mechanism.
322 ///
323 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000324 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000325
Richard Smithc83c2302012-12-19 01:39:02 +0000326 /// \brief Transform the given initializer.
327 ///
328 /// By default, this routine transforms an initializer by stripping off the
329 /// semantic nodes added by initialization, then passing the result to
330 /// TransformExpr or TransformExprs.
331 ///
332 /// \returns the transformed initializer.
333 ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
334
Douglas Gregoraa165f82011-01-03 19:04:46 +0000335 /// \brief Transform the given list of expressions.
336 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000337 /// This routine transforms a list of expressions by invoking
338 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregoraa165f82011-01-03 19:04:46 +0000339 /// support for variadic templates by expanding any pack expansions (if the
340 /// derived class permits such expansion) along the way. When pack expansions
341 /// are present, the number of outputs may not equal the number of inputs.
342 ///
343 /// \param Inputs The set of expressions to be transformed.
344 ///
345 /// \param NumInputs The number of expressions in \c Inputs.
346 ///
347 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier4a9d7952012-08-08 18:46:20 +0000348 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregoraa165f82011-01-03 19:04:46 +0000349 /// be.
350 ///
351 /// \param Outputs The transformed input expressions will be added to this
352 /// vector.
353 ///
354 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
355 /// due to transformation.
356 ///
357 /// \returns true if an error occurred, false otherwise.
358 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +0000359 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000360 bool *ArgChanged = 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000361
Douglas Gregor577f75a2009-08-04 16:50:30 +0000362 /// \brief Transform the given declaration, which is referenced from a type
363 /// or expression.
364 ///
Douglas Gregordfca6f52012-02-13 22:00:16 +0000365 /// By default, acts as the identity function on declarations, unless the
366 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregordcee1a12009-08-06 05:28:30 +0000367 /// may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000368 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregordfca6f52012-02-13 22:00:16 +0000369 llvm::DenseMap<Decl *, Decl *>::iterator Known
370 = TransformedLocalDecls.find(D);
371 if (Known != TransformedLocalDecls.end())
372 return Known->second;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000373
374 return D;
Douglas Gregordfca6f52012-02-13 22:00:16 +0000375 }
Douglas Gregor43959a92009-08-20 07:17:43 +0000376
Chad Rosier4a9d7952012-08-08 18:46:20 +0000377 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregordfca6f52012-02-13 22:00:16 +0000378 /// place them on the new declaration.
379 ///
380 /// By default, this operation does nothing. Subclasses may override this
381 /// behavior to transform attributes.
382 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000383
Douglas Gregordfca6f52012-02-13 22:00:16 +0000384 /// \brief Note that a local declaration has been transformed by this
385 /// transformer.
386 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000387 /// Local declarations are typically transformed via a call to
Douglas Gregordfca6f52012-02-13 22:00:16 +0000388 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
389 /// the transformer itself has to transform the declarations. This routine
390 /// can be overridden by a subclass that keeps track of such mappings.
391 void transformedLocalDecl(Decl *Old, Decl *New) {
392 TransformedLocalDecls[Old] = New;
393 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000394
Douglas Gregor43959a92009-08-20 07:17:43 +0000395 /// \brief Transform the definition of the given declaration.
396 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000397 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000398 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000399 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
400 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000401 }
Mike Stump1eb44332009-09-09 15:08:12 +0000402
Douglas Gregor6cd21982009-10-20 05:58:46 +0000403 /// \brief Transform the given declaration, which was the first part of a
404 /// nested-name-specifier in a member access expression.
405 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000406 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000407 /// identifier in a nested-name-specifier of a member access expression, e.g.,
408 /// the \c T in \c x->T::member
409 ///
410 /// By default, invokes TransformDecl() to transform the declaration.
411 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000412 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
413 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000414 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000415
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000416 /// \brief Transform the given nested-name-specifier with source-location
417 /// information.
418 ///
419 /// By default, transforms all of the types and declarations within the
420 /// nested-name-specifier. Subclasses may override this function to provide
421 /// alternate behavior.
422 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
423 NestedNameSpecifierLoc NNS,
424 QualType ObjectType = QualType(),
425 NamedDecl *FirstQualifierInScope = 0);
426
Douglas Gregor81499bb2009-09-03 22:13:48 +0000427 /// \brief Transform the given declaration name.
428 ///
429 /// By default, transforms the types of conversion function, constructor,
430 /// and destructor names and then (if needed) rebuilds the declaration name.
431 /// Identifiers and selectors are returned unmodified. Sublcasses may
432 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000433 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000434 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000435
Douglas Gregor577f75a2009-08-04 16:50:30 +0000436 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000437 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000438 /// \param SS The nested-name-specifier that qualifies the template
439 /// name. This nested-name-specifier must already have been transformed.
440 ///
441 /// \param Name The template name to transform.
442 ///
443 /// \param NameLoc The source location of the template name.
444 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000445 /// \param ObjectType If we're translating a template name within a member
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000446 /// access expression, this is the type of the object whose member template
447 /// is being referenced.
448 ///
449 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
450 /// also refers to a name within the current (lexical) scope, this is the
451 /// declaration it refers to.
452 ///
453 /// By default, transforms the template name by transforming the declarations
454 /// and nested-name-specifiers that occur within the template name.
455 /// Subclasses may override this function to provide alternate behavior.
456 TemplateName TransformTemplateName(CXXScopeSpec &SS,
457 TemplateName Name,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000458 SourceLocation NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000459 QualType ObjectType = QualType(),
460 NamedDecl *FirstQualifierInScope = 0);
461
Douglas Gregor577f75a2009-08-04 16:50:30 +0000462 /// \brief Transform the given template argument.
463 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000464 /// By default, this operation transforms the type, expression, or
465 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000466 /// new template argument from the transformed result. Subclasses may
467 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000468 ///
469 /// Returns true if there was an error.
470 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
471 TemplateArgumentLoc &Output);
472
Douglas Gregorfcc12532010-12-20 17:31:10 +0000473 /// \brief Transform the given set of template arguments.
474 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000475 /// By default, this operation transforms all of the template arguments
Douglas Gregorfcc12532010-12-20 17:31:10 +0000476 /// in the input set using \c TransformTemplateArgument(), and appends
477 /// the transformed arguments to the output list.
478 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000479 /// Note that this overload of \c TransformTemplateArguments() is merely
480 /// a convenience function. Subclasses that wish to override this behavior
481 /// should override the iterator-based member template version.
482 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000483 /// \param Inputs The set of template arguments to be transformed.
484 ///
485 /// \param NumInputs The number of template arguments in \p Inputs.
486 ///
487 /// \param Outputs The set of transformed template arguments output by this
488 /// routine.
489 ///
490 /// Returns true if an error occurred.
491 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
492 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000493 TemplateArgumentListInfo &Outputs) {
494 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
495 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000496
497 /// \brief Transform the given set of template arguments.
498 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000499 /// By default, this operation transforms all of the template arguments
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000500 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier4a9d7952012-08-08 18:46:20 +0000501 /// the transformed arguments to the output list.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000502 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000503 /// \param First An iterator to the first template argument.
504 ///
505 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000506 ///
507 /// \param Outputs The set of transformed template arguments output by this
508 /// routine.
509 ///
510 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000511 template<typename InputIterator>
512 bool TransformTemplateArguments(InputIterator First,
513 InputIterator Last,
514 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000515
John McCall833ca992009-10-29 08:12:44 +0000516 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
517 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
518 TemplateArgumentLoc &ArgLoc);
519
John McCalla93c9342009-12-07 02:54:59 +0000520 /// \brief Fakes up a TypeSourceInfo for a type.
521 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
522 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000523 getDerived().getBaseLocation());
524 }
Mike Stump1eb44332009-09-09 15:08:12 +0000525
John McCalla2becad2009-10-21 00:40:46 +0000526#define ABSTRACT_TYPELOC(CLASS, PARENT)
527#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000528 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000529#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000530
Douglas Gregorcefc3af2012-04-16 07:05:22 +0000531 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
532 FunctionProtoTypeLoc TL,
533 CXXRecordDecl *ThisContext,
534 unsigned ThisTypeQuals);
535
John Wiegley28bbe4b2011-04-28 01:08:34 +0000536 StmtResult
537 TransformSEHHandler(Stmt *Handler);
538
Chad Rosier4a9d7952012-08-08 18:46:20 +0000539 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000540 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
541 TemplateSpecializationTypeLoc TL,
542 TemplateName Template);
543
Chad Rosier4a9d7952012-08-08 18:46:20 +0000544 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000545 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
546 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000547 TemplateName Template,
548 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000549
Chad Rosier4a9d7952012-08-08 18:46:20 +0000550 QualType
Douglas Gregora88f09f2011-02-28 17:23:35 +0000551 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000552 DependentTemplateSpecializationTypeLoc TL,
553 NestedNameSpecifierLoc QualifierLoc);
554
John McCall21ef0fa2010-03-11 09:03:00 +0000555 /// \brief Transforms the parameters of a function type into the
556 /// given vectors.
557 ///
558 /// The result vectors should be kept in sync; null entries in the
559 /// variables vector are acceptable.
560 ///
561 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000562 bool TransformFunctionTypeParams(SourceLocation Loc,
563 ParmVarDecl **Params, unsigned NumParams,
564 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000565 SmallVectorImpl<QualType> &PTypes,
566 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000567
568 /// \brief Transforms a single function-type parameter. Return null
569 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000570 ///
571 /// \param indexAdjustment - A number to add to the parameter's
572 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000573 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000574 int indexAdjustment,
David Blaikiedc84cd52013-02-20 22:23:23 +0000575 Optional<unsigned> NumExpansions,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000576 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000577
John McCall43fed0d2010-11-12 08:19:04 +0000578 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000579
John McCall60d7b3a2010-08-24 06:29:42 +0000580 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
581 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000582
Richard Smith612409e2012-07-25 03:56:55 +0000583 /// \brief Transform the captures and body of a lambda expression.
584 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator);
585
Richard Smithefeeccf2012-10-21 03:28:35 +0000586 ExprResult TransformAddressOfOperand(Expr *E);
587 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
588 bool IsAddressOfOperand);
589
Douglas Gregor43959a92009-08-20 07:17:43 +0000590#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000591 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000592#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000593 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000594#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000595#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000596
Douglas Gregor577f75a2009-08-04 16:50:30 +0000597 /// \brief Build a new pointer type given its pointee type.
598 ///
599 /// By default, performs semantic analysis when building the pointer type.
600 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000601 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000602
603 /// \brief Build a new block pointer type given its pointee type.
604 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000605 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000606 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000607 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000608
John McCall85737a72009-10-30 00:06:24 +0000609 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000610 ///
John McCall85737a72009-10-30 00:06:24 +0000611 /// By default, performs semantic analysis when building the
612 /// reference type. Subclasses may override this routine to provide
613 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000614 ///
John McCall85737a72009-10-30 00:06:24 +0000615 /// \param LValue whether the type was written with an lvalue sigil
616 /// or an rvalue sigil.
617 QualType RebuildReferenceType(QualType ReferentType,
618 bool LValue,
619 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000620
Douglas Gregor577f75a2009-08-04 16:50:30 +0000621 /// \brief Build a new member pointer type given the pointee type and the
622 /// class type it refers into.
623 ///
624 /// By default, performs semantic analysis when building the member pointer
625 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000626 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
627 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000628
Douglas Gregor577f75a2009-08-04 16:50:30 +0000629 /// \brief Build a new array type given the element type, size
630 /// modifier, size of the array (if known), size expression, and index type
631 /// qualifiers.
632 ///
633 /// By default, performs semantic analysis when building the array type.
634 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000635 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000636 QualType RebuildArrayType(QualType ElementType,
637 ArrayType::ArraySizeModifier SizeMod,
638 const llvm::APInt *Size,
639 Expr *SizeExpr,
640 unsigned IndexTypeQuals,
641 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000642
Douglas Gregor577f75a2009-08-04 16:50:30 +0000643 /// \brief Build a new constant array type given the element type, size
644 /// modifier, (known) size of the array, and index type qualifiers.
645 ///
646 /// By default, performs semantic analysis when building the array type.
647 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000648 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000649 ArrayType::ArraySizeModifier SizeMod,
650 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000651 unsigned IndexTypeQuals,
652 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000653
Douglas Gregor577f75a2009-08-04 16:50:30 +0000654 /// \brief Build a new incomplete array type given the element type, size
655 /// modifier, and index type qualifiers.
656 ///
657 /// By default, performs semantic analysis when building the array type.
658 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000659 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000660 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000661 unsigned IndexTypeQuals,
662 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000663
Mike Stump1eb44332009-09-09 15:08:12 +0000664 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000665 /// size modifier, size expression, and index type qualifiers.
666 ///
667 /// By default, performs semantic analysis when building the array type.
668 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000669 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000670 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000671 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000672 unsigned IndexTypeQuals,
673 SourceRange BracketsRange);
674
Mike Stump1eb44332009-09-09 15:08:12 +0000675 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000676 /// size modifier, size expression, and index type qualifiers.
677 ///
678 /// By default, performs semantic analysis when building the array type.
679 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000680 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000681 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000682 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000683 unsigned IndexTypeQuals,
684 SourceRange BracketsRange);
685
686 /// \brief Build a new vector type given the element type and
687 /// number of elements.
688 ///
689 /// By default, performs semantic analysis when building the vector type.
690 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000691 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000692 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000693
Douglas Gregor577f75a2009-08-04 16:50:30 +0000694 /// \brief Build a new extended vector type given the element type and
695 /// number of elements.
696 ///
697 /// By default, performs semantic analysis when building the vector type.
698 /// Subclasses may override this routine to provide different behavior.
699 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
700 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000701
702 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000703 /// given the element type and number of elements.
704 ///
705 /// By default, performs semantic analysis when building the vector type.
706 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000707 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000708 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000709 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000710
Douglas Gregor577f75a2009-08-04 16:50:30 +0000711 /// \brief Build a new function type.
712 ///
713 /// By default, performs semantic analysis when building the function type.
714 /// Subclasses may override this routine to provide different behavior.
715 QualType RebuildFunctionProtoType(QualType T,
Jordan Rosebea522f2013-03-08 21:51:21 +0000716 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +0000717 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump1eb44332009-09-09 15:08:12 +0000718
John McCalla2becad2009-10-21 00:40:46 +0000719 /// \brief Build a new unprototyped function type.
720 QualType RebuildFunctionNoProtoType(QualType ResultType);
721
John McCalled976492009-12-04 22:46:56 +0000722 /// \brief Rebuild an unresolved typename type, given the decl that
723 /// the UnresolvedUsingTypenameDecl was transformed to.
724 QualType RebuildUnresolvedUsingType(Decl *D);
725
Douglas Gregor577f75a2009-08-04 16:50:30 +0000726 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000727 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000728 return SemaRef.Context.getTypeDeclType(Typedef);
729 }
730
731 /// \brief Build a new class/struct/union type.
732 QualType RebuildRecordType(RecordDecl *Record) {
733 return SemaRef.Context.getTypeDeclType(Record);
734 }
735
736 /// \brief Build a new Enum type.
737 QualType RebuildEnumType(EnumDecl *Enum) {
738 return SemaRef.Context.getTypeDeclType(Enum);
739 }
John McCall7da24312009-09-05 00:15:47 +0000740
Mike Stump1eb44332009-09-09 15:08:12 +0000741 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000742 ///
743 /// By default, performs semantic analysis when building the typeof type.
744 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000745 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000746
Mike Stump1eb44332009-09-09 15:08:12 +0000747 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000748 ///
749 /// By default, builds a new TypeOfType with the given underlying type.
750 QualType RebuildTypeOfType(QualType Underlying);
751
Sean Huntca63c202011-05-24 22:41:36 +0000752 /// \brief Build a new unary transform type.
753 QualType RebuildUnaryTransformType(QualType BaseType,
754 UnaryTransformType::UTTKind UKind,
755 SourceLocation Loc);
756
Richard Smitha2c36462013-04-26 16:15:35 +0000757 /// \brief Build a new C++11 decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000758 ///
759 /// By default, performs semantic analysis when building the decltype type.
760 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000761 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000762
Richard Smitha2c36462013-04-26 16:15:35 +0000763 /// \brief Build a new C++11 auto type.
Richard Smith34b41d92011-02-20 03:19:35 +0000764 ///
765 /// By default, builds a new AutoType with the given deduced type.
Richard Smitha2c36462013-04-26 16:15:35 +0000766 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smithdc7a4f52013-04-30 13:56:41 +0000767 // Note, IsDependent is always false here: we implicitly convert an 'auto'
768 // which has been deduced to a dependent type into an undeduced 'auto', so
769 // that we'll retry deduction after the transformation.
Richard Smitha2c36462013-04-26 16:15:35 +0000770 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto);
Richard Smith34b41d92011-02-20 03:19:35 +0000771 }
772
Douglas Gregor577f75a2009-08-04 16:50:30 +0000773 /// \brief Build a new template specialization type.
774 ///
775 /// By default, performs semantic analysis when building the template
776 /// specialization type. Subclasses may override this routine to provide
777 /// different behavior.
778 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000779 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000780 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000781
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000782 /// \brief Build a new parenthesized type.
783 ///
784 /// By default, builds a new ParenType type from the inner type.
785 /// Subclasses may override this routine to provide different behavior.
786 QualType RebuildParenType(QualType InnerType) {
787 return SemaRef.Context.getParenType(InnerType);
788 }
789
Douglas Gregor577f75a2009-08-04 16:50:30 +0000790 /// \brief Build a new qualified name type.
791 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000792 /// By default, builds a new ElaboratedType type from the keyword,
793 /// the nested-name-specifier and the named type.
794 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000795 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
796 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000797 NestedNameSpecifierLoc QualifierLoc,
798 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000799 return SemaRef.Context.getElaboratedType(Keyword,
800 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000801 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000802 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000803
804 /// \brief Build a new typename type that refers to a template-id.
805 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000806 /// By default, builds a new DependentNameType type from the
807 /// nested-name-specifier and the given type. Subclasses may override
808 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000809 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000810 ElaboratedTypeKeyword Keyword,
811 NestedNameSpecifierLoc QualifierLoc,
812 const IdentifierInfo *Name,
813 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000814 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000815 // Rebuild the template name.
816 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000817 CXXScopeSpec SS;
818 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000819 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000820 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000821
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000822 if (InstName.isNull())
823 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000824
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000825 // If it's still dependent, make a dependent specialization.
826 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000827 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
828 QualifierLoc.getNestedNameSpecifier(),
829 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000830 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000831
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000832 // Otherwise, make an elaborated type wrapping a non-dependent
833 // specialization.
834 QualType T =
835 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
836 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000837
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000838 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
839 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000840
841 return SemaRef.Context.getElaboratedType(Keyword,
842 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000843 T);
844 }
845
Douglas Gregor577f75a2009-08-04 16:50:30 +0000846 /// \brief Build a new typename type that refers to an identifier.
847 ///
848 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000849 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000850 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000851 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000852 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000853 NestedNameSpecifierLoc QualifierLoc,
854 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000855 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000856 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000857 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000858
Douglas Gregor2494dd02011-03-01 01:34:45 +0000859 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000860 // If the name is still dependent, just build a new dependent name type.
861 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000862 return SemaRef.Context.getDependentNameType(Keyword,
863 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000864 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000865 }
866
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000867 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000868 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000869 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000870
871 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
872
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000873 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000874 // into a non-dependent elaborated-type-specifier. Find the tag we're
875 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000876 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000877 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
878 if (!DC)
879 return QualType();
880
John McCall56138762010-05-27 06:40:31 +0000881 if (SemaRef.RequireCompleteDeclContext(SS, DC))
882 return QualType();
883
Douglas Gregor40336422010-03-31 22:19:08 +0000884 TagDecl *Tag = 0;
885 SemaRef.LookupQualifiedName(Result, DC);
886 switch (Result.getResultKind()) {
887 case LookupResult::NotFound:
888 case LookupResult::NotFoundInCurrentInstantiation:
889 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000890
Douglas Gregor40336422010-03-31 22:19:08 +0000891 case LookupResult::Found:
892 Tag = Result.getAsSingle<TagDecl>();
893 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000894
Douglas Gregor40336422010-03-31 22:19:08 +0000895 case LookupResult::FoundOverloaded:
896 case LookupResult::FoundUnresolvedValue:
897 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000898
Douglas Gregor40336422010-03-31 22:19:08 +0000899 case LookupResult::Ambiguous:
900 // Let the LookupResult structure handle ambiguities.
901 return QualType();
902 }
903
904 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000905 // Check where the name exists but isn't a tag type and use that to emit
906 // better diagnostics.
907 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
908 SemaRef.LookupQualifiedName(Result, DC);
909 switch (Result.getResultKind()) {
910 case LookupResult::Found:
911 case LookupResult::FoundOverloaded:
912 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000913 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000914 unsigned Kind = 0;
915 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000916 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
917 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000918 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
919 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
920 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000921 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000922 default:
923 // FIXME: Would be nice to highlight just the source range.
924 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
925 << Kind << Id << DC;
926 break;
927 }
Douglas Gregor40336422010-03-31 22:19:08 +0000928 return QualType();
929 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000930
Richard Trieubbf34c02011-06-10 03:11:26 +0000931 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
932 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000933 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000934 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
935 return QualType();
936 }
937
938 // Build the elaborated-type-specifier type.
939 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000940 return SemaRef.Context.getElaboratedType(Keyword,
941 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000942 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000943 }
Mike Stump1eb44332009-09-09 15:08:12 +0000944
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000945 /// \brief Build a new pack expansion type.
946 ///
947 /// By default, builds a new PackExpansionType type from the given pattern.
948 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000949 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000950 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000951 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +0000952 Optional<unsigned> NumExpansions) {
Douglas Gregorcded4f62011-01-14 17:04:44 +0000953 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
954 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000955 }
956
Eli Friedmanb001de72011-10-06 23:00:33 +0000957 /// \brief Build a new atomic type given its value type.
958 ///
959 /// By default, performs semantic analysis when building the atomic type.
960 /// Subclasses may override this routine to provide different behavior.
961 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
962
Douglas Gregord1067e52009-08-06 06:41:21 +0000963 /// \brief Build a new template name given a nested name specifier, a flag
964 /// indicating whether the "template" keyword was provided, and the template
965 /// that the template name refers to.
966 ///
967 /// By default, builds the new template name directly. Subclasses may override
968 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000969 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000970 bool TemplateKW,
971 TemplateDecl *Template);
972
Douglas Gregord1067e52009-08-06 06:41:21 +0000973 /// \brief Build a new template name given a nested name specifier and the
974 /// name that is referred to as a template.
975 ///
976 /// By default, performs semantic analysis to determine whether the name can
977 /// be resolved to a specific template, then builds the appropriate kind of
978 /// template name. Subclasses may override this routine to provide different
979 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000980 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
981 const IdentifierInfo &Name,
982 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000983 QualType ObjectType,
984 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000985
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000986 /// \brief Build a new template name given a nested name specifier and the
987 /// overloaded operator name that is referred to as a template.
988 ///
989 /// By default, performs semantic analysis to determine whether the name can
990 /// be resolved to a specific template, then builds the appropriate kind of
991 /// template name. Subclasses may override this routine to provide different
992 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000993 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000994 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000995 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000996 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000997
998 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +0000999 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001000 ///
1001 /// By default, performs semantic analysis to determine whether the name can
1002 /// be resolved to a specific template, then builds the appropriate kind of
1003 /// template name. Subclasses may override this routine to provide different
1004 /// behavior.
1005 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1006 const TemplateArgument &ArgPack) {
1007 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1008 }
1009
Douglas Gregor43959a92009-08-20 07:17:43 +00001010 /// \brief Build a new compound statement.
1011 ///
1012 /// By default, performs semantic analysis to build the new statement.
1013 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001014 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001015 MultiStmtArg Statements,
1016 SourceLocation RBraceLoc,
1017 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001018 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001019 IsStmtExpr);
1020 }
1021
1022 /// \brief Build a new case statement.
1023 ///
1024 /// By default, performs semantic analysis to build the new statement.
1025 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001026 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001027 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001028 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001029 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001030 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001031 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001032 ColonLoc);
1033 }
Mike Stump1eb44332009-09-09 15:08:12 +00001034
Douglas Gregor43959a92009-08-20 07:17:43 +00001035 /// \brief Attach the body to a new case statement.
1036 ///
1037 /// By default, performs semantic analysis to build the new statement.
1038 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001039 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001040 getSema().ActOnCaseStmtBody(S, Body);
1041 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001042 }
Mike Stump1eb44332009-09-09 15:08:12 +00001043
Douglas Gregor43959a92009-08-20 07:17:43 +00001044 /// \brief Build a new default statement.
1045 ///
1046 /// By default, performs semantic analysis to build the new statement.
1047 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001048 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001049 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001050 Stmt *SubStmt) {
1051 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001052 /*CurScope=*/0);
1053 }
Mike Stump1eb44332009-09-09 15:08:12 +00001054
Douglas Gregor43959a92009-08-20 07:17:43 +00001055 /// \brief Build a new label statement.
1056 ///
1057 /// By default, performs semantic analysis to build the new statement.
1058 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001059 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1060 SourceLocation ColonLoc, Stmt *SubStmt) {
1061 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001062 }
Mike Stump1eb44332009-09-09 15:08:12 +00001063
Richard Smith534986f2012-04-14 00:33:13 +00001064 /// \brief Build a new label statement.
1065 ///
1066 /// By default, performs semantic analysis to build the new statement.
1067 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001068 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1069 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001070 Stmt *SubStmt) {
1071 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1072 }
1073
Douglas Gregor43959a92009-08-20 07:17:43 +00001074 /// \brief Build a new "if" statement.
1075 ///
1076 /// By default, performs semantic analysis to build the new statement.
1077 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001078 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001079 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001080 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001081 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001082 }
Mike Stump1eb44332009-09-09 15:08:12 +00001083
Douglas Gregor43959a92009-08-20 07:17:43 +00001084 /// \brief Start building a new switch statement.
1085 ///
1086 /// By default, performs semantic analysis to build the new statement.
1087 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001088 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001089 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001090 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001091 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001092 }
Mike Stump1eb44332009-09-09 15:08:12 +00001093
Douglas Gregor43959a92009-08-20 07:17:43 +00001094 /// \brief Attach the body to the switch 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 RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001099 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001100 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001101 }
1102
1103 /// \brief Build a new while statement.
1104 ///
1105 /// By default, performs semantic analysis to build the new statement.
1106 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001107 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1108 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001109 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001110 }
Mike Stump1eb44332009-09-09 15:08:12 +00001111
Douglas Gregor43959a92009-08-20 07:17:43 +00001112 /// \brief Build a new do-while statement.
1113 ///
1114 /// By default, performs semantic analysis to build the new statement.
1115 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001116 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001117 SourceLocation WhileLoc, SourceLocation LParenLoc,
1118 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001119 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1120 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001121 }
1122
1123 /// \brief Build a new for statement.
1124 ///
1125 /// By default, performs semantic analysis to build the new statement.
1126 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001127 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001128 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001129 VarDecl *CondVar, Sema::FullExprArg Inc,
1130 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001131 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001132 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001133 }
Mike Stump1eb44332009-09-09 15:08:12 +00001134
Douglas Gregor43959a92009-08-20 07:17:43 +00001135 /// \brief Build a new goto statement.
1136 ///
1137 /// By default, performs semantic analysis to build the new statement.
1138 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001139 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1140 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001141 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001142 }
1143
1144 /// \brief Build a new indirect goto statement.
1145 ///
1146 /// By default, performs semantic analysis to build the new statement.
1147 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001148 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001149 SourceLocation StarLoc,
1150 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001151 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001152 }
Mike Stump1eb44332009-09-09 15:08:12 +00001153
Douglas Gregor43959a92009-08-20 07:17:43 +00001154 /// \brief Build a new return statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001158 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001159 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001160 }
Mike Stump1eb44332009-09-09 15:08:12 +00001161
Douglas Gregor43959a92009-08-20 07:17:43 +00001162 /// \brief Build a new declaration statement.
1163 ///
1164 /// By default, performs semantic analysis to build the new statement.
1165 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001166 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001167 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001168 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001169 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1170 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001171 }
Mike Stump1eb44332009-09-09 15:08:12 +00001172
Anders Carlsson703e3942010-01-24 05:50:09 +00001173 /// \brief Build a new inline asm statement.
1174 ///
1175 /// By default, performs semantic analysis to build the new statement.
1176 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001177 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1178 bool IsVolatile, unsigned NumOutputs,
1179 unsigned NumInputs, IdentifierInfo **Names,
1180 MultiExprArg Constraints, MultiExprArg Exprs,
1181 Expr *AsmString, MultiExprArg Clobbers,
1182 SourceLocation RParenLoc) {
1183 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1184 NumInputs, Names, Constraints, Exprs,
1185 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001186 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001187
Chad Rosier8cd64b42012-06-11 20:47:18 +00001188 /// \brief Build a new MS style inline asm statement.
1189 ///
1190 /// By default, performs semantic analysis to build the new statement.
1191 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001192 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallaeeacf72013-05-03 00:10:13 +00001193 ArrayRef<Token> AsmToks,
1194 StringRef AsmString,
1195 unsigned NumOutputs, unsigned NumInputs,
1196 ArrayRef<StringRef> Constraints,
1197 ArrayRef<StringRef> Clobbers,
1198 ArrayRef<Expr*> Exprs,
1199 SourceLocation EndLoc) {
1200 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1201 NumOutputs, NumInputs,
1202 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001203 }
1204
James Dennett699c9042012-06-15 07:13:21 +00001205 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001206 ///
1207 /// By default, performs semantic analysis to build the new statement.
1208 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001209 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001210 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001211 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001212 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001213 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001214 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001215 }
1216
Douglas Gregorbe270a02010-04-26 17:57:08 +00001217 /// \brief Rebuild an Objective-C exception declaration.
1218 ///
1219 /// By default, performs semantic analysis to build the new declaration.
1220 /// Subclasses may override this routine to provide different behavior.
1221 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1222 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001223 return getSema().BuildObjCExceptionDecl(TInfo, T,
1224 ExceptionDecl->getInnerLocStart(),
1225 ExceptionDecl->getLocation(),
1226 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001227 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001228
James Dennett699c9042012-06-15 07:13:21 +00001229 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001230 ///
1231 /// By default, performs semantic analysis to build the new statement.
1232 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001233 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001234 SourceLocation RParenLoc,
1235 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001236 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001237 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001238 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001239 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001240
James Dennett699c9042012-06-15 07:13:21 +00001241 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001242 ///
1243 /// By default, performs semantic analysis to build the new statement.
1244 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001245 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001246 Stmt *Body) {
1247 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001248 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001249
James Dennett699c9042012-06-15 07:13:21 +00001250 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001251 ///
1252 /// By default, performs semantic analysis to build the new statement.
1253 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001254 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001255 Expr *Operand) {
1256 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001257 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001258
James Dennett699c9042012-06-15 07:13:21 +00001259 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001260 ///
1261 /// By default, performs semantic analysis to build the new statement.
1262 /// Subclasses may override this routine to provide different behavior.
1263 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1264 Expr *object) {
1265 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1266 }
1267
James Dennett699c9042012-06-15 07:13:21 +00001268 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001269 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001270 /// By default, performs semantic analysis to build the new statement.
1271 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001272 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001273 Expr *Object, Stmt *Body) {
1274 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001275 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001276
James Dennett699c9042012-06-15 07:13:21 +00001277 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001278 ///
1279 /// By default, performs semantic analysis to build the new statement.
1280 /// Subclasses may override this routine to provide different behavior.
1281 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1282 Stmt *Body) {
1283 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1284 }
John McCall990567c2011-07-27 01:07:15 +00001285
Douglas Gregorc3203e72010-04-22 23:10:45 +00001286 /// \brief Build a new Objective-C fast enumeration statement.
1287 ///
1288 /// By default, performs semantic analysis to build the new statement.
1289 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001290 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001291 Stmt *Element,
1292 Expr *Collection,
1293 SourceLocation RParenLoc,
1294 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001295 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001296 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001297 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001298 RParenLoc);
1299 if (ForEachStmt.isInvalid())
1300 return StmtError();
1301
1302 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001303 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001304
Douglas Gregor43959a92009-08-20 07:17:43 +00001305 /// \brief Build a new C++ exception declaration.
1306 ///
1307 /// By default, performs semantic analysis to build the new decaration.
1308 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001309 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001310 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001311 SourceLocation StartLoc,
1312 SourceLocation IdLoc,
1313 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001314 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1315 StartLoc, IdLoc, Id);
1316 if (Var)
1317 getSema().CurContext->addDecl(Var);
1318 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001319 }
1320
1321 /// \brief Build a new C++ catch statement.
1322 ///
1323 /// By default, performs semantic analysis to build the new statement.
1324 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001325 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001326 VarDecl *ExceptionDecl,
1327 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001328 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1329 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001330 }
Mike Stump1eb44332009-09-09 15:08:12 +00001331
Douglas Gregor43959a92009-08-20 07:17:43 +00001332 /// \brief Build a new C++ try statement.
1333 ///
1334 /// By default, performs semantic analysis to build the new statement.
1335 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001336 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001337 Stmt *TryBlock,
1338 MultiStmtArg Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001339 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001340 }
Mike Stump1eb44332009-09-09 15:08:12 +00001341
Richard Smithad762fc2011-04-14 22:09:26 +00001342 /// \brief Build a new C++0x range-based for statement.
1343 ///
1344 /// By default, performs semantic analysis to build the new statement.
1345 /// Subclasses may override this routine to provide different behavior.
1346 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1347 SourceLocation ColonLoc,
1348 Stmt *Range, Stmt *BeginEnd,
1349 Expr *Cond, Expr *Inc,
1350 Stmt *LoopVar,
1351 SourceLocation RParenLoc) {
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001352 // If we've just learned that the range is actually an Objective-C
1353 // collection, treat this as an Objective-C fast enumeration loop.
1354 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1355 if (RangeStmt->isSingleDecl()) {
1356 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39b60dc2013-05-02 18:35:56 +00001357 if (RangeVar->isInvalidDecl())
1358 return StmtError();
1359
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001360 Expr *RangeExpr = RangeVar->getInit();
1361 if (!RangeExpr->isTypeDependent() &&
1362 RangeExpr->getType()->isObjCObjectPointerType())
1363 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1364 RParenLoc);
1365 }
1366 }
1367 }
1368
Richard Smithad762fc2011-04-14 22:09:26 +00001369 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001370 Cond, Inc, LoopVar, RParenLoc,
1371 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001372 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001373
1374 /// \brief Build a new C++0x range-based for statement.
1375 ///
1376 /// By default, performs semantic analysis to build the new statement.
1377 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001378 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001379 bool IsIfExists,
1380 NestedNameSpecifierLoc QualifierLoc,
1381 DeclarationNameInfo NameInfo,
1382 Stmt *Nested) {
1383 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1384 QualifierLoc, NameInfo, Nested);
1385 }
1386
Richard Smithad762fc2011-04-14 22:09:26 +00001387 /// \brief Attach body to a C++0x range-based for statement.
1388 ///
1389 /// By default, performs semantic analysis to finish the new statement.
1390 /// Subclasses may override this routine to provide different behavior.
1391 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1392 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1393 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001394
John Wiegley28bbe4b2011-04-28 01:08:34 +00001395 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1396 SourceLocation TryLoc,
1397 Stmt *TryBlock,
1398 Stmt *Handler) {
1399 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1400 }
1401
1402 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1403 Expr *FilterExpr,
1404 Stmt *Block) {
1405 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1406 }
1407
1408 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1409 Stmt *Block) {
1410 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1411 }
1412
Douglas Gregorb98b1992009-08-11 05:31:07 +00001413 /// \brief Build a new expression that references a declaration.
1414 ///
1415 /// By default, performs semantic analysis to build the new expression.
1416 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001417 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001418 LookupResult &R,
1419 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001420 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1421 }
1422
1423
1424 /// \brief Build a new expression that references a declaration.
1425 ///
1426 /// By default, performs semantic analysis to build the new expression.
1427 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001428 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001429 ValueDecl *VD,
1430 const DeclarationNameInfo &NameInfo,
1431 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001432 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001433 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001434
1435 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001436
1437 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001438 }
Mike Stump1eb44332009-09-09 15:08:12 +00001439
Douglas Gregorb98b1992009-08-11 05:31:07 +00001440 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001441 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001442 /// By default, performs semantic analysis to build the new expression.
1443 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001444 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001445 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001446 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001447 }
1448
Douglas Gregora71d8192009-09-04 17:36:40 +00001449 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001450 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001451 /// By default, performs semantic analysis to build the new expression.
1452 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001453 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001454 SourceLocation OperatorLoc,
1455 bool isArrow,
1456 CXXScopeSpec &SS,
1457 TypeSourceInfo *ScopeType,
1458 SourceLocation CCLoc,
1459 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001460 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001461
Douglas Gregorb98b1992009-08-11 05:31:07 +00001462 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001463 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001464 /// By default, performs semantic analysis to build the new expression.
1465 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001466 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001467 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001468 Expr *SubExpr) {
1469 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001470 }
Mike Stump1eb44332009-09-09 15:08:12 +00001471
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001472 /// \brief Build a new builtin offsetof expression.
1473 ///
1474 /// By default, performs semantic analysis to build the new expression.
1475 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001476 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001477 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001478 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001479 unsigned NumComponents,
1480 SourceLocation RParenLoc) {
1481 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1482 NumComponents, RParenLoc);
1483 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001484
1485 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001486 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001487 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001488 /// By default, performs semantic analysis to build the new expression.
1489 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001490 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1491 SourceLocation OpLoc,
1492 UnaryExprOrTypeTrait ExprKind,
1493 SourceRange R) {
1494 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001495 }
1496
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001497 /// \brief Build a new sizeof, alignof or vec step expression with an
1498 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001499 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001500 /// By default, performs semantic analysis to build the new expression.
1501 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001502 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1503 UnaryExprOrTypeTrait ExprKind,
1504 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001505 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001506 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001507 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001508 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001509
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001510 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001511 }
Mike Stump1eb44332009-09-09 15:08:12 +00001512
Douglas Gregorb98b1992009-08-11 05:31:07 +00001513 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001514 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001515 /// By default, performs semantic analysis to build the new expression.
1516 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001517 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001518 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001519 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001520 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001521 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1522 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001523 RBracketLoc);
1524 }
1525
1526 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001527 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001528 /// By default, performs semantic analysis to build the new expression.
1529 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001530 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001531 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001532 SourceLocation RParenLoc,
1533 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001534 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001535 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001536 }
1537
1538 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001539 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001540 /// By default, performs semantic analysis to build the new expression.
1541 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001542 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001543 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001544 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001545 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001546 const DeclarationNameInfo &MemberNameInfo,
1547 ValueDecl *Member,
1548 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001549 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001550 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001551 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1552 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001553 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001554 // We have a reference to an unnamed field. This is always the
1555 // base of an anonymous struct/union member access, i.e. the
1556 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001557 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001558 assert(Member->getType()->isRecordType() &&
1559 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001560
Richard Smith9138b4e2011-10-26 19:06:56 +00001561 BaseResult =
1562 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001563 QualifierLoc.getNestedNameSpecifier(),
1564 FoundDecl, Member);
1565 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001566 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001567 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001568 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001569 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001570 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001571 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001572 cast<FieldDecl>(Member)->getType(),
1573 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001574 return getSema().Owned(ME);
1575 }
Mike Stump1eb44332009-09-09 15:08:12 +00001576
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001577 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001578 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001579
John Wiegley429bb272011-04-08 18:41:53 +00001580 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001581 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001582
John McCall6bb80172010-03-30 21:47:33 +00001583 // FIXME: this involves duplicating earlier analysis in a lot of
1584 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001585 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001586 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001587 R.resolveKind();
1588
John McCall9ae2f072010-08-23 23:25:46 +00001589 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001590 SS, TemplateKWLoc,
1591 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001592 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001593 }
Mike Stump1eb44332009-09-09 15:08:12 +00001594
Douglas Gregorb98b1992009-08-11 05:31:07 +00001595 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001596 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001597 /// By default, performs semantic analysis to build the new expression.
1598 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001599 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001600 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001601 Expr *LHS, Expr *RHS) {
1602 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001603 }
1604
1605 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001606 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001607 /// By default, performs semantic analysis to build the new expression.
1608 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001609 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001610 SourceLocation QuestionLoc,
1611 Expr *LHS,
1612 SourceLocation ColonLoc,
1613 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001614 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1615 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001616 }
1617
Douglas Gregorb98b1992009-08-11 05:31:07 +00001618 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001619 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001620 /// By default, performs semantic analysis to build the new expression.
1621 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001622 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001623 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001624 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001625 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001626 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001627 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001628 }
Mike Stump1eb44332009-09-09 15:08:12 +00001629
Douglas Gregorb98b1992009-08-11 05:31:07 +00001630 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001631 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001632 /// By default, performs semantic analysis to build the new expression.
1633 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001634 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001635 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001636 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001637 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001638 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001639 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001640 }
Mike Stump1eb44332009-09-09 15:08:12 +00001641
Douglas Gregorb98b1992009-08-11 05:31:07 +00001642 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001643 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001644 /// By default, performs semantic analysis to build the new expression.
1645 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001646 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001647 SourceLocation OpLoc,
1648 SourceLocation AccessorLoc,
1649 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001650
John McCall129e2df2009-11-30 22:42:35 +00001651 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001652 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001653 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001654 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001655 SS, SourceLocation(),
1656 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001657 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001658 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001659 }
Mike Stump1eb44332009-09-09 15:08:12 +00001660
Douglas Gregorb98b1992009-08-11 05:31:07 +00001661 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001662 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001663 /// By default, performs semantic analysis to build the new expression.
1664 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001665 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001666 MultiExprArg Inits,
1667 SourceLocation RBraceLoc,
1668 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001669 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001670 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001671 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001672 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001673
Douglas Gregore48319a2009-11-09 17:16:50 +00001674 // Patch in the result type we were given, which may have been computed
1675 // when the initial InitListExpr was built.
1676 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1677 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001678 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001679 }
Mike Stump1eb44332009-09-09 15:08:12 +00001680
Douglas Gregorb98b1992009-08-11 05:31:07 +00001681 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001682 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001683 /// By default, performs semantic analysis to build the new expression.
1684 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001685 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001686 MultiExprArg ArrayExprs,
1687 SourceLocation EqualOrColonLoc,
1688 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001689 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001690 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001691 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001692 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001693 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001694 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001695
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001696 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001697 }
Mike Stump1eb44332009-09-09 15:08:12 +00001698
Douglas Gregorb98b1992009-08-11 05:31:07 +00001699 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001700 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001701 /// By default, builds the implicit value initialization without performing
1702 /// any semantic analysis. Subclasses may override this routine to provide
1703 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001704 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001705 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1706 }
Mike Stump1eb44332009-09-09 15:08:12 +00001707
Douglas Gregorb98b1992009-08-11 05:31:07 +00001708 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001709 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 /// By default, performs semantic analysis to build the new expression.
1711 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001712 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001713 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001714 SourceLocation RParenLoc) {
1715 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001716 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001717 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 }
1719
1720 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001721 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001722 /// By default, performs semantic analysis to build the new expression.
1723 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001724 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001725 MultiExprArg SubExprs,
1726 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001727 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001728 }
Mike Stump1eb44332009-09-09 15:08:12 +00001729
Douglas Gregorb98b1992009-08-11 05:31:07 +00001730 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001731 ///
1732 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001733 /// rather than attempting to map the label statement itself.
1734 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001735 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001736 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001737 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001738 }
Mike Stump1eb44332009-09-09 15:08:12 +00001739
Douglas Gregorb98b1992009-08-11 05:31:07 +00001740 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001741 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001742 /// By default, performs semantic analysis to build the new expression.
1743 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001744 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001745 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001746 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001747 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001748 }
Mike Stump1eb44332009-09-09 15:08:12 +00001749
Douglas Gregorb98b1992009-08-11 05:31:07 +00001750 /// \brief Build a new __builtin_choose_expr expression.
1751 ///
1752 /// By default, performs semantic analysis to build the new expression.
1753 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001754 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001755 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001756 SourceLocation RParenLoc) {
1757 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001758 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001759 RParenLoc);
1760 }
Mike Stump1eb44332009-09-09 15:08:12 +00001761
Peter Collingbournef111d932011-04-15 00:35:48 +00001762 /// \brief Build a new generic selection expression.
1763 ///
1764 /// By default, performs semantic analysis to build the new expression.
1765 /// Subclasses may override this routine to provide different behavior.
1766 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1767 SourceLocation DefaultLoc,
1768 SourceLocation RParenLoc,
1769 Expr *ControllingExpr,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001770 ArrayRef<TypeSourceInfo *> Types,
1771 ArrayRef<Expr *> Exprs) {
Peter Collingbournef111d932011-04-15 00:35:48 +00001772 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko80613222013-05-10 13:06:58 +00001773 ControllingExpr, Types, Exprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00001774 }
1775
Douglas Gregorb98b1992009-08-11 05:31:07 +00001776 /// \brief Build a new overloaded operator call expression.
1777 ///
1778 /// By default, performs semantic analysis to build the new expression.
1779 /// The semantic analysis provides the behavior of template instantiation,
1780 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001781 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001782 /// argument-dependent lookup, etc. Subclasses may override this routine to
1783 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001784 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001785 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001786 Expr *Callee,
1787 Expr *First,
1788 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001789
1790 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791 /// reinterpret_cast.
1792 ///
1793 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001794 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001795 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001796 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001797 Stmt::StmtClass Class,
1798 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001799 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001800 SourceLocation RAngleLoc,
1801 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001802 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001803 SourceLocation RParenLoc) {
1804 switch (Class) {
1805 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001806 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001807 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001808 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001809
1810 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001811 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001812 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001813 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001814
Douglas Gregorb98b1992009-08-11 05:31:07 +00001815 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001816 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001817 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001818 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001819 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001820
Douglas Gregorb98b1992009-08-11 05:31:07 +00001821 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001822 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001823 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001824 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001825
Douglas Gregorb98b1992009-08-11 05:31:07 +00001826 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001827 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001828 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001829 }
Mike Stump1eb44332009-09-09 15:08:12 +00001830
Douglas Gregorb98b1992009-08-11 05:31:07 +00001831 /// \brief Build a new C++ static_cast expression.
1832 ///
1833 /// By default, performs semantic analysis to build the new expression.
1834 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001835 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001836 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001837 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001838 SourceLocation RAngleLoc,
1839 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001840 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001841 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001842 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001843 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001844 SourceRange(LAngleLoc, RAngleLoc),
1845 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001846 }
1847
1848 /// \brief Build a new C++ dynamic_cast expression.
1849 ///
1850 /// By default, performs semantic analysis to build the new expression.
1851 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001852 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001853 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001854 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001855 SourceLocation RAngleLoc,
1856 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001857 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001858 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001859 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001860 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001861 SourceRange(LAngleLoc, RAngleLoc),
1862 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001863 }
1864
1865 /// \brief Build a new C++ reinterpret_cast expression.
1866 ///
1867 /// By default, performs semantic analysis to build the new expression.
1868 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001869 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001870 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001871 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001872 SourceLocation RAngleLoc,
1873 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001874 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001875 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001876 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001877 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001878 SourceRange(LAngleLoc, RAngleLoc),
1879 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001880 }
1881
1882 /// \brief Build a new C++ const_cast expression.
1883 ///
1884 /// By default, performs semantic analysis to build the new expression.
1885 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001886 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001887 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001888 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001889 SourceLocation RAngleLoc,
1890 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001891 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001892 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001893 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001894 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001895 SourceRange(LAngleLoc, RAngleLoc),
1896 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001897 }
Mike Stump1eb44332009-09-09 15:08:12 +00001898
Douglas Gregorb98b1992009-08-11 05:31:07 +00001899 /// \brief Build a new C++ functional-style cast expression.
1900 ///
1901 /// By default, performs semantic analysis to build the new expression.
1902 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001903 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1904 SourceLocation LParenLoc,
1905 Expr *Sub,
1906 SourceLocation RParenLoc) {
1907 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001908 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001909 RParenLoc);
1910 }
Mike Stump1eb44332009-09-09 15:08:12 +00001911
Douglas Gregorb98b1992009-08-11 05:31:07 +00001912 /// \brief Build a new C++ typeid(type) expression.
1913 ///
1914 /// By default, performs semantic analysis to build the new expression.
1915 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001916 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001917 SourceLocation TypeidLoc,
1918 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001919 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001920 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001921 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001922 }
Mike Stump1eb44332009-09-09 15:08:12 +00001923
Francois Pichet01b7c302010-09-08 12:20:18 +00001924
Douglas Gregorb98b1992009-08-11 05:31:07 +00001925 /// \brief Build a new C++ typeid(expr) expression.
1926 ///
1927 /// By default, performs semantic analysis to build the new expression.
1928 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001929 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001930 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001931 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001932 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001933 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001934 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001935 }
1936
Francois Pichet01b7c302010-09-08 12:20:18 +00001937 /// \brief Build a new C++ __uuidof(type) expression.
1938 ///
1939 /// By default, performs semantic analysis to build the new expression.
1940 /// Subclasses may override this routine to provide different behavior.
1941 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1942 SourceLocation TypeidLoc,
1943 TypeSourceInfo *Operand,
1944 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001945 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00001946 RParenLoc);
1947 }
1948
1949 /// \brief Build a new C++ __uuidof(expr) expression.
1950 ///
1951 /// By default, performs semantic analysis to build the new expression.
1952 /// Subclasses may override this routine to provide different behavior.
1953 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1954 SourceLocation TypeidLoc,
1955 Expr *Operand,
1956 SourceLocation RParenLoc) {
1957 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1958 RParenLoc);
1959 }
1960
Douglas Gregorb98b1992009-08-11 05:31:07 +00001961 /// \brief Build a new C++ "this" expression.
1962 ///
1963 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001964 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001965 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001966 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001967 QualType ThisType,
1968 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001969 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001970 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001971 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1972 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001973 }
1974
1975 /// \brief Build a new C++ throw expression.
1976 ///
1977 /// By default, performs semantic analysis to build the new expression.
1978 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001979 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1980 bool IsThrownVariableInScope) {
1981 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001982 }
1983
1984 /// \brief Build a new C++ default-argument expression.
1985 ///
1986 /// By default, builds a new default-argument expression, which does not
1987 /// require any semantic analysis. Subclasses may override this routine to
1988 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001989 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001990 ParmVarDecl *Param) {
1991 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1992 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001993 }
1994
Richard Smithc3bf52c2013-04-20 22:23:05 +00001995 /// \brief Build a new C++11 default-initialization expression.
1996 ///
1997 /// By default, builds a new default field initialization expression, which
1998 /// does not require any semantic analysis. Subclasses may override this
1999 /// routine to provide different behavior.
2000 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2001 FieldDecl *Field) {
2002 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
2003 Field));
2004 }
2005
Douglas Gregorb98b1992009-08-11 05:31:07 +00002006 /// \brief Build a new C++ zero-initialization expression.
2007 ///
2008 /// By default, performs semantic analysis to build the new expression.
2009 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002010 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2011 SourceLocation LParenLoc,
2012 SourceLocation RParenLoc) {
2013 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002014 None, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002015 }
Mike Stump1eb44332009-09-09 15:08:12 +00002016
Douglas Gregorb98b1992009-08-11 05:31:07 +00002017 /// \brief Build a new C++ "new" expression.
2018 ///
2019 /// By default, performs semantic analysis to build the new expression.
2020 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002021 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002022 bool UseGlobal,
2023 SourceLocation PlacementLParen,
2024 MultiExprArg PlacementArgs,
2025 SourceLocation PlacementRParen,
2026 SourceRange TypeIdParens,
2027 QualType AllocatedType,
2028 TypeSourceInfo *AllocatedTypeInfo,
2029 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002030 SourceRange DirectInitRange,
2031 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00002032 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002033 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002034 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002035 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002036 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002037 AllocatedType,
2038 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002039 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002040 DirectInitRange,
2041 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002042 }
Mike Stump1eb44332009-09-09 15:08:12 +00002043
Douglas Gregorb98b1992009-08-11 05:31:07 +00002044 /// \brief Build a new C++ "delete" expression.
2045 ///
2046 /// By default, performs semantic analysis to build the new expression.
2047 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002048 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002049 bool IsGlobalDelete,
2050 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002051 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002052 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002053 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002054 }
Mike Stump1eb44332009-09-09 15:08:12 +00002055
Douglas Gregorb98b1992009-08-11 05:31:07 +00002056 /// \brief Build a new unary type trait expression.
2057 ///
2058 /// By default, performs semantic analysis to build the new expression.
2059 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002060 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002061 SourceLocation StartLoc,
2062 TypeSourceInfo *T,
2063 SourceLocation RParenLoc) {
2064 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002065 }
2066
Francois Pichet6ad6f282010-12-07 00:08:36 +00002067 /// \brief Build a new binary type trait expression.
2068 ///
2069 /// By default, performs semantic analysis to build the new expression.
2070 /// Subclasses may override this routine to provide different behavior.
2071 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2072 SourceLocation StartLoc,
2073 TypeSourceInfo *LhsT,
2074 TypeSourceInfo *RhsT,
2075 SourceLocation RParenLoc) {
2076 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2077 }
2078
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002079 /// \brief Build a new type trait expression.
2080 ///
2081 /// By default, performs semantic analysis to build the new expression.
2082 /// Subclasses may override this routine to provide different behavior.
2083 ExprResult RebuildTypeTrait(TypeTrait Trait,
2084 SourceLocation StartLoc,
2085 ArrayRef<TypeSourceInfo *> Args,
2086 SourceLocation RParenLoc) {
2087 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2088 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002089
John Wiegley21ff2e52011-04-28 00:16:57 +00002090 /// \brief Build a new array type trait expression.
2091 ///
2092 /// By default, performs semantic analysis to build the new expression.
2093 /// Subclasses may override this routine to provide different behavior.
2094 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2095 SourceLocation StartLoc,
2096 TypeSourceInfo *TSInfo,
2097 Expr *DimExpr,
2098 SourceLocation RParenLoc) {
2099 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2100 }
2101
John Wiegley55262202011-04-25 06:54:41 +00002102 /// \brief Build a new expression trait expression.
2103 ///
2104 /// By default, performs semantic analysis to build the new expression.
2105 /// Subclasses may override this routine to provide different behavior.
2106 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2107 SourceLocation StartLoc,
2108 Expr *Queried,
2109 SourceLocation RParenLoc) {
2110 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2111 }
2112
Mike Stump1eb44332009-09-09 15:08:12 +00002113 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002114 /// expression.
2115 ///
2116 /// By default, performs semantic analysis to build the new expression.
2117 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002118 ExprResult RebuildDependentScopeDeclRefExpr(
2119 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002120 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002121 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002122 const TemplateArgumentListInfo *TemplateArgs,
2123 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002124 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002125 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002126
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002127 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002128 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002129 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002130
Richard Smithefeeccf2012-10-21 03:28:35 +00002131 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2132 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002133 }
2134
2135 /// \brief Build a new template-id expression.
2136 ///
2137 /// By default, performs semantic analysis to build the new expression.
2138 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002139 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002140 SourceLocation TemplateKWLoc,
2141 LookupResult &R,
2142 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002143 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002144 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2145 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002146 }
2147
2148 /// \brief Build a new object-construction expression.
2149 ///
2150 /// By default, performs semantic analysis to build the new expression.
2151 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002152 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002153 SourceLocation Loc,
2154 CXXConstructorDecl *Constructor,
2155 bool IsElidable,
2156 MultiExprArg Args,
2157 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002158 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002159 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002160 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002161 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002162 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002163 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002164 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002165 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002166
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002167 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002168 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002169 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002170 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002171 RequiresZeroInit, ConstructKind,
2172 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002173 }
2174
2175 /// \brief Build a new object-construction expression.
2176 ///
2177 /// By default, performs semantic analysis to build the new expression.
2178 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002179 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2180 SourceLocation LParenLoc,
2181 MultiExprArg Args,
2182 SourceLocation RParenLoc) {
2183 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002184 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002185 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002186 RParenLoc);
2187 }
2188
2189 /// \brief Build a new object-construction expression.
2190 ///
2191 /// By default, performs semantic analysis to build the new expression.
2192 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002193 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2194 SourceLocation LParenLoc,
2195 MultiExprArg Args,
2196 SourceLocation RParenLoc) {
2197 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002198 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002199 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002200 RParenLoc);
2201 }
Mike Stump1eb44332009-09-09 15:08:12 +00002202
Douglas Gregorb98b1992009-08-11 05:31:07 +00002203 /// \brief Build a new member reference expression.
2204 ///
2205 /// By default, performs semantic analysis to build the new expression.
2206 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002207 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002208 QualType BaseType,
2209 bool IsArrow,
2210 SourceLocation OperatorLoc,
2211 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002212 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002213 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002214 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002215 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002216 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002217 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002218
John McCall9ae2f072010-08-23 23:25:46 +00002219 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002220 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002221 SS, TemplateKWLoc,
2222 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002223 MemberNameInfo,
2224 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002225 }
2226
John McCall129e2df2009-11-30 22:42:35 +00002227 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002228 ///
2229 /// By default, performs semantic analysis to build the new expression.
2230 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002231 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2232 SourceLocation OperatorLoc,
2233 bool IsArrow,
2234 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002235 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002236 NamedDecl *FirstQualifierInScope,
2237 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002238 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002239 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002240 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002241
John McCall9ae2f072010-08-23 23:25:46 +00002242 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002243 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002244 SS, TemplateKWLoc,
2245 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002246 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002247 }
Mike Stump1eb44332009-09-09 15:08:12 +00002248
Sebastian Redl2e156222010-09-10 20:55:43 +00002249 /// \brief Build a new noexcept expression.
2250 ///
2251 /// By default, performs semantic analysis to build the new expression.
2252 /// Subclasses may override this routine to provide different behavior.
2253 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2254 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2255 }
2256
Douglas Gregoree8aff02011-01-04 17:33:58 +00002257 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002258 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2259 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002260 SourceLocation RParenLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002261 Optional<unsigned> Length) {
Douglas Gregor089e8932011-10-10 18:59:29 +00002262 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002263 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2264 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002265 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002266
2267 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2268 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002269 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002270 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002271
Patrick Beardeb382ec2012-04-19 00:25:12 +00002272 /// \brief Build a new Objective-C boxed expression.
2273 ///
2274 /// By default, performs semantic analysis to build the new expression.
2275 /// Subclasses may override this routine to provide different behavior.
2276 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2277 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2278 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002279
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002280 /// \brief Build a new Objective-C array literal.
2281 ///
2282 /// By default, performs semantic analysis to build the new expression.
2283 /// Subclasses may override this routine to provide different behavior.
2284 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2285 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002286 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002287 MultiExprArg(Elements, NumElements));
2288 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002289
2290 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002291 Expr *Base, Expr *Key,
2292 ObjCMethodDecl *getterMethod,
2293 ObjCMethodDecl *setterMethod) {
2294 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2295 getterMethod, setterMethod);
2296 }
2297
2298 /// \brief Build a new Objective-C dictionary literal.
2299 ///
2300 /// By default, performs semantic analysis to build the new expression.
2301 /// Subclasses may override this routine to provide different behavior.
2302 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2303 ObjCDictionaryElement *Elements,
2304 unsigned NumElements) {
2305 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2306 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002307
James Dennett699c9042012-06-15 07:13:21 +00002308 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002309 ///
2310 /// By default, performs semantic analysis to build the new expression.
2311 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002312 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002313 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002314 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002315 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002316 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002317 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002318
Douglas Gregor92e986e2010-04-22 16:44:27 +00002319 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002320 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002321 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002322 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002323 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002324 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002325 MultiExprArg Args,
2326 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002327 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2328 ReceiverTypeInfo->getType(),
2329 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002330 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002331 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002332 }
2333
2334 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002335 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002336 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002337 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002338 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002339 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002340 MultiExprArg Args,
2341 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002342 return SemaRef.BuildInstanceMessage(Receiver,
2343 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002344 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002345 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002346 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002347 }
2348
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002349 /// \brief Build a new Objective-C ivar reference expression.
2350 ///
2351 /// By default, performs semantic analysis to build the new expression.
2352 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002353 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002354 SourceLocation IvarLoc,
2355 bool IsArrow, bool IsFreeIvar) {
2356 // FIXME: We lose track of the IsFreeIvar bit.
2357 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002358 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002359 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2360 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002361 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002362 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002363 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002364 false);
John Wiegley429bb272011-04-08 18:41:53 +00002365 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002366 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002367
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002368 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002369 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002370
John Wiegley429bb272011-04-08 18:41:53 +00002371 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002372 /*FIXME:*/IvarLoc, IsArrow,
2373 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002374 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002375 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002376 /*TemplateArgs=*/0);
2377 }
Douglas Gregore3303542010-04-26 20:47:02 +00002378
2379 /// \brief Build a new Objective-C property reference expression.
2380 ///
2381 /// By default, performs semantic analysis to build the new expression.
2382 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002383 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002384 ObjCPropertyDecl *Property,
2385 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002386 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002387 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002388 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2389 Sema::LookupMemberName);
2390 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002391 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002392 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002393 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002394 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002395 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002396
Douglas Gregore3303542010-04-26 20:47:02 +00002397 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002398 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002399
John Wiegley429bb272011-04-08 18:41:53 +00002400 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002401 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002402 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002403 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002404 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002405 /*TemplateArgs=*/0);
2406 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002407
John McCall12f78a62010-12-02 01:19:52 +00002408 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002409 ///
2410 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002411 /// Subclasses may override this routine to provide different behavior.
2412 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2413 ObjCMethodDecl *Getter,
2414 ObjCMethodDecl *Setter,
2415 SourceLocation PropertyLoc) {
2416 // Since these expressions can only be value-dependent, we do not
2417 // need to perform semantic analysis again.
2418 return Owned(
2419 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2420 VK_LValue, OK_ObjCProperty,
2421 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002422 }
2423
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002424 /// \brief Build a new Objective-C "isa" expression.
2425 ///
2426 /// By default, performs semantic analysis to build the new expression.
2427 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002428 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002429 SourceLocation OpLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002430 bool IsArrow) {
2431 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002432 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002433 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2434 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002435 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002436 OpLoc,
John McCalld226f652010-08-21 09:40:31 +00002437 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002438 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002439 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002440
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002441 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002442 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002443
John Wiegley429bb272011-04-08 18:41:53 +00002444 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002445 OpLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002446 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002447 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002448 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002449 /*TemplateArgs=*/0);
2450 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002451
Douglas Gregorb98b1992009-08-11 05:31:07 +00002452 /// \brief Build a new shuffle vector expression.
2453 ///
2454 /// By default, performs semantic analysis to build the new expression.
2455 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002456 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002457 MultiExprArg SubExprs,
2458 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002459 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002460 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002461 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2462 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2463 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002464 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002465
Douglas Gregorb98b1992009-08-11 05:31:07 +00002466 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002467 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002468 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2469 SemaRef.Context.BuiltinFnTy,
2470 VK_RValue, BuiltinLoc);
2471 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2472 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2473 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002474
2475 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002476 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002477 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002478 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002479 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002480 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002481
Douglas Gregorb98b1992009-08-11 05:31:07 +00002482 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002483 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002484 }
John McCall43fed0d2010-11-12 08:19:04 +00002485
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002486 /// \brief Build a new template argument pack expansion.
2487 ///
2488 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002489 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002490 /// different behavior.
2491 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002492 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002493 Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002494 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002495 case TemplateArgument::Expression: {
2496 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002497 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2498 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002499 if (Result.isInvalid())
2500 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002501
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002502 return TemplateArgumentLoc(Result.get(), Result.get());
2503 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002504
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002505 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002506 return TemplateArgumentLoc(TemplateArgument(
2507 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002508 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002509 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002510 Pattern.getTemplateNameLoc(),
2511 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002512
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002513 case TemplateArgument::Null:
2514 case TemplateArgument::Integral:
2515 case TemplateArgument::Declaration:
2516 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002517 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002518 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002519 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002520
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002521 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002522 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002523 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002524 EllipsisLoc,
2525 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002526 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2527 Expansion);
2528 break;
2529 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002530
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002531 return TemplateArgumentLoc();
2532 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002533
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002534 /// \brief Build a new expression pack expansion.
2535 ///
2536 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002537 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002538 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002539 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002540 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002541 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002542 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002543
2544 /// \brief Build a new atomic operation expression.
2545 ///
2546 /// By default, performs semantic analysis to build the new expression.
2547 /// Subclasses may override this routine to provide different behavior.
2548 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2549 MultiExprArg SubExprs,
2550 QualType RetTy,
2551 AtomicExpr::AtomicOp Op,
2552 SourceLocation RParenLoc) {
2553 // Just create the expression; there is not any interesting semantic
2554 // analysis here because we can't actually build an AtomicExpr until
2555 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002556 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002557 RParenLoc);
2558 }
2559
John McCall43fed0d2010-11-12 08:19:04 +00002560private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002561 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2562 QualType ObjectType,
2563 NamedDecl *FirstQualifierInScope,
2564 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002565
2566 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2567 QualType ObjectType,
2568 NamedDecl *FirstQualifierInScope,
2569 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002570};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002571
Douglas Gregor43959a92009-08-20 07:17:43 +00002572template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002573StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002574 if (!S)
2575 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002576
Douglas Gregor43959a92009-08-20 07:17:43 +00002577 switch (S->getStmtClass()) {
2578 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002579
Douglas Gregor43959a92009-08-20 07:17:43 +00002580 // Transform individual statement nodes
2581#define STMT(Node, Parent) \
2582 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002583#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002584#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002585#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002586
Douglas Gregor43959a92009-08-20 07:17:43 +00002587 // Transform expressions by calling TransformExpr.
2588#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002589#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002590#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002591#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002592 {
John McCall60d7b3a2010-08-24 06:29:42 +00002593 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002594 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002595 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002596
Richard Smith41956372013-01-14 22:39:08 +00002597 return getSema().ActOnExprStmt(E);
Douglas Gregor43959a92009-08-20 07:17:43 +00002598 }
Mike Stump1eb44332009-09-09 15:08:12 +00002599 }
2600
John McCall3fa5cae2010-10-26 07:05:15 +00002601 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002602}
Mike Stump1eb44332009-09-09 15:08:12 +00002603
2604
Douglas Gregor670444e2009-08-04 22:27:00 +00002605template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002606ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002607 if (!E)
2608 return SemaRef.Owned(E);
2609
2610 switch (E->getStmtClass()) {
2611 case Stmt::NoStmtClass: break;
2612#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002613#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002614#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002615 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002616#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002617 }
2618
John McCall3fa5cae2010-10-26 07:05:15 +00002619 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002620}
2621
2622template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002623ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2624 bool CXXDirectInit) {
2625 // Initializers are instantiated like expressions, except that various outer
2626 // layers are stripped.
2627 if (!Init)
2628 return SemaRef.Owned(Init);
2629
2630 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2631 Init = ExprTemp->getSubExpr();
2632
Richard Smith858c2c32013-05-30 22:40:16 +00002633 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
2634 Init = MTE->GetTemporaryExpr();
2635
Richard Smithc83c2302012-12-19 01:39:02 +00002636 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2637 Init = Binder->getSubExpr();
2638
2639 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2640 Init = ICE->getSubExprAsWritten();
2641
Richard Smith7c3e6152013-06-12 22:31:48 +00002642 if (CXXStdInitializerListExpr *ILE =
2643 dyn_cast<CXXStdInitializerListExpr>(Init))
2644 return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
2645
Richard Smith5cf15892012-12-21 08:13:35 +00002646 // If this is not a direct-initializer, we only need to reconstruct
2647 // InitListExprs. Other forms of copy-initialization will be a no-op if
2648 // the initializer is already the right type.
2649 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2650 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2651 return getDerived().TransformExpr(Init);
2652
2653 // Revert value-initialization back to empty parens.
2654 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2655 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002656 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002657 Parens.getEnd());
2658 }
2659
2660 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2661 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko62ed8892013-05-05 20:40:26 +00002662 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith5cf15892012-12-21 08:13:35 +00002663 SourceLocation());
2664
2665 // Revert initialization by constructor back to a parenthesized or braced list
2666 // of expressions. Any other form of initializer can just be reused directly.
2667 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002668 return getDerived().TransformExpr(Init);
2669
2670 SmallVector<Expr*, 8> NewArgs;
2671 bool ArgChanged = false;
2672 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2673 /*IsCall*/true, NewArgs, &ArgChanged))
2674 return ExprError();
2675
2676 // If this was list initialization, revert to list form.
2677 if (Construct->isListInitialization())
2678 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2679 Construct->getLocEnd(),
2680 Construct->getType());
2681
Richard Smithc83c2302012-12-19 01:39:02 +00002682 // Build a ParenListExpr to represent anything else.
2683 SourceRange Parens = Construct->getParenRange();
2684 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2685 Parens.getEnd());
2686}
2687
2688template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002689bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2690 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002691 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002692 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002693 bool *ArgChanged) {
2694 for (unsigned I = 0; I != NumInputs; ++I) {
2695 // If requested, drop call arguments that need to be dropped.
2696 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2697 if (ArgChanged)
2698 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002699
Douglas Gregoraa165f82011-01-03 19:04:46 +00002700 break;
2701 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002702
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002703 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2704 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002705
Chris Lattner686775d2011-07-20 06:58:45 +00002706 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002707 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2708 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002709
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002710 // Determine whether the set of unexpanded parameter packs can and should
2711 // be expanded.
2712 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002713 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00002714 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2715 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002716 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2717 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002718 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002719 Expand, RetainExpansion,
2720 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002721 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002722
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002723 if (!Expand) {
2724 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002725 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002726 // expansion.
2727 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2728 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2729 if (OutPattern.isInvalid())
2730 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002731
2732 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002733 Expansion->getEllipsisLoc(),
2734 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002735 if (Out.isInvalid())
2736 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002737
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002738 if (ArgChanged)
2739 *ArgChanged = true;
2740 Outputs.push_back(Out.get());
2741 continue;
2742 }
John McCallc8fc90a2011-07-06 07:30:07 +00002743
2744 // Record right away that the argument was changed. This needs
2745 // to happen even if the array expands to nothing.
2746 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002747
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002748 // The transform has determined that we should perform an elementwise
2749 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002750 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002751 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2752 ExprResult Out = getDerived().TransformExpr(Pattern);
2753 if (Out.isInvalid())
2754 return true;
2755
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002756 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002757 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2758 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002759 if (Out.isInvalid())
2760 return true;
2761 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002762
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002763 Outputs.push_back(Out.get());
2764 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002765
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002766 continue;
2767 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002768
Richard Smithc83c2302012-12-19 01:39:02 +00002769 ExprResult Result =
2770 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2771 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002772 if (Result.isInvalid())
2773 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002774
Douglas Gregoraa165f82011-01-03 19:04:46 +00002775 if (Result.get() != Inputs[I] && ArgChanged)
2776 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002777
2778 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002779 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002780
Douglas Gregoraa165f82011-01-03 19:04:46 +00002781 return false;
2782}
2783
2784template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002785NestedNameSpecifierLoc
2786TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2787 NestedNameSpecifierLoc NNS,
2788 QualType ObjectType,
2789 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002790 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002791 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002792 Qualifier = Qualifier.getPrefix())
2793 Qualifiers.push_back(Qualifier);
2794
2795 CXXScopeSpec SS;
2796 while (!Qualifiers.empty()) {
2797 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2798 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002799
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002800 switch (QNNS->getKind()) {
2801 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002802 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002803 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002804 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002805 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002806 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002807 FirstQualifierInScope, false))
2808 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002809
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002810 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002811
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002812 case NestedNameSpecifier::Namespace: {
2813 NamespaceDecl *NS
2814 = cast_or_null<NamespaceDecl>(
2815 getDerived().TransformDecl(
2816 Q.getLocalBeginLoc(),
2817 QNNS->getAsNamespace()));
2818 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2819 break;
2820 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002821
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002822 case NestedNameSpecifier::NamespaceAlias: {
2823 NamespaceAliasDecl *Alias
2824 = cast_or_null<NamespaceAliasDecl>(
2825 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2826 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002827 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002828 Q.getLocalEndLoc());
2829 break;
2830 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002831
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002832 case NestedNameSpecifier::Global:
2833 // There is no meaningful transformation that one could perform on the
2834 // global scope.
2835 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2836 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002837
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002838 case NestedNameSpecifier::TypeSpecWithTemplate:
2839 case NestedNameSpecifier::TypeSpec: {
2840 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2841 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002842
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002843 if (!TL)
2844 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002845
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002846 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002847 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002848 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002849 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002850 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002851 if (TL.getType()->isEnumeralType())
2852 SemaRef.Diag(TL.getBeginLoc(),
2853 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002854 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2855 Q.getLocalEndLoc());
2856 break;
2857 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002858 // If the nested-name-specifier is an invalid type def, don't emit an
2859 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002860 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2861 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002862 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002863 << TL.getType() << SS.getRange();
2864 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002865 return NestedNameSpecifierLoc();
2866 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002867 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002868
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002869 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002870 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002871 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002872 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002873
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002874 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002875 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002876 !getDerived().AlwaysRebuild())
2877 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002878
2879 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002880 // nested-name-specifier, do so.
2881 if (SS.location_size() == NNS.getDataLength() &&
2882 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2883 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2884
2885 // Allocate new nested-name-specifier location information.
2886 return SS.getWithLocInContext(SemaRef.Context);
2887}
2888
2889template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002890DeclarationNameInfo
2891TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002892::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002893 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002894 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002895 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002896
2897 switch (Name.getNameKind()) {
2898 case DeclarationName::Identifier:
2899 case DeclarationName::ObjCZeroArgSelector:
2900 case DeclarationName::ObjCOneArgSelector:
2901 case DeclarationName::ObjCMultiArgSelector:
2902 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002903 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002904 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002905 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002906
Douglas Gregor81499bb2009-09-03 22:13:48 +00002907 case DeclarationName::CXXConstructorName:
2908 case DeclarationName::CXXDestructorName:
2909 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002910 TypeSourceInfo *NewTInfo;
2911 CanQualType NewCanTy;
2912 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002913 NewTInfo = getDerived().TransformType(OldTInfo);
2914 if (!NewTInfo)
2915 return DeclarationNameInfo();
2916 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002917 }
2918 else {
2919 NewTInfo = 0;
2920 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002921 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002922 if (NewT.isNull())
2923 return DeclarationNameInfo();
2924 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2925 }
Mike Stump1eb44332009-09-09 15:08:12 +00002926
Abramo Bagnara25777432010-08-11 22:01:17 +00002927 DeclarationName NewName
2928 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2929 NewCanTy);
2930 DeclarationNameInfo NewNameInfo(NameInfo);
2931 NewNameInfo.setName(NewName);
2932 NewNameInfo.setNamedTypeInfo(NewTInfo);
2933 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002934 }
Mike Stump1eb44332009-09-09 15:08:12 +00002935 }
2936
David Blaikieb219cfc2011-09-23 05:06:16 +00002937 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002938}
2939
2940template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002941TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002942TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2943 TemplateName Name,
2944 SourceLocation NameLoc,
2945 QualType ObjectType,
2946 NamedDecl *FirstQualifierInScope) {
2947 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2948 TemplateDecl *Template = QTN->getTemplateDecl();
2949 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002950
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002951 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002952 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002953 Template));
2954 if (!TransTemplate)
2955 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002956
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002957 if (!getDerived().AlwaysRebuild() &&
2958 SS.getScopeRep() == QTN->getQualifier() &&
2959 TransTemplate == Template)
2960 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002961
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002962 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2963 TransTemplate);
2964 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002965
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002966 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2967 if (SS.getScopeRep()) {
2968 // These apply to the scope specifier, not the template.
2969 ObjectType = QualType();
2970 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002971 }
2972
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002973 if (!getDerived().AlwaysRebuild() &&
2974 SS.getScopeRep() == DTN->getQualifier() &&
2975 ObjectType.isNull())
2976 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002977
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002978 if (DTN->isIdentifier()) {
2979 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002980 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002981 NameLoc,
2982 ObjectType,
2983 FirstQualifierInScope);
2984 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002985
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002986 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2987 ObjectType);
2988 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002989
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002990 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2991 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002992 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002993 Template));
2994 if (!TransTemplate)
2995 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002996
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002997 if (!getDerived().AlwaysRebuild() &&
2998 TransTemplate == Template)
2999 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003000
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003001 return TemplateName(TransTemplate);
3002 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003003
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003004 if (SubstTemplateTemplateParmPackStorage *SubstPack
3005 = Name.getAsSubstTemplateTemplateParmPack()) {
3006 TemplateTemplateParmDecl *TransParam
3007 = cast_or_null<TemplateTemplateParmDecl>(
3008 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3009 if (!TransParam)
3010 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003011
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003012 if (!getDerived().AlwaysRebuild() &&
3013 TransParam == SubstPack->getParameterPack())
3014 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003015
3016 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003017 SubstPack->getArgumentPack());
3018 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003019
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003020 // These should be getting filtered out before they reach the AST.
3021 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003022}
3023
3024template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003025void TreeTransform<Derived>::InventTemplateArgumentLoc(
3026 const TemplateArgument &Arg,
3027 TemplateArgumentLoc &Output) {
3028 SourceLocation Loc = getDerived().getBaseLocation();
3029 switch (Arg.getKind()) {
3030 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003031 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00003032 break;
3033
3034 case TemplateArgument::Type:
3035 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00003036 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00003037
John McCall833ca992009-10-29 08:12:44 +00003038 break;
3039
Douglas Gregor788cd062009-11-11 01:00:40 +00003040 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003041 case TemplateArgument::TemplateExpansion: {
3042 NestedNameSpecifierLocBuilder Builder;
3043 TemplateName Template = Arg.getAsTemplate();
3044 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3045 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3046 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3047 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003048
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003049 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003050 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003051 Builder.getWithLocInContext(SemaRef.Context),
3052 Loc);
3053 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003054 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003055 Builder.getWithLocInContext(SemaRef.Context),
3056 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003057
Douglas Gregor788cd062009-11-11 01:00:40 +00003058 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003059 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003060
John McCall833ca992009-10-29 08:12:44 +00003061 case TemplateArgument::Expression:
3062 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3063 break;
3064
3065 case TemplateArgument::Declaration:
3066 case TemplateArgument::Integral:
3067 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003068 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003069 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003070 break;
3071 }
3072}
3073
3074template<typename Derived>
3075bool TreeTransform<Derived>::TransformTemplateArgument(
3076 const TemplateArgumentLoc &Input,
3077 TemplateArgumentLoc &Output) {
3078 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003079 switch (Arg.getKind()) {
3080 case TemplateArgument::Null:
3081 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003082 case TemplateArgument::Pack:
3083 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003084 case TemplateArgument::NullPtr:
3085 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003086
Douglas Gregor670444e2009-08-04 22:27:00 +00003087 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003088 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003089 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003090 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003091
3092 DI = getDerived().TransformType(DI);
3093 if (!DI) return true;
3094
3095 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3096 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003097 }
Mike Stump1eb44332009-09-09 15:08:12 +00003098
Douglas Gregor788cd062009-11-11 01:00:40 +00003099 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003100 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3101 if (QualifierLoc) {
3102 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3103 if (!QualifierLoc)
3104 return true;
3105 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003106
Douglas Gregor1d752d72011-03-02 18:46:51 +00003107 CXXScopeSpec SS;
3108 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003109 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003110 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3111 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003112 if (Template.isNull())
3113 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003114
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003115 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003116 Input.getTemplateNameLoc());
3117 return false;
3118 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003119
3120 case TemplateArgument::TemplateExpansion:
3121 llvm_unreachable("Caller should expand pack expansions");
3122
Douglas Gregor670444e2009-08-04 22:27:00 +00003123 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003124 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003125 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003126 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003127
John McCall833ca992009-10-29 08:12:44 +00003128 Expr *InputExpr = Input.getSourceExpression();
3129 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3130
Chris Lattner223de242011-04-25 20:37:58 +00003131 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003132 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003133 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003134 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003135 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003136 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003137 }
Mike Stump1eb44332009-09-09 15:08:12 +00003138
Douglas Gregor670444e2009-08-04 22:27:00 +00003139 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003140 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003141}
3142
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003143/// \brief Iterator adaptor that invents template argument location information
3144/// for each of the template arguments in its underlying iterator.
3145template<typename Derived, typename InputIterator>
3146class TemplateArgumentLocInventIterator {
3147 TreeTransform<Derived> &Self;
3148 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003149
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003150public:
3151 typedef TemplateArgumentLoc value_type;
3152 typedef TemplateArgumentLoc reference;
3153 typedef typename std::iterator_traits<InputIterator>::difference_type
3154 difference_type;
3155 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003156
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003157 class pointer {
3158 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003159
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003160 public:
3161 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003162
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003163 const TemplateArgumentLoc *operator->() const { return &Arg; }
3164 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003165
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003166 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003167
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003168 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3169 InputIterator Iter)
3170 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003171
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003172 TemplateArgumentLocInventIterator &operator++() {
3173 ++Iter;
3174 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003175 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003176
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003177 TemplateArgumentLocInventIterator operator++(int) {
3178 TemplateArgumentLocInventIterator Old(*this);
3179 ++(*this);
3180 return Old;
3181 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003182
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003183 reference operator*() const {
3184 TemplateArgumentLoc Result;
3185 Self.InventTemplateArgumentLoc(*Iter, Result);
3186 return Result;
3187 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003188
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003189 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003190
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003191 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3192 const TemplateArgumentLocInventIterator &Y) {
3193 return X.Iter == Y.Iter;
3194 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003195
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003196 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3197 const TemplateArgumentLocInventIterator &Y) {
3198 return X.Iter != Y.Iter;
3199 }
3200};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003201
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003202template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003203template<typename InputIterator>
3204bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3205 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003206 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003207 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003208 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003209 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003210
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003211 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3212 // Unpack argument packs, which we translate them into separate
3213 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003214 // FIXME: We could do much better if we could guarantee that the
3215 // TemplateArgumentLocInfo for the pack expansion would be usable for
3216 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003217 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003218 TemplateArgument::pack_iterator>
3219 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003220 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003221 In.getArgument().pack_begin()),
3222 PackLocIterator(*this,
3223 In.getArgument().pack_end()),
3224 Outputs))
3225 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003226
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003227 continue;
3228 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003229
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003230 if (In.getArgument().isPackExpansion()) {
3231 // We have a pack expansion, for which we will be substituting into
3232 // the pattern.
3233 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003234 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003235 TemplateArgumentLoc Pattern
Eli Friedman850cf512013-06-20 04:11:21 +00003236 = getSema().getTemplateArgumentPackExpansionPattern(
3237 In, Ellipsis, OrigNumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003238
Chris Lattner686775d2011-07-20 06:58:45 +00003239 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003240 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3241 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003242
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003243 // Determine whether the set of unexpanded parameter packs can and should
3244 // be expanded.
3245 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003246 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003247 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003248 if (getDerived().TryExpandParameterPacks(Ellipsis,
3249 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003250 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003251 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003252 RetainExpansion,
3253 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003254 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003255
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003256 if (!Expand) {
3257 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003258 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003259 // expansion.
3260 TemplateArgumentLoc OutPattern;
3261 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3262 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3263 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003264
Douglas Gregorcded4f62011-01-14 17:04:44 +00003265 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3266 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003267 if (Out.getArgument().isNull())
3268 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003269
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003270 Outputs.addArgument(Out);
3271 continue;
3272 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003273
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003274 // The transform has determined that we should perform an elementwise
3275 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003276 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003277 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3278
3279 if (getDerived().TransformTemplateArgument(Pattern, Out))
3280 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003281
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003282 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003283 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3284 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003285 if (Out.getArgument().isNull())
3286 return true;
3287 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003288
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003289 Outputs.addArgument(Out);
3290 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003291
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003292 // If we're supposed to retain a pack expansion, do so by temporarily
3293 // forgetting the partially-substituted parameter pack.
3294 if (RetainExpansion) {
3295 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003296
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003297 if (getDerived().TransformTemplateArgument(Pattern, Out))
3298 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003299
Douglas Gregorcded4f62011-01-14 17:04:44 +00003300 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3301 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003302 if (Out.getArgument().isNull())
3303 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003304
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003305 Outputs.addArgument(Out);
3306 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003307
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003308 continue;
3309 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003310
3311 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003312 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003313 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003314
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003315 Outputs.addArgument(Out);
3316 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003317
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003318 return false;
3319
3320}
3321
Douglas Gregor577f75a2009-08-04 16:50:30 +00003322//===----------------------------------------------------------------------===//
3323// Type transformation
3324//===----------------------------------------------------------------------===//
3325
3326template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003327QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003328 if (getDerived().AlreadyTransformed(T))
3329 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003330
John McCalla2becad2009-10-21 00:40:46 +00003331 // Temporary workaround. All of these transformations should
3332 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003333 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3334 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003335
John McCall43fed0d2010-11-12 08:19:04 +00003336 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003337
John McCalla2becad2009-10-21 00:40:46 +00003338 if (!NewDI)
3339 return QualType();
3340
3341 return NewDI->getType();
3342}
3343
3344template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003345TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003346 // Refine the base location to the type's location.
3347 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3348 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003349 if (getDerived().AlreadyTransformed(DI->getType()))
3350 return DI;
3351
3352 TypeLocBuilder TLB;
3353
3354 TypeLoc TL = DI->getTypeLoc();
3355 TLB.reserve(TL.getFullDataSize());
3356
John McCall43fed0d2010-11-12 08:19:04 +00003357 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003358 if (Result.isNull())
3359 return 0;
3360
John McCalla93c9342009-12-07 02:54:59 +00003361 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003362}
3363
3364template<typename Derived>
3365QualType
John McCall43fed0d2010-11-12 08:19:04 +00003366TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003367 switch (T.getTypeLocClass()) {
3368#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003369#define TYPELOC(CLASS, PARENT) \
3370 case TypeLoc::CLASS: \
3371 return getDerived().Transform##CLASS##Type(TLB, \
3372 T.castAs<CLASS##TypeLoc>());
John McCalla2becad2009-10-21 00:40:46 +00003373#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003374 }
Mike Stump1eb44332009-09-09 15:08:12 +00003375
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003376 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003377}
3378
3379/// FIXME: By default, this routine adds type qualifiers only to types
3380/// that can have qualifiers, and silently suppresses those qualifiers
3381/// that are not permitted (e.g., qualifiers on reference or function
3382/// types). This is the right thing for template instantiation, but
3383/// probably not for other clients.
3384template<typename Derived>
3385QualType
3386TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003387 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003388 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003389
John McCall43fed0d2010-11-12 08:19:04 +00003390 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003391 if (Result.isNull())
3392 return QualType();
3393
3394 // Silently suppress qualifiers if the result type can't be qualified.
3395 // FIXME: this is the right thing for template instantiation, but
3396 // probably not for other clients.
3397 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003398 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003399
John McCallf85e1932011-06-15 23:02:42 +00003400 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003401 // resulting type.
3402 if (Quals.hasObjCLifetime()) {
3403 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3404 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003405 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003406 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003407 // A lifetime qualifier applied to a substituted template parameter
3408 // overrides the lifetime qualifier from the template argument.
Douglas Gregor92d13872013-01-17 23:59:28 +00003409 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003410 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003411 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3412 QualType Replacement = SubstTypeParam->getReplacementType();
3413 Qualifiers Qs = Replacement.getQualifiers();
3414 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003415 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003416 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3417 Qs);
3418 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003419 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003420 Replacement);
3421 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003422 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3423 // 'auto' types behave the same way as template parameters.
3424 QualType Deduced = AutoTy->getDeducedType();
3425 Qualifiers Qs = Deduced.getQualifiers();
3426 Qs.removeObjCLifetime();
3427 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3428 Qs);
Richard Smitha2c36462013-04-26 16:15:35 +00003429 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto());
Douglas Gregor92d13872013-01-17 23:59:28 +00003430 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003431 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003432 // Otherwise, complain about the addition of a qualifier to an
3433 // already-qualified type.
Eli Friedman44ee0a72013-06-07 20:31:48 +00003434 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003435 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003436 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003437
Douglas Gregore559ca12011-06-17 22:11:49 +00003438 Quals.removeObjCLifetime();
3439 }
3440 }
3441 }
John McCall28654742010-06-05 06:41:15 +00003442 if (!Quals.empty()) {
3443 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smith9807a2e2013-03-27 23:36:39 +00003444 // BuildQualifiedType might not add qualifiers if they are invalid.
3445 if (Result.hasLocalQualifiers())
3446 TLB.push<QualifiedTypeLoc>(Result);
John McCall28654742010-06-05 06:41:15 +00003447 // No location information to preserve.
3448 }
John McCalla2becad2009-10-21 00:40:46 +00003449
3450 return Result;
3451}
3452
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003453template<typename Derived>
3454TypeLoc
3455TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3456 QualType ObjectType,
3457 NamedDecl *UnqualLookup,
3458 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003459 QualType T = TL.getType();
3460 if (getDerived().AlreadyTransformed(T))
3461 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003462
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003463 TypeLocBuilder TLB;
3464 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003465
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003466 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003467 TemplateSpecializationTypeLoc SpecTL =
3468 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003469
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003470 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003471 getDerived().TransformTemplateName(SS,
3472 SpecTL.getTypePtr()->getTemplateName(),
3473 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003474 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003475 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003476 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003477
3478 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003479 Template);
3480 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003481 DependentTemplateSpecializationTypeLoc SpecTL =
3482 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003483
Douglas Gregora88f09f2011-02-28 17:23:35 +00003484 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003485 = getDerived().RebuildTemplateName(SS,
3486 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003487 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003488 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003489 if (Template.isNull())
3490 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003491
3492 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003493 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003494 Template,
3495 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003496 } else {
3497 // Nothing special needs to be done for these.
3498 Result = getDerived().TransformType(TLB, TL);
3499 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003500
3501 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003502 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003503
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003504 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3505}
3506
Douglas Gregorb71d8212011-03-02 18:32:08 +00003507template<typename Derived>
3508TypeSourceInfo *
3509TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3510 QualType ObjectType,
3511 NamedDecl *UnqualLookup,
3512 CXXScopeSpec &SS) {
3513 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003514
Douglas Gregorb71d8212011-03-02 18:32:08 +00003515 QualType T = TSInfo->getType();
3516 if (getDerived().AlreadyTransformed(T))
3517 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003518
Douglas Gregorb71d8212011-03-02 18:32:08 +00003519 TypeLocBuilder TLB;
3520 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003521
Douglas Gregorb71d8212011-03-02 18:32:08 +00003522 TypeLoc TL = TSInfo->getTypeLoc();
3523 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003524 TemplateSpecializationTypeLoc SpecTL =
3525 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003526
Douglas Gregorb71d8212011-03-02 18:32:08 +00003527 TemplateName Template
3528 = getDerived().TransformTemplateName(SS,
3529 SpecTL.getTypePtr()->getTemplateName(),
3530 SpecTL.getTemplateNameLoc(),
3531 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003532 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003533 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003534
3535 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003536 Template);
3537 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003538 DependentTemplateSpecializationTypeLoc SpecTL =
3539 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003540
Douglas Gregorb71d8212011-03-02 18:32:08 +00003541 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003542 = getDerived().RebuildTemplateName(SS,
3543 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003544 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003545 ObjectType, UnqualLookup);
3546 if (Template.isNull())
3547 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003548
3549 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003550 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003551 Template,
3552 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003553 } else {
3554 // Nothing special needs to be done for these.
3555 Result = getDerived().TransformType(TLB, TL);
3556 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003557
3558 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003559 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003560
Douglas Gregorb71d8212011-03-02 18:32:08 +00003561 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3562}
3563
John McCalla2becad2009-10-21 00:40:46 +00003564template <class TyLoc> static inline
3565QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3566 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3567 NewT.setNameLoc(T.getNameLoc());
3568 return T.getType();
3569}
3570
John McCalla2becad2009-10-21 00:40:46 +00003571template<typename Derived>
3572QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003573 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003574 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3575 NewT.setBuiltinLoc(T.getBuiltinLoc());
3576 if (T.needsExtraLocalData())
3577 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3578 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003579}
Mike Stump1eb44332009-09-09 15:08:12 +00003580
Douglas Gregor577f75a2009-08-04 16:50:30 +00003581template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003582QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003583 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003584 // FIXME: recurse?
3585 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003586}
Mike Stump1eb44332009-09-09 15:08:12 +00003587
Douglas Gregor577f75a2009-08-04 16:50:30 +00003588template<typename Derived>
Reid Kleckner12df2462013-06-24 17:51:48 +00003589QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3590 DecayedTypeLoc TL) {
3591 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3592 if (OriginalType.isNull())
3593 return QualType();
3594
3595 QualType Result = TL.getType();
3596 if (getDerived().AlwaysRebuild() ||
3597 OriginalType != TL.getOriginalLoc().getType())
3598 Result = SemaRef.Context.getDecayedType(OriginalType);
3599 TLB.push<DecayedTypeLoc>(Result);
3600 // Nothing to set for DecayedTypeLoc.
3601 return Result;
3602}
3603
3604template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003605QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003606 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003607 QualType PointeeType
3608 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003609 if (PointeeType.isNull())
3610 return QualType();
3611
3612 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003613 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003614 // A dependent pointer type 'T *' has is being transformed such
3615 // that an Objective-C class type is being replaced for 'T'. The
3616 // resulting pointer type is an ObjCObjectPointerType, not a
3617 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003618 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003619
John McCallc12c5bb2010-05-15 11:32:37 +00003620 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3621 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003622 return Result;
3623 }
John McCall43fed0d2010-11-12 08:19:04 +00003624
Douglas Gregor92e986e2010-04-22 16:44:27 +00003625 if (getDerived().AlwaysRebuild() ||
3626 PointeeType != TL.getPointeeLoc().getType()) {
3627 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3628 if (Result.isNull())
3629 return QualType();
3630 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003631
John McCallf85e1932011-06-15 23:02:42 +00003632 // Objective-C ARC can add lifetime qualifiers to the type that we're
3633 // pointing to.
3634 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003635
Douglas Gregor92e986e2010-04-22 16:44:27 +00003636 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3637 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003638 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003639}
Mike Stump1eb44332009-09-09 15:08:12 +00003640
3641template<typename Derived>
3642QualType
John McCalla2becad2009-10-21 00:40:46 +00003643TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003644 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003645 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003646 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3647 if (PointeeType.isNull())
3648 return QualType();
3649
3650 QualType Result = TL.getType();
3651 if (getDerived().AlwaysRebuild() ||
3652 PointeeType != TL.getPointeeLoc().getType()) {
3653 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003654 TL.getSigilLoc());
3655 if (Result.isNull())
3656 return QualType();
3657 }
3658
Douglas Gregor39968ad2010-04-22 16:50:51 +00003659 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003660 NewT.setSigilLoc(TL.getSigilLoc());
3661 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003662}
3663
John McCall85737a72009-10-30 00:06:24 +00003664/// Transforms a reference type. Note that somewhat paradoxically we
3665/// don't care whether the type itself is an l-value type or an r-value
3666/// type; we only care if the type was *written* as an l-value type
3667/// or an r-value type.
3668template<typename Derived>
3669QualType
3670TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003671 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003672 const ReferenceType *T = TL.getTypePtr();
3673
3674 // Note that this works with the pointee-as-written.
3675 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3676 if (PointeeType.isNull())
3677 return QualType();
3678
3679 QualType Result = TL.getType();
3680 if (getDerived().AlwaysRebuild() ||
3681 PointeeType != T->getPointeeTypeAsWritten()) {
3682 Result = getDerived().RebuildReferenceType(PointeeType,
3683 T->isSpelledAsLValue(),
3684 TL.getSigilLoc());
3685 if (Result.isNull())
3686 return QualType();
3687 }
3688
John McCallf85e1932011-06-15 23:02:42 +00003689 // Objective-C ARC can add lifetime qualifiers to the type that we're
3690 // referring to.
3691 TLB.TypeWasModifiedSafely(
3692 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3693
John McCall85737a72009-10-30 00:06:24 +00003694 // r-value references can be rebuilt as l-value references.
3695 ReferenceTypeLoc NewTL;
3696 if (isa<LValueReferenceType>(Result))
3697 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3698 else
3699 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3700 NewTL.setSigilLoc(TL.getSigilLoc());
3701
3702 return Result;
3703}
3704
Mike Stump1eb44332009-09-09 15:08:12 +00003705template<typename Derived>
3706QualType
John McCalla2becad2009-10-21 00:40:46 +00003707TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003708 LValueReferenceTypeLoc TL) {
3709 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003710}
3711
Mike Stump1eb44332009-09-09 15:08:12 +00003712template<typename Derived>
3713QualType
John McCalla2becad2009-10-21 00:40:46 +00003714TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003715 RValueReferenceTypeLoc TL) {
3716 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003717}
Mike Stump1eb44332009-09-09 15:08:12 +00003718
Douglas Gregor577f75a2009-08-04 16:50:30 +00003719template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003720QualType
John McCalla2becad2009-10-21 00:40:46 +00003721TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003722 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003723 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003724 if (PointeeType.isNull())
3725 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003726
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003727 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3728 TypeSourceInfo* NewClsTInfo = 0;
3729 if (OldClsTInfo) {
3730 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3731 if (!NewClsTInfo)
3732 return QualType();
3733 }
3734
3735 const MemberPointerType *T = TL.getTypePtr();
3736 QualType OldClsType = QualType(T->getClass(), 0);
3737 QualType NewClsType;
3738 if (NewClsTInfo)
3739 NewClsType = NewClsTInfo->getType();
3740 else {
3741 NewClsType = getDerived().TransformType(OldClsType);
3742 if (NewClsType.isNull())
3743 return QualType();
3744 }
Mike Stump1eb44332009-09-09 15:08:12 +00003745
John McCalla2becad2009-10-21 00:40:46 +00003746 QualType Result = TL.getType();
3747 if (getDerived().AlwaysRebuild() ||
3748 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003749 NewClsType != OldClsType) {
3750 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003751 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003752 if (Result.isNull())
3753 return QualType();
3754 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003755
John McCalla2becad2009-10-21 00:40:46 +00003756 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3757 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003758 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003759
3760 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003761}
3762
Mike Stump1eb44332009-09-09 15:08:12 +00003763template<typename Derived>
3764QualType
John McCalla2becad2009-10-21 00:40:46 +00003765TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003766 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003767 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003768 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003769 if (ElementType.isNull())
3770 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003771
John McCalla2becad2009-10-21 00:40:46 +00003772 QualType Result = TL.getType();
3773 if (getDerived().AlwaysRebuild() ||
3774 ElementType != T->getElementType()) {
3775 Result = getDerived().RebuildConstantArrayType(ElementType,
3776 T->getSizeModifier(),
3777 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003778 T->getIndexTypeCVRQualifiers(),
3779 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003780 if (Result.isNull())
3781 return QualType();
3782 }
Eli Friedman457a3772012-01-25 22:19:07 +00003783
3784 // We might have either a ConstantArrayType or a VariableArrayType now:
3785 // a ConstantArrayType is allowed to have an element type which is a
3786 // VariableArrayType if the type is dependent. Fortunately, all array
3787 // types have the same location layout.
3788 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003789 NewTL.setLBracketLoc(TL.getLBracketLoc());
3790 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003791
John McCalla2becad2009-10-21 00:40:46 +00003792 Expr *Size = TL.getSizeExpr();
3793 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003794 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3795 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003796 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003797 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003798 }
3799 NewTL.setSizeExpr(Size);
3800
3801 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003802}
Mike Stump1eb44332009-09-09 15:08:12 +00003803
Douglas Gregor577f75a2009-08-04 16:50:30 +00003804template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003805QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003806 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003807 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003808 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003809 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003810 if (ElementType.isNull())
3811 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003812
John McCalla2becad2009-10-21 00:40:46 +00003813 QualType Result = TL.getType();
3814 if (getDerived().AlwaysRebuild() ||
3815 ElementType != T->getElementType()) {
3816 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003817 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003818 T->getIndexTypeCVRQualifiers(),
3819 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003820 if (Result.isNull())
3821 return QualType();
3822 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003823
John McCalla2becad2009-10-21 00:40:46 +00003824 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3825 NewTL.setLBracketLoc(TL.getLBracketLoc());
3826 NewTL.setRBracketLoc(TL.getRBracketLoc());
3827 NewTL.setSizeExpr(0);
3828
3829 return Result;
3830}
3831
3832template<typename Derived>
3833QualType
3834TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003835 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003836 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003837 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3838 if (ElementType.isNull())
3839 return QualType();
3840
John McCall60d7b3a2010-08-24 06:29:42 +00003841 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003842 = getDerived().TransformExpr(T->getSizeExpr());
3843 if (SizeResult.isInvalid())
3844 return QualType();
3845
John McCall9ae2f072010-08-23 23:25:46 +00003846 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003847
3848 QualType Result = TL.getType();
3849 if (getDerived().AlwaysRebuild() ||
3850 ElementType != T->getElementType() ||
3851 Size != T->getSizeExpr()) {
3852 Result = getDerived().RebuildVariableArrayType(ElementType,
3853 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003854 Size,
John McCalla2becad2009-10-21 00:40:46 +00003855 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003856 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003857 if (Result.isNull())
3858 return QualType();
3859 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003860
John McCalla2becad2009-10-21 00:40:46 +00003861 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3862 NewTL.setLBracketLoc(TL.getLBracketLoc());
3863 NewTL.setRBracketLoc(TL.getRBracketLoc());
3864 NewTL.setSizeExpr(Size);
3865
3866 return Result;
3867}
3868
3869template<typename Derived>
3870QualType
3871TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003872 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003873 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003874 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3875 if (ElementType.isNull())
3876 return QualType();
3877
Richard Smithf6702a32011-12-20 02:08:33 +00003878 // Array bounds are constant expressions.
3879 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3880 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003881
John McCall3b657512011-01-19 10:06:00 +00003882 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3883 Expr *origSize = TL.getSizeExpr();
3884 if (!origSize) origSize = T->getSizeExpr();
3885
3886 ExprResult sizeResult
3887 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003888 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003889 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003890 return QualType();
3891
John McCall3b657512011-01-19 10:06:00 +00003892 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003893
3894 QualType Result = TL.getType();
3895 if (getDerived().AlwaysRebuild() ||
3896 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003897 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003898 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3899 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003900 size,
John McCalla2becad2009-10-21 00:40:46 +00003901 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003902 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003903 if (Result.isNull())
3904 return QualType();
3905 }
John McCalla2becad2009-10-21 00:40:46 +00003906
3907 // We might have any sort of array type now, but fortunately they
3908 // all have the same location layout.
3909 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3910 NewTL.setLBracketLoc(TL.getLBracketLoc());
3911 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003912 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003913
3914 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003915}
Mike Stump1eb44332009-09-09 15:08:12 +00003916
3917template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003918QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003919 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003920 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003921 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003922
3923 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003924 QualType ElementType = getDerived().TransformType(T->getElementType());
3925 if (ElementType.isNull())
3926 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003927
Richard Smithf6702a32011-12-20 02:08:33 +00003928 // Vector sizes are constant expressions.
3929 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3930 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003931
John McCall60d7b3a2010-08-24 06:29:42 +00003932 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003933 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003934 if (Size.isInvalid())
3935 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003936
John McCalla2becad2009-10-21 00:40:46 +00003937 QualType Result = TL.getType();
3938 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003939 ElementType != T->getElementType() ||
3940 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003941 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003942 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003943 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003944 if (Result.isNull())
3945 return QualType();
3946 }
John McCalla2becad2009-10-21 00:40:46 +00003947
3948 // Result might be dependent or not.
3949 if (isa<DependentSizedExtVectorType>(Result)) {
3950 DependentSizedExtVectorTypeLoc NewTL
3951 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3952 NewTL.setNameLoc(TL.getNameLoc());
3953 } else {
3954 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3955 NewTL.setNameLoc(TL.getNameLoc());
3956 }
3957
3958 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003959}
Mike Stump1eb44332009-09-09 15:08:12 +00003960
3961template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003962QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003963 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003964 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003965 QualType ElementType = getDerived().TransformType(T->getElementType());
3966 if (ElementType.isNull())
3967 return QualType();
3968
John McCalla2becad2009-10-21 00:40:46 +00003969 QualType Result = TL.getType();
3970 if (getDerived().AlwaysRebuild() ||
3971 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003972 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003973 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003974 if (Result.isNull())
3975 return QualType();
3976 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003977
John McCalla2becad2009-10-21 00:40:46 +00003978 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3979 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003980
John McCalla2becad2009-10-21 00:40:46 +00003981 return Result;
3982}
3983
3984template<typename Derived>
3985QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003986 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003987 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003988 QualType ElementType = getDerived().TransformType(T->getElementType());
3989 if (ElementType.isNull())
3990 return QualType();
3991
3992 QualType Result = TL.getType();
3993 if (getDerived().AlwaysRebuild() ||
3994 ElementType != T->getElementType()) {
3995 Result = getDerived().RebuildExtVectorType(ElementType,
3996 T->getNumElements(),
3997 /*FIXME*/ SourceLocation());
3998 if (Result.isNull())
3999 return QualType();
4000 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004001
John McCalla2becad2009-10-21 00:40:46 +00004002 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4003 NewTL.setNameLoc(TL.getNameLoc());
4004
4005 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004006}
Mike Stump1eb44332009-09-09 15:08:12 +00004007
David Blaikiedc84cd52013-02-20 22:23:23 +00004008template <typename Derived>
4009ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4010 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4011 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00004012 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004013 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004014
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004015 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004016 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004017 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004018 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004019 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004020
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004021 TypeLocBuilder TLB;
4022 TypeLoc NewTL = OldDI->getTypeLoc();
4023 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004024
4025 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004026 OldExpansionTL.getPatternLoc());
4027 if (Result.isNull())
4028 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004029
4030 Result = RebuildPackExpansionType(Result,
4031 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004032 OldExpansionTL.getEllipsisLoc(),
4033 NumExpansions);
4034 if (Result.isNull())
4035 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004036
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004037 PackExpansionTypeLoc NewExpansionTL
4038 = TLB.push<PackExpansionTypeLoc>(Result);
4039 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4040 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4041 } else
4042 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00004043 if (!NewDI)
4044 return 0;
4045
John McCallfb44de92011-05-01 22:35:37 +00004046 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00004047 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00004048
4049 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4050 OldParm->getDeclContext(),
4051 OldParm->getInnerLocStart(),
4052 OldParm->getLocation(),
4053 OldParm->getIdentifier(),
4054 NewDI->getType(),
4055 NewDI,
4056 OldParm->getStorageClass(),
John McCallfb44de92011-05-01 22:35:37 +00004057 /* DefArg */ NULL);
4058 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4059 OldParm->getFunctionScopeIndex() + indexAdjustment);
4060 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004061}
4062
4063template<typename Derived>
4064bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004065 TransformFunctionTypeParams(SourceLocation Loc,
4066 ParmVarDecl **Params, unsigned NumParams,
4067 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004068 SmallVectorImpl<QualType> &OutParamTypes,
4069 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004070 int indexAdjustment = 0;
4071
Douglas Gregora009b592011-01-07 00:20:55 +00004072 for (unsigned i = 0; i != NumParams; ++i) {
4073 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004074 assert(OldParm->getFunctionScopeIndex() == i);
4075
David Blaikiedc84cd52013-02-20 22:23:23 +00004076 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004077 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004078 if (OldParm->isParameterPack()) {
4079 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004080 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004081
Douglas Gregor603cfb42011-01-05 23:12:31 +00004082 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004083 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004084 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004085 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4086 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004087 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4088
Douglas Gregor603cfb42011-01-05 23:12:31 +00004089 // Determine whether we should expand the parameter packs.
4090 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004091 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004092 Optional<unsigned> OrigNumExpansions =
4093 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004094 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004095 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4096 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004097 Unexpanded,
4098 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004099 RetainExpansion,
4100 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004101 return true;
4102 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004103
Douglas Gregor603cfb42011-01-05 23:12:31 +00004104 if (ShouldExpand) {
4105 // Expand the function parameter pack into multiple, separate
4106 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004107 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004108 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004109 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004110 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004111 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004112 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004113 OrigNumExpansions,
4114 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004115 if (!NewParm)
4116 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004117
Douglas Gregora009b592011-01-07 00:20:55 +00004118 OutParamTypes.push_back(NewParm->getType());
4119 if (PVars)
4120 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004121 }
Douglas Gregord3731192011-01-10 07:32:04 +00004122
4123 // If we're supposed to retain a pack expansion, do so by temporarily
4124 // forgetting the partially-substituted parameter pack.
4125 if (RetainExpansion) {
4126 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004127 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004128 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004129 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004130 OrigNumExpansions,
4131 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004132 if (!NewParm)
4133 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004134
Douglas Gregord3731192011-01-10 07:32:04 +00004135 OutParamTypes.push_back(NewParm->getType());
4136 if (PVars)
4137 PVars->push_back(NewParm);
4138 }
4139
John McCallfb44de92011-05-01 22:35:37 +00004140 // The next parameter should have the same adjustment as the
4141 // last thing we pushed, but we post-incremented indexAdjustment
4142 // on every push. Also, if we push nothing, the adjustment should
4143 // go down by one.
4144 indexAdjustment--;
4145
Douglas Gregor603cfb42011-01-05 23:12:31 +00004146 // We're done with the pack expansion.
4147 continue;
4148 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004149
4150 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004151 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004152 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4153 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004154 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004155 NumExpansions,
4156 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004157 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004158 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004159 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004160 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004161
John McCall21ef0fa2010-03-11 09:03:00 +00004162 if (!NewParm)
4163 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004164
Douglas Gregora009b592011-01-07 00:20:55 +00004165 OutParamTypes.push_back(NewParm->getType());
4166 if (PVars)
4167 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004168 continue;
4169 }
John McCall21ef0fa2010-03-11 09:03:00 +00004170
4171 // Deal with the possibility that we don't have a parameter
4172 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004173 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004174 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004175 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004176 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004177 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004178 = dyn_cast<PackExpansionType>(OldType)) {
4179 // We have a function parameter pack that may need to be expanded.
4180 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004181 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004182 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004183
Douglas Gregor603cfb42011-01-05 23:12:31 +00004184 // Determine whether we should expand the parameter packs.
4185 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004186 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004187 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004188 Unexpanded,
4189 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004190 RetainExpansion,
4191 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004192 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004193 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004194
Douglas Gregor603cfb42011-01-05 23:12:31 +00004195 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004196 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004197 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004198 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004199 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4200 QualType NewType = getDerived().TransformType(Pattern);
4201 if (NewType.isNull())
4202 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004203
Douglas Gregora009b592011-01-07 00:20:55 +00004204 OutParamTypes.push_back(NewType);
4205 if (PVars)
4206 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004207 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004208
Douglas Gregor603cfb42011-01-05 23:12:31 +00004209 // We're done with the pack expansion.
4210 continue;
4211 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004212
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004213 // If we're supposed to retain a pack expansion, do so by temporarily
4214 // forgetting the partially-substituted parameter pack.
4215 if (RetainExpansion) {
4216 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4217 QualType NewType = getDerived().TransformType(Pattern);
4218 if (NewType.isNull())
4219 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004220
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004221 OutParamTypes.push_back(NewType);
4222 if (PVars)
4223 PVars->push_back(0);
4224 }
Douglas Gregord3731192011-01-10 07:32:04 +00004225
Chad Rosier4a9d7952012-08-08 18:46:20 +00004226 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004227 // expansion.
4228 OldType = Expansion->getPattern();
4229 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004230 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4231 NewType = getDerived().TransformType(OldType);
4232 } else {
4233 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004234 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004235
Douglas Gregor603cfb42011-01-05 23:12:31 +00004236 if (NewType.isNull())
4237 return true;
4238
4239 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004240 NewType = getSema().Context.getPackExpansionType(NewType,
4241 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004242
Douglas Gregora009b592011-01-07 00:20:55 +00004243 OutParamTypes.push_back(NewType);
4244 if (PVars)
4245 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004246 }
4247
John McCallfb44de92011-05-01 22:35:37 +00004248#ifndef NDEBUG
4249 if (PVars) {
4250 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4251 if (ParmVarDecl *parm = (*PVars)[i])
4252 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004253 }
John McCallfb44de92011-05-01 22:35:37 +00004254#endif
4255
4256 return false;
4257}
John McCall21ef0fa2010-03-11 09:03:00 +00004258
4259template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004260QualType
John McCalla2becad2009-10-21 00:40:46 +00004261TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004262 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004263 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4264}
4265
4266template<typename Derived>
4267QualType
4268TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4269 FunctionProtoTypeLoc TL,
4270 CXXRecordDecl *ThisContext,
4271 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004272 // Transform the parameters and return type.
4273 //
Richard Smithe6975e92012-04-17 00:58:00 +00004274 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004275 // When the function has a trailing return type, we instantiate the
4276 // parameters before the return type, since the return type can then refer
4277 // to the parameters themselves (via decltype, sizeof, etc.).
4278 //
Chris Lattner686775d2011-07-20 06:58:45 +00004279 SmallVector<QualType, 4> ParamTypes;
4280 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004281 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004282
Douglas Gregordab60ad2010-10-01 18:44:50 +00004283 QualType ResultType;
4284
Richard Smith9fbf3272012-08-14 22:51:13 +00004285 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004286 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004287 TL.getParmArray(),
4288 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004289 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004290 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004291 return QualType();
4292
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004293 {
4294 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004295 // If a declaration declares a member function or member function
4296 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004297 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004298 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004299 // declarator.
4300 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004301
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004302 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4303 if (ResultType.isNull())
4304 return QualType();
4305 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004306 }
4307 else {
4308 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4309 if (ResultType.isNull())
4310 return QualType();
4311
Chad Rosier4a9d7952012-08-08 18:46:20 +00004312 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004313 TL.getParmArray(),
4314 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004315 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004316 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004317 return QualType();
4318 }
4319
Richard Smithe6975e92012-04-17 00:58:00 +00004320 // FIXME: Need to transform the exception-specification too.
4321
John McCalla2becad2009-10-21 00:40:46 +00004322 QualType Result = TL.getType();
4323 if (getDerived().AlwaysRebuild() ||
4324 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004325 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004326 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004327 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004328 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004329 if (Result.isNull())
4330 return QualType();
4331 }
Mike Stump1eb44332009-09-09 15:08:12 +00004332
John McCalla2becad2009-10-21 00:40:46 +00004333 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004334 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004335 NewTL.setLParenLoc(TL.getLParenLoc());
4336 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004337 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004338 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4339 NewTL.setArg(i, ParamDecls[i]);
4340
4341 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004342}
Mike Stump1eb44332009-09-09 15:08:12 +00004343
Douglas Gregor577f75a2009-08-04 16:50:30 +00004344template<typename Derived>
4345QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004346 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004347 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004348 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004349 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4350 if (ResultType.isNull())
4351 return QualType();
4352
4353 QualType Result = TL.getType();
4354 if (getDerived().AlwaysRebuild() ||
4355 ResultType != T->getResultType())
4356 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4357
4358 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004359 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004360 NewTL.setLParenLoc(TL.getLParenLoc());
4361 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004362 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004363
4364 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004365}
Mike Stump1eb44332009-09-09 15:08:12 +00004366
John McCalled976492009-12-04 22:46:56 +00004367template<typename Derived> QualType
4368TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004369 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004370 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004371 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004372 if (!D)
4373 return QualType();
4374
4375 QualType Result = TL.getType();
4376 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4377 Result = getDerived().RebuildUnresolvedUsingType(D);
4378 if (Result.isNull())
4379 return QualType();
4380 }
4381
4382 // We might get an arbitrary type spec type back. We should at
4383 // least always get a type spec type, though.
4384 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4385 NewTL.setNameLoc(TL.getNameLoc());
4386
4387 return Result;
4388}
4389
Douglas Gregor577f75a2009-08-04 16:50:30 +00004390template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004391QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004392 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004393 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004394 TypedefNameDecl *Typedef
4395 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4396 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004397 if (!Typedef)
4398 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004399
John McCalla2becad2009-10-21 00:40:46 +00004400 QualType Result = TL.getType();
4401 if (getDerived().AlwaysRebuild() ||
4402 Typedef != T->getDecl()) {
4403 Result = getDerived().RebuildTypedefType(Typedef);
4404 if (Result.isNull())
4405 return QualType();
4406 }
Mike Stump1eb44332009-09-09 15:08:12 +00004407
John McCalla2becad2009-10-21 00:40:46 +00004408 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4409 NewTL.setNameLoc(TL.getNameLoc());
4410
4411 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004412}
Mike Stump1eb44332009-09-09 15:08:12 +00004413
Douglas Gregor577f75a2009-08-04 16:50:30 +00004414template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004415QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004416 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004417 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004418 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4419 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004420
John McCall60d7b3a2010-08-24 06:29:42 +00004421 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004422 if (E.isInvalid())
4423 return QualType();
4424
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004425 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4426 if (E.isInvalid())
4427 return QualType();
4428
John McCalla2becad2009-10-21 00:40:46 +00004429 QualType Result = TL.getType();
4430 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004431 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004432 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004433 if (Result.isNull())
4434 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004435 }
John McCalla2becad2009-10-21 00:40:46 +00004436 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004437
John McCalla2becad2009-10-21 00:40:46 +00004438 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004439 NewTL.setTypeofLoc(TL.getTypeofLoc());
4440 NewTL.setLParenLoc(TL.getLParenLoc());
4441 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004442
4443 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004444}
Mike Stump1eb44332009-09-09 15:08:12 +00004445
4446template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004447QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004448 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004449 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4450 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4451 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004452 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004453
John McCalla2becad2009-10-21 00:40:46 +00004454 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004455 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4456 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004457 if (Result.isNull())
4458 return QualType();
4459 }
Mike Stump1eb44332009-09-09 15:08:12 +00004460
John McCalla2becad2009-10-21 00:40:46 +00004461 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004462 NewTL.setTypeofLoc(TL.getTypeofLoc());
4463 NewTL.setLParenLoc(TL.getLParenLoc());
4464 NewTL.setRParenLoc(TL.getRParenLoc());
4465 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004466
4467 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004468}
Mike Stump1eb44332009-09-09 15:08:12 +00004469
4470template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004471QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004472 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004473 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004474
Douglas Gregor670444e2009-08-04 22:27:00 +00004475 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004476 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4477 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004478
John McCall60d7b3a2010-08-24 06:29:42 +00004479 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004480 if (E.isInvalid())
4481 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004482
Richard Smith76f3f692012-02-22 02:04:18 +00004483 E = getSema().ActOnDecltypeExpression(E.take());
4484 if (E.isInvalid())
4485 return QualType();
4486
John McCalla2becad2009-10-21 00:40:46 +00004487 QualType Result = TL.getType();
4488 if (getDerived().AlwaysRebuild() ||
4489 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004490 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004491 if (Result.isNull())
4492 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004493 }
John McCalla2becad2009-10-21 00:40:46 +00004494 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004495
John McCalla2becad2009-10-21 00:40:46 +00004496 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4497 NewTL.setNameLoc(TL.getNameLoc());
4498
4499 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004500}
4501
4502template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004503QualType TreeTransform<Derived>::TransformUnaryTransformType(
4504 TypeLocBuilder &TLB,
4505 UnaryTransformTypeLoc TL) {
4506 QualType Result = TL.getType();
4507 if (Result->isDependentType()) {
4508 const UnaryTransformType *T = TL.getTypePtr();
4509 QualType NewBase =
4510 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4511 Result = getDerived().RebuildUnaryTransformType(NewBase,
4512 T->getUTTKind(),
4513 TL.getKWLoc());
4514 if (Result.isNull())
4515 return QualType();
4516 }
4517
4518 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4519 NewTL.setKWLoc(TL.getKWLoc());
4520 NewTL.setParensRange(TL.getParensRange());
4521 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4522 return Result;
4523}
4524
4525template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004526QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4527 AutoTypeLoc TL) {
4528 const AutoType *T = TL.getTypePtr();
4529 QualType OldDeduced = T->getDeducedType();
4530 QualType NewDeduced;
4531 if (!OldDeduced.isNull()) {
4532 NewDeduced = getDerived().TransformType(OldDeduced);
4533 if (NewDeduced.isNull())
4534 return QualType();
4535 }
4536
4537 QualType Result = TL.getType();
Richard Smithdc7a4f52013-04-30 13:56:41 +00004538 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4539 T->isDependentType()) {
Richard Smitha2c36462013-04-26 16:15:35 +00004540 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith34b41d92011-02-20 03:19:35 +00004541 if (Result.isNull())
4542 return QualType();
4543 }
4544
4545 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4546 NewTL.setNameLoc(TL.getNameLoc());
4547
4548 return Result;
4549}
4550
4551template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004552QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004553 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004554 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004555 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004556 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4557 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004558 if (!Record)
4559 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004560
John McCalla2becad2009-10-21 00:40:46 +00004561 QualType Result = TL.getType();
4562 if (getDerived().AlwaysRebuild() ||
4563 Record != T->getDecl()) {
4564 Result = getDerived().RebuildRecordType(Record);
4565 if (Result.isNull())
4566 return QualType();
4567 }
Mike Stump1eb44332009-09-09 15:08:12 +00004568
John McCalla2becad2009-10-21 00:40:46 +00004569 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4570 NewTL.setNameLoc(TL.getNameLoc());
4571
4572 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004573}
Mike Stump1eb44332009-09-09 15:08:12 +00004574
4575template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004576QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004577 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004578 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004579 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004580 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4581 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004582 if (!Enum)
4583 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004584
John McCalla2becad2009-10-21 00:40:46 +00004585 QualType Result = TL.getType();
4586 if (getDerived().AlwaysRebuild() ||
4587 Enum != T->getDecl()) {
4588 Result = getDerived().RebuildEnumType(Enum);
4589 if (Result.isNull())
4590 return QualType();
4591 }
Mike Stump1eb44332009-09-09 15:08:12 +00004592
John McCalla2becad2009-10-21 00:40:46 +00004593 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4594 NewTL.setNameLoc(TL.getNameLoc());
4595
4596 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004597}
John McCall7da24312009-09-05 00:15:47 +00004598
John McCall3cb0ebd2010-03-10 03:28:59 +00004599template<typename Derived>
4600QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4601 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004602 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004603 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4604 TL.getTypePtr()->getDecl());
4605 if (!D) return QualType();
4606
4607 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4608 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4609 return T;
4610}
4611
Douglas Gregor577f75a2009-08-04 16:50:30 +00004612template<typename Derived>
4613QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004614 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004615 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004616 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004617}
4618
Mike Stump1eb44332009-09-09 15:08:12 +00004619template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004620QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004621 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004622 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004623 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004624
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004625 // Substitute into the replacement type, which itself might involve something
4626 // that needs to be transformed. This only tends to occur with default
4627 // template arguments of template template parameters.
4628 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4629 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4630 if (Replacement.isNull())
4631 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004632
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004633 // Always canonicalize the replacement type.
4634 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4635 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004636 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004637 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004638
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004639 // Propagate type-source information.
4640 SubstTemplateTypeParmTypeLoc NewTL
4641 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4642 NewTL.setNameLoc(TL.getNameLoc());
4643 return Result;
4644
John McCall49a832b2009-10-18 09:09:24 +00004645}
4646
4647template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004648QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4649 TypeLocBuilder &TLB,
4650 SubstTemplateTypeParmPackTypeLoc TL) {
4651 return TransformTypeSpecType(TLB, TL);
4652}
4653
4654template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004655QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004656 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004657 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004658 const TemplateSpecializationType *T = TL.getTypePtr();
4659
Douglas Gregor1d752d72011-03-02 18:46:51 +00004660 // The nested-name-specifier never matters in a TemplateSpecializationType,
4661 // because we can't have a dependent nested-name-specifier anyway.
4662 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004663 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004664 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4665 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004666 if (Template.isNull())
4667 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004668
John McCall43fed0d2010-11-12 08:19:04 +00004669 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4670}
4671
Eli Friedmanb001de72011-10-06 23:00:33 +00004672template<typename Derived>
4673QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4674 AtomicTypeLoc TL) {
4675 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4676 if (ValueType.isNull())
4677 return QualType();
4678
4679 QualType Result = TL.getType();
4680 if (getDerived().AlwaysRebuild() ||
4681 ValueType != TL.getValueLoc().getType()) {
4682 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4683 if (Result.isNull())
4684 return QualType();
4685 }
4686
4687 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4688 NewTL.setKWLoc(TL.getKWLoc());
4689 NewTL.setLParenLoc(TL.getLParenLoc());
4690 NewTL.setRParenLoc(TL.getRParenLoc());
4691
4692 return Result;
4693}
4694
Chad Rosier4a9d7952012-08-08 18:46:20 +00004695 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004696 /// container that provides a \c getArgLoc() member function.
4697 ///
4698 /// This iterator is intended to be used with the iterator form of
4699 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4700 template<typename ArgLocContainer>
4701 class TemplateArgumentLocContainerIterator {
4702 ArgLocContainer *Container;
4703 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004704
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004705 public:
4706 typedef TemplateArgumentLoc value_type;
4707 typedef TemplateArgumentLoc reference;
4708 typedef int difference_type;
4709 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004710
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004711 class pointer {
4712 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004713
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004714 public:
4715 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004716
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004717 const TemplateArgumentLoc *operator->() const {
4718 return &Arg;
4719 }
4720 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004721
4722
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004723 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004724
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004725 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4726 unsigned Index)
4727 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004728
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004729 TemplateArgumentLocContainerIterator &operator++() {
4730 ++Index;
4731 return *this;
4732 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004733
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004734 TemplateArgumentLocContainerIterator operator++(int) {
4735 TemplateArgumentLocContainerIterator Old(*this);
4736 ++(*this);
4737 return Old;
4738 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004739
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004740 TemplateArgumentLoc operator*() const {
4741 return Container->getArgLoc(Index);
4742 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004743
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004744 pointer operator->() const {
4745 return pointer(Container->getArgLoc(Index));
4746 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004747
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004748 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004749 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004750 return X.Container == Y.Container && X.Index == Y.Index;
4751 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004752
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004753 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004754 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004755 return !(X == Y);
4756 }
4757 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004758
4759
John McCall43fed0d2010-11-12 08:19:04 +00004760template <typename Derived>
4761QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4762 TypeLocBuilder &TLB,
4763 TemplateSpecializationTypeLoc TL,
4764 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004765 TemplateArgumentListInfo NewTemplateArgs;
4766 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4767 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004768 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4769 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004770 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004771 ArgIterator(TL, TL.getNumArgs()),
4772 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004773 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004774
John McCall833ca992009-10-29 08:12:44 +00004775 // FIXME: maybe don't rebuild if all the template arguments are the same.
4776
4777 QualType Result =
4778 getDerived().RebuildTemplateSpecializationType(Template,
4779 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004780 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004781
4782 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004783 // Specializations of template template parameters are represented as
4784 // TemplateSpecializationTypes, and substitution of type alias templates
4785 // within a dependent context can transform them into
4786 // DependentTemplateSpecializationTypes.
4787 if (isa<DependentTemplateSpecializationType>(Result)) {
4788 DependentTemplateSpecializationTypeLoc NewTL
4789 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004790 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004791 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004792 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004793 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004794 NewTL.setLAngleLoc(TL.getLAngleLoc());
4795 NewTL.setRAngleLoc(TL.getRAngleLoc());
4796 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4797 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4798 return Result;
4799 }
4800
John McCall833ca992009-10-29 08:12:44 +00004801 TemplateSpecializationTypeLoc NewTL
4802 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004803 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004804 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4805 NewTL.setLAngleLoc(TL.getLAngleLoc());
4806 NewTL.setRAngleLoc(TL.getRAngleLoc());
4807 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4808 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004809 }
Mike Stump1eb44332009-09-09 15:08:12 +00004810
John McCall833ca992009-10-29 08:12:44 +00004811 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004812}
Mike Stump1eb44332009-09-09 15:08:12 +00004813
Douglas Gregora88f09f2011-02-28 17:23:35 +00004814template <typename Derived>
4815QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4816 TypeLocBuilder &TLB,
4817 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004818 TemplateName Template,
4819 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004820 TemplateArgumentListInfo NewTemplateArgs;
4821 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4822 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4823 typedef TemplateArgumentLocContainerIterator<
4824 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004825 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004826 ArgIterator(TL, TL.getNumArgs()),
4827 NewTemplateArgs))
4828 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004829
Douglas Gregora88f09f2011-02-28 17:23:35 +00004830 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004831
Douglas Gregora88f09f2011-02-28 17:23:35 +00004832 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4833 QualType Result
4834 = getSema().Context.getDependentTemplateSpecializationType(
4835 TL.getTypePtr()->getKeyword(),
4836 DTN->getQualifier(),
4837 DTN->getIdentifier(),
4838 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004839
Douglas Gregora88f09f2011-02-28 17:23:35 +00004840 DependentTemplateSpecializationTypeLoc NewTL
4841 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004842 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004843 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004844 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004845 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004846 NewTL.setLAngleLoc(TL.getLAngleLoc());
4847 NewTL.setRAngleLoc(TL.getRAngleLoc());
4848 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4849 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4850 return Result;
4851 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004852
4853 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004854 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004855 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004856 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004857
Douglas Gregora88f09f2011-02-28 17:23:35 +00004858 if (!Result.isNull()) {
4859 /// FIXME: Wrap this in an elaborated-type-specifier?
4860 TemplateSpecializationTypeLoc NewTL
4861 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004862 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004863 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004864 NewTL.setLAngleLoc(TL.getLAngleLoc());
4865 NewTL.setRAngleLoc(TL.getRAngleLoc());
4866 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4867 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4868 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004869
Douglas Gregora88f09f2011-02-28 17:23:35 +00004870 return Result;
4871}
4872
Mike Stump1eb44332009-09-09 15:08:12 +00004873template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004874QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004875TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004876 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004877 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004878
Douglas Gregor9e876872011-03-01 18:12:44 +00004879 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004880 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004881 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004882 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004883 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4884 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004885 return QualType();
4886 }
Mike Stump1eb44332009-09-09 15:08:12 +00004887
John McCall43fed0d2010-11-12 08:19:04 +00004888 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4889 if (NamedT.isNull())
4890 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004891
Richard Smith3e4c6c42011-05-05 21:57:07 +00004892 // C++0x [dcl.type.elab]p2:
4893 // If the identifier resolves to a typedef-name or the simple-template-id
4894 // resolves to an alias template specialization, the
4895 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004896 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4897 if (const TemplateSpecializationType *TST =
4898 NamedT->getAs<TemplateSpecializationType>()) {
4899 TemplateName Template = TST->getTemplateName();
4900 if (TypeAliasTemplateDecl *TAT =
4901 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4902 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4903 diag::err_tag_reference_non_tag) << 4;
4904 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4905 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004906 }
4907 }
4908
John McCalla2becad2009-10-21 00:40:46 +00004909 QualType Result = TL.getType();
4910 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004911 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004912 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004913 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004914 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004915 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004916 if (Result.isNull())
4917 return QualType();
4918 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004919
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004920 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004921 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004922 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004923 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004924}
Mike Stump1eb44332009-09-09 15:08:12 +00004925
4926template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004927QualType TreeTransform<Derived>::TransformAttributedType(
4928 TypeLocBuilder &TLB,
4929 AttributedTypeLoc TL) {
4930 const AttributedType *oldType = TL.getTypePtr();
4931 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4932 if (modifiedType.isNull())
4933 return QualType();
4934
4935 QualType result = TL.getType();
4936
4937 // FIXME: dependent operand expressions?
4938 if (getDerived().AlwaysRebuild() ||
4939 modifiedType != oldType->getModifiedType()) {
4940 // TODO: this is really lame; we should really be rebuilding the
4941 // equivalent type from first principles.
4942 QualType equivalentType
4943 = getDerived().TransformType(oldType->getEquivalentType());
4944 if (equivalentType.isNull())
4945 return QualType();
4946 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4947 modifiedType,
4948 equivalentType);
4949 }
4950
4951 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4952 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4953 if (TL.hasAttrOperand())
4954 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4955 if (TL.hasAttrExprOperand())
4956 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4957 else if (TL.hasAttrEnumOperand())
4958 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4959
4960 return result;
4961}
4962
4963template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004964QualType
4965TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4966 ParenTypeLoc TL) {
4967 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4968 if (Inner.isNull())
4969 return QualType();
4970
4971 QualType Result = TL.getType();
4972 if (getDerived().AlwaysRebuild() ||
4973 Inner != TL.getInnerLoc().getType()) {
4974 Result = getDerived().RebuildParenType(Inner);
4975 if (Result.isNull())
4976 return QualType();
4977 }
4978
4979 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4980 NewTL.setLParenLoc(TL.getLParenLoc());
4981 NewTL.setRParenLoc(TL.getRParenLoc());
4982 return Result;
4983}
4984
4985template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004986QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004987 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004988 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004989
Douglas Gregor2494dd02011-03-01 01:34:45 +00004990 NestedNameSpecifierLoc QualifierLoc
4991 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4992 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004993 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004994
John McCall33500952010-06-11 00:33:02 +00004995 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004996 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004997 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004998 QualifierLoc,
4999 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00005000 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00005001 if (Result.isNull())
5002 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005003
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005004 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5005 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00005006 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5007
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005008 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005009 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00005010 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00005011 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005012 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005013 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00005014 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00005015 NewTL.setNameLoc(TL.getNameLoc());
5016 }
John McCalla2becad2009-10-21 00:40:46 +00005017 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00005018}
Mike Stump1eb44332009-09-09 15:08:12 +00005019
Douglas Gregor577f75a2009-08-04 16:50:30 +00005020template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00005021QualType TreeTransform<Derived>::
5022 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005023 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005024 NestedNameSpecifierLoc QualifierLoc;
5025 if (TL.getQualifierLoc()) {
5026 QualifierLoc
5027 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5028 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00005029 return QualType();
5030 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005031
John McCall43fed0d2010-11-12 08:19:04 +00005032 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005033 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00005034}
5035
5036template<typename Derived>
5037QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005038TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5039 DependentTemplateSpecializationTypeLoc TL,
5040 NestedNameSpecifierLoc QualifierLoc) {
5041 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005042
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005043 TemplateArgumentListInfo NewTemplateArgs;
5044 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5045 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005046
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005047 typedef TemplateArgumentLocContainerIterator<
5048 DependentTemplateSpecializationTypeLoc> ArgIterator;
5049 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5050 ArgIterator(TL, TL.getNumArgs()),
5051 NewTemplateArgs))
5052 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005053
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005054 QualType Result
5055 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5056 QualifierLoc,
5057 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005058 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005059 NewTemplateArgs);
5060 if (Result.isNull())
5061 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005062
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005063 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5064 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005065
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005066 // Copy information relevant to the template specialization.
5067 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005068 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005069 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005070 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005071 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5072 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005073 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005074 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005075
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005076 // Copy information relevant to the elaborated type.
5077 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005078 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005079 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005080 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5081 DependentTemplateSpecializationTypeLoc SpecTL
5082 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005083 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005084 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005085 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005086 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005087 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5088 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005089 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005090 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005091 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005092 TemplateSpecializationTypeLoc SpecTL
5093 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005094 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005095 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005096 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5097 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005098 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005099 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005100 }
5101 return Result;
5102}
5103
5104template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005105QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5106 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005107 QualType Pattern
5108 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005109 if (Pattern.isNull())
5110 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005111
5112 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005113 if (getDerived().AlwaysRebuild() ||
5114 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005115 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005116 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005117 TL.getEllipsisLoc(),
5118 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005119 if (Result.isNull())
5120 return QualType();
5121 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005122
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005123 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5124 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5125 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005126}
5127
5128template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005129QualType
5130TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005131 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005132 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005133 TLB.pushFullCopy(TL);
5134 return TL.getType();
5135}
5136
5137template<typename Derived>
5138QualType
5139TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005140 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005141 // ObjCObjectType is never dependent.
5142 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005143 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005144}
Mike Stump1eb44332009-09-09 15:08:12 +00005145
5146template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005147QualType
5148TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005149 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005150 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005151 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005152 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005153}
5154
Douglas Gregor577f75a2009-08-04 16:50:30 +00005155//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005156// Statement transformation
5157//===----------------------------------------------------------------------===//
5158template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005159StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005160TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005161 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005162}
5163
5164template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005165StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005166TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5167 return getDerived().TransformCompoundStmt(S, false);
5168}
5169
5170template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005171StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005172TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005173 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005174 Sema::CompoundScopeRAII CompoundScope(getSema());
5175
John McCall7114cba2010-08-27 19:56:05 +00005176 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005177 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005178 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005179 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5180 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005181 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005182 if (Result.isInvalid()) {
5183 // Immediately fail if this was a DeclStmt, since it's very
5184 // likely that this will cause problems for future statements.
5185 if (isa<DeclStmt>(*B))
5186 return StmtError();
5187
5188 // Otherwise, just keep processing substatements and fail later.
5189 SubStmtInvalid = true;
5190 continue;
5191 }
Mike Stump1eb44332009-09-09 15:08:12 +00005192
Douglas Gregor43959a92009-08-20 07:17:43 +00005193 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5194 Statements.push_back(Result.takeAs<Stmt>());
5195 }
Mike Stump1eb44332009-09-09 15:08:12 +00005196
John McCall7114cba2010-08-27 19:56:05 +00005197 if (SubStmtInvalid)
5198 return StmtError();
5199
Douglas Gregor43959a92009-08-20 07:17:43 +00005200 if (!getDerived().AlwaysRebuild() &&
5201 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005202 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005203
5204 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005205 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005206 S->getRBracLoc(),
5207 IsStmtExpr);
5208}
Mike Stump1eb44332009-09-09 15:08:12 +00005209
Douglas Gregor43959a92009-08-20 07:17:43 +00005210template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005211StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005212TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005213 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005214 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005215 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5216 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005217
Eli Friedman264c1f82009-11-19 03:14:00 +00005218 // Transform the left-hand case value.
5219 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005220 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005221 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005222 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005223
Eli Friedman264c1f82009-11-19 03:14:00 +00005224 // Transform the right-hand case value (for the GNU case-range extension).
5225 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005226 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005227 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005228 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005229 }
Mike Stump1eb44332009-09-09 15:08:12 +00005230
Douglas Gregor43959a92009-08-20 07:17:43 +00005231 // Build the case statement.
5232 // Case statements are always rebuilt so that they will attached to their
5233 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005234 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005235 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005236 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005237 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005238 S->getColonLoc());
5239 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005240 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005241
Douglas Gregor43959a92009-08-20 07:17:43 +00005242 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005243 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005244 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005245 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005246
Douglas Gregor43959a92009-08-20 07:17:43 +00005247 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005248 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005249}
5250
5251template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005252StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005253TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005254 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005255 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005256 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005257 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005258
Douglas Gregor43959a92009-08-20 07:17:43 +00005259 // Default statements are always rebuilt
5260 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005261 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005262}
Mike Stump1eb44332009-09-09 15:08:12 +00005263
Douglas Gregor43959a92009-08-20 07:17:43 +00005264template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005265StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005266TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005267 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005268 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005269 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005270
Chris Lattner57ad3782011-02-17 20:34:02 +00005271 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5272 S->getDecl());
5273 if (!LD)
5274 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005275
5276
Douglas Gregor43959a92009-08-20 07:17:43 +00005277 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005278 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005279 cast<LabelDecl>(LD), SourceLocation(),
5280 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005281}
Mike Stump1eb44332009-09-09 15:08:12 +00005282
Douglas Gregor43959a92009-08-20 07:17:43 +00005283template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005284StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005285TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5286 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5287 if (SubStmt.isInvalid())
5288 return StmtError();
5289
5290 // TODO: transform attributes
5291 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5292 return S;
5293
5294 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5295 S->getAttrs(),
5296 SubStmt.get());
5297}
5298
5299template<typename Derived>
5300StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005301TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005302 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005303 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005304 VarDecl *ConditionVar = 0;
5305 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005306 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005307 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005308 getDerived().TransformDefinition(
5309 S->getConditionVariable()->getLocation(),
5310 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005311 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005312 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005313 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005314 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005315
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005316 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005317 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005318
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005319 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005320 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005321 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005322 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005323 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005324 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005325
John McCall9ae2f072010-08-23 23:25:46 +00005326 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005327 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005328 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005329
John McCall9ae2f072010-08-23 23:25:46 +00005330 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5331 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005332 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005333
Douglas Gregor43959a92009-08-20 07:17:43 +00005334 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005335 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005336 if (Then.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 "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005340 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005341 if (Else.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 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005345 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005346 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005347 Then.get() == S->getThen() &&
5348 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005349 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005350
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005351 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005352 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005353 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005354}
5355
5356template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005357StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005358TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005359 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005360 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005361 VarDecl *ConditionVar = 0;
5362 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005363 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005364 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005365 getDerived().TransformDefinition(
5366 S->getConditionVariable()->getLocation(),
5367 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005368 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005369 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005370 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005371 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005372
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005373 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005374 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005375 }
Mike Stump1eb44332009-09-09 15:08:12 +00005376
Douglas Gregor43959a92009-08-20 07:17:43 +00005377 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005378 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005379 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005380 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005381 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005382 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005383
Douglas Gregor43959a92009-08-20 07:17:43 +00005384 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005385 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005386 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005387 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005388
Douglas Gregor43959a92009-08-20 07:17:43 +00005389 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005390 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5391 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005392}
Mike Stump1eb44332009-09-09 15:08:12 +00005393
Douglas Gregor43959a92009-08-20 07:17:43 +00005394template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005395StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005396TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005397 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005398 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005399 VarDecl *ConditionVar = 0;
5400 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005401 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005402 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005403 getDerived().TransformDefinition(
5404 S->getConditionVariable()->getLocation(),
5405 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005406 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005407 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005408 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005409 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005410
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005411 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005412 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005413
5414 if (S->getCond()) {
5415 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005416 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005417 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005418 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005419 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005420 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005421 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005422 }
Mike Stump1eb44332009-09-09 15:08:12 +00005423
John McCall9ae2f072010-08-23 23:25:46 +00005424 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5425 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005426 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005427
Douglas Gregor43959a92009-08-20 07:17:43 +00005428 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005429 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005430 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005431 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005432
Douglas Gregor43959a92009-08-20 07:17:43 +00005433 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005434 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005435 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005436 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005437 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005438
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005439 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005440 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005441}
Mike Stump1eb44332009-09-09 15:08:12 +00005442
Douglas Gregor43959a92009-08-20 07:17:43 +00005443template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005444StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005445TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005446 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005447 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005448 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005449 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005450
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005451 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005452 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005453 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005454 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005455
Douglas Gregor43959a92009-08-20 07:17:43 +00005456 if (!getDerived().AlwaysRebuild() &&
5457 Cond.get() == S->getCond() &&
5458 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005459 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005460
John McCall9ae2f072010-08-23 23:25:46 +00005461 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5462 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005463 S->getRParenLoc());
5464}
Mike Stump1eb44332009-09-09 15:08:12 +00005465
Douglas Gregor43959a92009-08-20 07:17:43 +00005466template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005467StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005468TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005469 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005470 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005471 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005472 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005473
Douglas Gregor43959a92009-08-20 07:17:43 +00005474 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005475 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005476 VarDecl *ConditionVar = 0;
5477 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005478 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005479 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005480 getDerived().TransformDefinition(
5481 S->getConditionVariable()->getLocation(),
5482 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005483 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005484 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005485 } else {
5486 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005487
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005488 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005489 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005490
5491 if (S->getCond()) {
5492 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005493 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005494 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005495 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005496 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005497
John McCall9ae2f072010-08-23 23:25:46 +00005498 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005499 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005500 }
Mike Stump1eb44332009-09-09 15:08:12 +00005501
Chad Rosier4a9d7952012-08-08 18:46:20 +00005502 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005503 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005504 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005505
Douglas Gregor43959a92009-08-20 07:17:43 +00005506 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005507 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005508 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005509 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005510
Richard Smith41956372013-01-14 22:39:08 +00005511 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005512 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005513 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005514
Douglas Gregor43959a92009-08-20 07:17:43 +00005515 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005516 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005517 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005518 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005519
Douglas Gregor43959a92009-08-20 07:17:43 +00005520 if (!getDerived().AlwaysRebuild() &&
5521 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005522 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005523 Inc.get() == S->getInc() &&
5524 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005525 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005526
Douglas Gregor43959a92009-08-20 07:17:43 +00005527 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005528 Init.get(), FullCond, ConditionVar,
5529 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005530}
5531
5532template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005533StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005534TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005535 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5536 S->getLabel());
5537 if (!LD)
5538 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005539
Douglas Gregor43959a92009-08-20 07:17:43 +00005540 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005541 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005542 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005543}
5544
5545template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005546StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005547TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005548 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005549 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005550 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005551 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005552
Douglas Gregor43959a92009-08-20 07:17:43 +00005553 if (!getDerived().AlwaysRebuild() &&
5554 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005555 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005556
5557 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005558 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005559}
5560
5561template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005562StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005563TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005564 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005565}
Mike Stump1eb44332009-09-09 15:08:12 +00005566
Douglas Gregor43959a92009-08-20 07:17:43 +00005567template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005568StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005569TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005570 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005571}
Mike Stump1eb44332009-09-09 15:08:12 +00005572
Douglas Gregor43959a92009-08-20 07:17:43 +00005573template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005574StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005575TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005576 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005577 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005578 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005579
Mike Stump1eb44332009-09-09 15:08:12 +00005580 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005581 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005582 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005583}
Mike Stump1eb44332009-09-09 15:08:12 +00005584
Douglas Gregor43959a92009-08-20 07:17:43 +00005585template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005586StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005587TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005588 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005589 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005590 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5591 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005592 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5593 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005594 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005595 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005596
Douglas Gregor43959a92009-08-20 07:17:43 +00005597 if (Transformed != *D)
5598 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005599
Douglas Gregor43959a92009-08-20 07:17:43 +00005600 Decls.push_back(Transformed);
5601 }
Mike Stump1eb44332009-09-09 15:08:12 +00005602
Douglas Gregor43959a92009-08-20 07:17:43 +00005603 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005604 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005605
5606 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005607 S->getStartLoc(), S->getEndLoc());
5608}
Mike Stump1eb44332009-09-09 15:08:12 +00005609
Douglas Gregor43959a92009-08-20 07:17:43 +00005610template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005611StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005612TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005613
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005614 SmallVector<Expr*, 8> Constraints;
5615 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005616 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005617
John McCall60d7b3a2010-08-24 06:29:42 +00005618 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005619 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005620
5621 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005622
Anders Carlsson703e3942010-01-24 05:50:09 +00005623 // Go through the outputs.
5624 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005625 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005626
Anders Carlsson703e3942010-01-24 05:50:09 +00005627 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005628 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005629
Anders Carlsson703e3942010-01-24 05:50:09 +00005630 // Transform the output expr.
5631 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005632 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005633 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005634 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005635
Anders Carlsson703e3942010-01-24 05:50:09 +00005636 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005637
John McCall9ae2f072010-08-23 23:25:46 +00005638 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005639 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005640
Anders Carlsson703e3942010-01-24 05:50:09 +00005641 // Go through the inputs.
5642 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005643 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005644
Anders Carlsson703e3942010-01-24 05:50:09 +00005645 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005646 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005647
Anders Carlsson703e3942010-01-24 05:50:09 +00005648 // Transform the input expr.
5649 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005650 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005651 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005652 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005653
Anders Carlsson703e3942010-01-24 05:50:09 +00005654 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005655
John McCall9ae2f072010-08-23 23:25:46 +00005656 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005657 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005658
Anders Carlsson703e3942010-01-24 05:50:09 +00005659 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005660 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005661
5662 // Go through the clobbers.
5663 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005664 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005665
5666 // No need to transform the asm string literal.
5667 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005668 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5669 S->isVolatile(), S->getNumOutputs(),
5670 S->getNumInputs(), Names.data(),
5671 Constraints, Exprs, AsmString.get(),
5672 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005673}
5674
Chad Rosier8cd64b42012-06-11 20:47:18 +00005675template<typename Derived>
5676StmtResult
5677TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005678 ArrayRef<Token> AsmToks =
5679 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005680
John McCallaeeacf72013-05-03 00:10:13 +00005681 bool HadError = false, HadChange = false;
5682
5683 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5684 SmallVector<Expr*, 8> TransformedExprs;
5685 TransformedExprs.reserve(SrcExprs.size());
5686 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5687 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5688 if (!Result.isUsable()) {
5689 HadError = true;
5690 } else {
5691 HadChange |= (Result.get() != SrcExprs[i]);
5692 TransformedExprs.push_back(Result.take());
5693 }
5694 }
5695
5696 if (HadError) return StmtError();
5697 if (!HadChange && !getDerived().AlwaysRebuild())
5698 return Owned(S);
5699
Chad Rosier7bd092b2012-08-15 16:53:30 +00005700 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallaeeacf72013-05-03 00:10:13 +00005701 AsmToks, S->getAsmString(),
5702 S->getNumOutputs(), S->getNumInputs(),
5703 S->getAllConstraints(), S->getClobbers(),
5704 TransformedExprs, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005705}
Douglas Gregor43959a92009-08-20 07:17:43 +00005706
5707template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005708StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005709TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005710 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005711 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005712 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005713 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005714
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005715 // Transform the @catch statements (if present).
5716 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005717 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005718 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005719 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005720 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005721 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005722 if (Catch.get() != S->getCatchStmt(I))
5723 AnyCatchChanged = true;
5724 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005725 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005726
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005727 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005728 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005729 if (S->getFinallyStmt()) {
5730 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5731 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005732 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005733 }
5734
5735 // If nothing changed, just retain this statement.
5736 if (!getDerived().AlwaysRebuild() &&
5737 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005738 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005739 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005740 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005741
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005742 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005743 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005744 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005745}
Mike Stump1eb44332009-09-09 15:08:12 +00005746
Douglas Gregor43959a92009-08-20 07:17:43 +00005747template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005748StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005749TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005750 // Transform the @catch parameter, if there is one.
5751 VarDecl *Var = 0;
5752 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5753 TypeSourceInfo *TSInfo = 0;
5754 if (FromVar->getTypeSourceInfo()) {
5755 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5756 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005757 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005758 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005759
Douglas Gregorbe270a02010-04-26 17:57:08 +00005760 QualType T;
5761 if (TSInfo)
5762 T = TSInfo->getType();
5763 else {
5764 T = getDerived().TransformType(FromVar->getType());
5765 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005766 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005767 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005768
Douglas Gregorbe270a02010-04-26 17:57:08 +00005769 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5770 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005771 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005772 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005773
John McCall60d7b3a2010-08-24 06:29:42 +00005774 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005775 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005776 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005777
5778 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005779 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005780 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005781}
Mike Stump1eb44332009-09-09 15:08:12 +00005782
Douglas Gregor43959a92009-08-20 07:17:43 +00005783template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005784StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005785TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005786 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005787 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005788 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005789 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005790
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005791 // If nothing changed, just retain this statement.
5792 if (!getDerived().AlwaysRebuild() &&
5793 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005794 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005795
5796 // Build a new statement.
5797 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005798 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005799}
Mike Stump1eb44332009-09-09 15:08:12 +00005800
Douglas Gregor43959a92009-08-20 07:17:43 +00005801template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005802StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005803TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005804 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005805 if (S->getThrowExpr()) {
5806 Operand = getDerived().TransformExpr(S->getThrowExpr());
5807 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005808 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005809 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005810
Douglas Gregord1377b22010-04-22 21:44:01 +00005811 if (!getDerived().AlwaysRebuild() &&
5812 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005813 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005814
John McCall9ae2f072010-08-23 23:25:46 +00005815 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005816}
Mike Stump1eb44332009-09-09 15:08:12 +00005817
Douglas Gregor43959a92009-08-20 07:17:43 +00005818template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005819StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005820TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005821 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005822 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005823 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005824 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005825 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005826 Object =
5827 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5828 Object.get());
5829 if (Object.isInvalid())
5830 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005831
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005832 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005833 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005834 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005835 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005836
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005837 // If nothing change, just retain the current statement.
5838 if (!getDerived().AlwaysRebuild() &&
5839 Object.get() == S->getSynchExpr() &&
5840 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005841 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005842
5843 // Build a new statement.
5844 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005845 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005846}
5847
5848template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005849StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005850TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5851 ObjCAutoreleasePoolStmt *S) {
5852 // Transform the body.
5853 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5854 if (Body.isInvalid())
5855 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005856
John McCallf85e1932011-06-15 23:02:42 +00005857 // If nothing changed, just retain this statement.
5858 if (!getDerived().AlwaysRebuild() &&
5859 Body.get() == S->getSubStmt())
5860 return SemaRef.Owned(S);
5861
5862 // Build a new statement.
5863 return getDerived().RebuildObjCAutoreleasePoolStmt(
5864 S->getAtLoc(), Body.get());
5865}
5866
5867template<typename Derived>
5868StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005869TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005870 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005871 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005872 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005873 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005874 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005875
Douglas Gregorc3203e72010-04-22 23:10:45 +00005876 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005877 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005878 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005879 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005880
Douglas Gregorc3203e72010-04-22 23:10:45 +00005881 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005882 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005883 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005884 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005885
Douglas Gregorc3203e72010-04-22 23:10:45 +00005886 // If nothing changed, just retain this statement.
5887 if (!getDerived().AlwaysRebuild() &&
5888 Element.get() == S->getElement() &&
5889 Collection.get() == S->getCollection() &&
5890 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005891 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005892
Douglas Gregorc3203e72010-04-22 23:10:45 +00005893 // Build a new statement.
5894 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005895 Element.get(),
5896 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005897 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005898 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005899}
5900
5901
5902template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005903StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005904TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5905 // Transform the exception declaration, if any.
5906 VarDecl *Var = 0;
5907 if (S->getExceptionDecl()) {
5908 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005909 TypeSourceInfo *T = getDerived().TransformType(
5910 ExceptionDecl->getTypeSourceInfo());
5911 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005912 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005913
Douglas Gregor83cb9422010-09-09 17:09:21 +00005914 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005915 ExceptionDecl->getInnerLocStart(),
5916 ExceptionDecl->getLocation(),
5917 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005918 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005919 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005920 }
Mike Stump1eb44332009-09-09 15:08:12 +00005921
Douglas Gregor43959a92009-08-20 07:17:43 +00005922 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005923 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005924 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005925 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005926
Douglas Gregor43959a92009-08-20 07:17:43 +00005927 if (!getDerived().AlwaysRebuild() &&
5928 !Var &&
5929 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005930 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005931
5932 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5933 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005934 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005935}
Mike Stump1eb44332009-09-09 15:08:12 +00005936
Douglas Gregor43959a92009-08-20 07:17:43 +00005937template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005938StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005939TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5940 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005941 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005942 = getDerived().TransformCompoundStmt(S->getTryBlock());
5943 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005944 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005945
Douglas Gregor43959a92009-08-20 07:17:43 +00005946 // Transform the handlers.
5947 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005948 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00005949 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005950 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005951 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5952 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005953 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005954
Douglas Gregor43959a92009-08-20 07:17:43 +00005955 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5956 Handlers.push_back(Handler.takeAs<Stmt>());
5957 }
Mike Stump1eb44332009-09-09 15:08:12 +00005958
Douglas Gregor43959a92009-08-20 07:17:43 +00005959 if (!getDerived().AlwaysRebuild() &&
5960 TryBlock.get() == S->getTryBlock() &&
5961 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005962 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005963
John McCall9ae2f072010-08-23 23:25:46 +00005964 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005965 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00005966}
Mike Stump1eb44332009-09-09 15:08:12 +00005967
Richard Smithad762fc2011-04-14 22:09:26 +00005968template<typename Derived>
5969StmtResult
5970TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5971 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5972 if (Range.isInvalid())
5973 return StmtError();
5974
5975 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5976 if (BeginEnd.isInvalid())
5977 return StmtError();
5978
5979 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5980 if (Cond.isInvalid())
5981 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005982 if (Cond.get())
5983 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5984 if (Cond.isInvalid())
5985 return StmtError();
5986 if (Cond.get())
5987 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005988
5989 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5990 if (Inc.isInvalid())
5991 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005992 if (Inc.get())
5993 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005994
5995 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5996 if (LoopVar.isInvalid())
5997 return StmtError();
5998
5999 StmtResult NewStmt = S;
6000 if (getDerived().AlwaysRebuild() ||
6001 Range.get() != S->getRangeStmt() ||
6002 BeginEnd.get() != S->getBeginEndStmt() ||
6003 Cond.get() != S->getCond() ||
6004 Inc.get() != S->getInc() ||
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006005 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smithad762fc2011-04-14 22:09:26 +00006006 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6007 S->getColonLoc(), Range.get(),
6008 BeginEnd.get(), Cond.get(),
6009 Inc.get(), LoopVar.get(),
6010 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006011 if (NewStmt.isInvalid())
6012 return StmtError();
6013 }
Richard Smithad762fc2011-04-14 22:09:26 +00006014
6015 StmtResult Body = getDerived().TransformStmt(S->getBody());
6016 if (Body.isInvalid())
6017 return StmtError();
6018
6019 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6020 // it now so we have a new statement to attach the body to.
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006021 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smithad762fc2011-04-14 22:09:26 +00006022 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6023 S->getColonLoc(), Range.get(),
6024 BeginEnd.get(), Cond.get(),
6025 Inc.get(), LoopVar.get(),
6026 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006027 if (NewStmt.isInvalid())
6028 return StmtError();
6029 }
Richard Smithad762fc2011-04-14 22:09:26 +00006030
6031 if (NewStmt.get() == S)
6032 return SemaRef.Owned(S);
6033
6034 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6035}
6036
John Wiegley28bbe4b2011-04-28 01:08:34 +00006037template<typename Derived>
6038StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00006039TreeTransform<Derived>::TransformMSDependentExistsStmt(
6040 MSDependentExistsStmt *S) {
6041 // Transform the nested-name-specifier, if any.
6042 NestedNameSpecifierLoc QualifierLoc;
6043 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006044 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00006045 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6046 if (!QualifierLoc)
6047 return StmtError();
6048 }
6049
6050 // Transform the declaration name.
6051 DeclarationNameInfo NameInfo = S->getNameInfo();
6052 if (NameInfo.getName()) {
6053 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6054 if (!NameInfo.getName())
6055 return StmtError();
6056 }
6057
6058 // Check whether anything changed.
6059 if (!getDerived().AlwaysRebuild() &&
6060 QualifierLoc == S->getQualifierLoc() &&
6061 NameInfo.getName() == S->getNameInfo().getName())
6062 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006063
Douglas Gregorba0513d2011-10-25 01:33:02 +00006064 // Determine whether this name exists, if we can.
6065 CXXScopeSpec SS;
6066 SS.Adopt(QualifierLoc);
6067 bool Dependent = false;
6068 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6069 case Sema::IER_Exists:
6070 if (S->isIfExists())
6071 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006072
Douglas Gregorba0513d2011-10-25 01:33:02 +00006073 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6074
6075 case Sema::IER_DoesNotExist:
6076 if (S->isIfNotExists())
6077 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006078
Douglas Gregorba0513d2011-10-25 01:33:02 +00006079 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006080
Douglas Gregorba0513d2011-10-25 01:33:02 +00006081 case Sema::IER_Dependent:
6082 Dependent = true;
6083 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006084
Douglas Gregor65019ac2011-10-25 03:44:56 +00006085 case Sema::IER_Error:
6086 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006087 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006088
Douglas Gregorba0513d2011-10-25 01:33:02 +00006089 // We need to continue with the instantiation, so do so now.
6090 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6091 if (SubStmt.isInvalid())
6092 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006093
Douglas Gregorba0513d2011-10-25 01:33:02 +00006094 // If we have resolved the name, just transform to the substatement.
6095 if (!Dependent)
6096 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006097
Douglas Gregorba0513d2011-10-25 01:33:02 +00006098 // The name is still dependent, so build a dependent expression again.
6099 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6100 S->isIfExists(),
6101 QualifierLoc,
6102 NameInfo,
6103 SubStmt.get());
6104}
6105
6106template<typename Derived>
John McCall76da55d2013-04-16 07:28:30 +00006107ExprResult
6108TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6109 NestedNameSpecifierLoc QualifierLoc;
6110 if (E->getQualifierLoc()) {
6111 QualifierLoc
6112 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6113 if (!QualifierLoc)
6114 return ExprError();
6115 }
6116
6117 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6118 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6119 if (!PD)
6120 return ExprError();
6121
6122 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6123 if (Base.isInvalid())
6124 return ExprError();
6125
6126 return new (SemaRef.getASTContext())
6127 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6128 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6129 QualifierLoc, E->getMemberLoc());
6130}
6131
6132template<typename Derived>
Douglas Gregorba0513d2011-10-25 01:33:02 +00006133StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006134TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6135 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6136 if(TryBlock.isInvalid()) return StmtError();
6137
6138 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6139 if(!getDerived().AlwaysRebuild() &&
6140 TryBlock.get() == S->getTryBlock() &&
6141 Handler.get() == S->getHandler())
6142 return SemaRef.Owned(S);
6143
6144 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6145 S->getTryLoc(),
6146 TryBlock.take(),
6147 Handler.take());
6148}
6149
6150template<typename Derived>
6151StmtResult
6152TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6153 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6154 if(Block.isInvalid()) return StmtError();
6155
6156 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6157 Block.take());
6158}
6159
6160template<typename Derived>
6161StmtResult
6162TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6163 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6164 if(FilterExpr.isInvalid()) return StmtError();
6165
6166 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6167 if(Block.isInvalid()) return StmtError();
6168
6169 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6170 FilterExpr.take(),
6171 Block.take());
6172}
6173
6174template<typename Derived>
6175StmtResult
6176TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6177 if(isa<SEHFinallyStmt>(Handler))
6178 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6179 else
6180 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6181}
6182
Douglas Gregor43959a92009-08-20 07:17:43 +00006183//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006184// Expression transformation
6185//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006186template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006187ExprResult
John McCall454feb92009-12-08 09:21:05 +00006188TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006189 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006190}
Mike Stump1eb44332009-09-09 15:08:12 +00006191
6192template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006193ExprResult
John McCall454feb92009-12-08 09:21:05 +00006194TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006195 NestedNameSpecifierLoc QualifierLoc;
6196 if (E->getQualifierLoc()) {
6197 QualifierLoc
6198 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6199 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006200 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006201 }
John McCalldbd872f2009-12-08 09:08:17 +00006202
6203 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006204 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6205 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006206 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006207 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006208
John McCallec8045d2010-08-17 21:27:17 +00006209 DeclarationNameInfo NameInfo = E->getNameInfo();
6210 if (NameInfo.getName()) {
6211 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6212 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006213 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006214 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006215
6216 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006217 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006218 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006219 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006220 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006221
6222 // Mark it referenced in the new context regardless.
6223 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006224 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006225
John McCall3fa5cae2010-10-26 07:05:15 +00006226 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006227 }
John McCalldbd872f2009-12-08 09:08:17 +00006228
6229 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006230 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006231 TemplateArgs = &TransArgs;
6232 TransArgs.setLAngleLoc(E->getLAngleLoc());
6233 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006234 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6235 E->getNumTemplateArgs(),
6236 TransArgs))
6237 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006238 }
6239
Chad Rosier4a9d7952012-08-08 18:46:20 +00006240 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006241 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006242}
Mike Stump1eb44332009-09-09 15:08:12 +00006243
Douglas Gregorb98b1992009-08-11 05:31:07 +00006244template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006245ExprResult
John McCall454feb92009-12-08 09:21:05 +00006246TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006247 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006248}
Mike Stump1eb44332009-09-09 15:08:12 +00006249
Douglas Gregorb98b1992009-08-11 05:31:07 +00006250template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006251ExprResult
John McCall454feb92009-12-08 09:21:05 +00006252TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006253 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006254}
Mike Stump1eb44332009-09-09 15:08:12 +00006255
Douglas Gregorb98b1992009-08-11 05:31:07 +00006256template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006257ExprResult
John McCall454feb92009-12-08 09:21:05 +00006258TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006259 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006260}
Mike Stump1eb44332009-09-09 15:08:12 +00006261
Douglas Gregorb98b1992009-08-11 05:31:07 +00006262template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006263ExprResult
John McCall454feb92009-12-08 09:21:05 +00006264TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006265 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006266}
Mike Stump1eb44332009-09-09 15:08:12 +00006267
Douglas Gregorb98b1992009-08-11 05:31:07 +00006268template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006269ExprResult
John McCall454feb92009-12-08 09:21:05 +00006270TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006271 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006272}
6273
6274template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006275ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006276TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis391ca9f2013-04-09 01:17:02 +00006277 if (FunctionDecl *FD = E->getDirectCallee())
6278 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smith9fcce652012-03-07 08:35:16 +00006279 return SemaRef.MaybeBindToTemporary(E);
6280}
6281
6282template<typename Derived>
6283ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006284TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6285 ExprResult ControllingExpr =
6286 getDerived().TransformExpr(E->getControllingExpr());
6287 if (ControllingExpr.isInvalid())
6288 return ExprError();
6289
Chris Lattner686775d2011-07-20 06:58:45 +00006290 SmallVector<Expr *, 4> AssocExprs;
6291 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006292 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6293 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6294 if (TS) {
6295 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6296 if (!AssocType)
6297 return ExprError();
6298 AssocTypes.push_back(AssocType);
6299 } else {
6300 AssocTypes.push_back(0);
6301 }
6302
6303 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6304 if (AssocExpr.isInvalid())
6305 return ExprError();
6306 AssocExprs.push_back(AssocExpr.release());
6307 }
6308
6309 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6310 E->getDefaultLoc(),
6311 E->getRParenLoc(),
6312 ControllingExpr.release(),
Dmitri Gribenko80613222013-05-10 13:06:58 +00006313 AssocTypes,
6314 AssocExprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00006315}
6316
6317template<typename Derived>
6318ExprResult
John McCall454feb92009-12-08 09:21:05 +00006319TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006320 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006321 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006322 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006323
Douglas Gregorb98b1992009-08-11 05:31:07 +00006324 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006325 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006326
John McCall9ae2f072010-08-23 23:25:46 +00006327 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006328 E->getRParen());
6329}
6330
Richard Smithefeeccf2012-10-21 03:28:35 +00006331/// \brief The operand of a unary address-of operator has special rules: it's
6332/// allowed to refer to a non-static member of a class even if there's no 'this'
6333/// object available.
6334template<typename Derived>
6335ExprResult
6336TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6337 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6338 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6339 else
6340 return getDerived().TransformExpr(E);
6341}
6342
Mike Stump1eb44332009-09-09 15:08:12 +00006343template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006344ExprResult
John McCall454feb92009-12-08 09:21:05 +00006345TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smith82b00012013-05-21 23:29:46 +00006346 ExprResult SubExpr;
6347 if (E->getOpcode() == UO_AddrOf)
6348 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6349 else
6350 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006351 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006352 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006353
Douglas Gregorb98b1992009-08-11 05:31:07 +00006354 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006355 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006356
Douglas Gregorb98b1992009-08-11 05:31:07 +00006357 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6358 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006359 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006360}
Mike Stump1eb44332009-09-09 15:08:12 +00006361
Douglas Gregorb98b1992009-08-11 05:31:07 +00006362template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006363ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006364TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6365 // Transform the type.
6366 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6367 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006368 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006369
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006370 // Transform all of the components into components similar to what the
6371 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006372 // FIXME: It would be slightly more efficient in the non-dependent case to
6373 // just map FieldDecls, rather than requiring the rebuilder to look for
6374 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006375 // template code that we don't care.
6376 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006377 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006378 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006379 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006380 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6381 const Node &ON = E->getComponent(I);
6382 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006383 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006384 Comp.LocStart = ON.getSourceRange().getBegin();
6385 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006386 switch (ON.getKind()) {
6387 case Node::Array: {
6388 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006389 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006390 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006391 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006392
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006393 ExprChanged = ExprChanged || Index.get() != FromIndex;
6394 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006395 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006396 break;
6397 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006398
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006399 case Node::Field:
6400 case Node::Identifier:
6401 Comp.isBrackets = false;
6402 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006403 if (!Comp.U.IdentInfo)
6404 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006405
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006406 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006407
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006408 case Node::Base:
6409 // Will be recomputed during the rebuild.
6410 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006411 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006412
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006413 Components.push_back(Comp);
6414 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006415
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006416 // If nothing changed, retain the existing expression.
6417 if (!getDerived().AlwaysRebuild() &&
6418 Type == E->getTypeSourceInfo() &&
6419 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006420 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006421
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006422 // Build a new offsetof expression.
6423 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6424 Components.data(), Components.size(),
6425 E->getRParenLoc());
6426}
6427
6428template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006429ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006430TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6431 assert(getDerived().AlreadyTransformed(E->getType()) &&
6432 "opaque value expression requires transformation");
6433 return SemaRef.Owned(E);
6434}
6435
6436template<typename Derived>
6437ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006438TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006439 // Rebuild the syntactic form. The original syntactic form has
6440 // opaque-value expressions in it, so strip those away and rebuild
6441 // the result. This is a really awful way of doing this, but the
6442 // better solution (rebuilding the semantic expressions and
6443 // rebinding OVEs as necessary) doesn't work; we'd need
6444 // TreeTransform to not strip away implicit conversions.
6445 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6446 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006447 if (result.isInvalid()) return ExprError();
6448
6449 // If that gives us a pseudo-object result back, the pseudo-object
6450 // expression must have been an lvalue-to-rvalue conversion which we
6451 // should reapply.
6452 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6453 result = SemaRef.checkPseudoObjectRValue(result.take());
6454
6455 return result;
6456}
6457
6458template<typename Derived>
6459ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006460TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6461 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006462 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006463 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006464
John McCalla93c9342009-12-07 02:54:59 +00006465 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006466 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006467 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006468
John McCall5ab75172009-11-04 07:28:41 +00006469 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006470 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006471
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006472 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6473 E->getKind(),
6474 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006475 }
Mike Stump1eb44332009-09-09 15:08:12 +00006476
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006477 // C++0x [expr.sizeof]p1:
6478 // The operand is either an expression, which is an unevaluated operand
6479 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006480 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6481 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006482
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006483 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6484 if (SubExpr.isInvalid())
6485 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006486
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006487 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6488 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006489
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006490 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6491 E->getOperatorLoc(),
6492 E->getKind(),
6493 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006494}
Mike Stump1eb44332009-09-09 15:08:12 +00006495
Douglas Gregorb98b1992009-08-11 05:31:07 +00006496template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006497ExprResult
John McCall454feb92009-12-08 09:21:05 +00006498TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006499 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006500 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006501 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006502
John McCall60d7b3a2010-08-24 06:29:42 +00006503 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006504 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006505 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006506
6507
Douglas Gregorb98b1992009-08-11 05:31:07 +00006508 if (!getDerived().AlwaysRebuild() &&
6509 LHS.get() == E->getLHS() &&
6510 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006511 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006512
John McCall9ae2f072010-08-23 23:25:46 +00006513 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006514 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006515 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006516 E->getRBracketLoc());
6517}
Mike Stump1eb44332009-09-09 15:08:12 +00006518
6519template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006520ExprResult
John McCall454feb92009-12-08 09:21:05 +00006521TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006522 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006523 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006524 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006525 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006526
6527 // Transform arguments.
6528 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006529 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006530 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006531 &ArgChanged))
6532 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006533
Douglas Gregorb98b1992009-08-11 05:31:07 +00006534 if (!getDerived().AlwaysRebuild() &&
6535 Callee.get() == E->getCallee() &&
6536 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006537 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006538
Douglas Gregorb98b1992009-08-11 05:31:07 +00006539 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006540 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006541 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006542 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006543 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006544 E->getRParenLoc());
6545}
Mike Stump1eb44332009-09-09 15:08:12 +00006546
6547template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006548ExprResult
John McCall454feb92009-12-08 09:21:05 +00006549TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006550 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006551 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006552 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006553
Douglas Gregor40d96a62011-02-28 21:54:11 +00006554 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006555 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006556 QualifierLoc
6557 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006558
Douglas Gregor40d96a62011-02-28 21:54:11 +00006559 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006560 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006561 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006562 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006563
Eli Friedmanf595cc42009-12-04 06:40:45 +00006564 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006565 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6566 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006567 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006568 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006569
John McCall6bb80172010-03-30 21:47:33 +00006570 NamedDecl *FoundDecl = E->getFoundDecl();
6571 if (FoundDecl == E->getMemberDecl()) {
6572 FoundDecl = Member;
6573 } else {
6574 FoundDecl = cast_or_null<NamedDecl>(
6575 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6576 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006577 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006578 }
6579
Douglas Gregorb98b1992009-08-11 05:31:07 +00006580 if (!getDerived().AlwaysRebuild() &&
6581 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006582 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006583 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006584 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006585 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006586
Anders Carlsson1f240322009-12-22 05:24:09 +00006587 // Mark it referenced in the new context regardless.
6588 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006589 SemaRef.MarkMemberReferenced(E);
6590
John McCall3fa5cae2010-10-26 07:05:15 +00006591 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006592 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006593
John McCalld5532b62009-11-23 01:53:49 +00006594 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006595 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006596 TransArgs.setLAngleLoc(E->getLAngleLoc());
6597 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006598 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6599 E->getNumTemplateArgs(),
6600 TransArgs))
6601 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006602 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006603
Douglas Gregorb98b1992009-08-11 05:31:07 +00006604 // FIXME: Bogus source location for the operator
6605 SourceLocation FakeOperatorLoc
6606 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6607
John McCallc2233c52010-01-15 08:34:02 +00006608 // FIXME: to do this check properly, we will need to preserve the
6609 // first-qualifier-in-scope here, just in case we had a dependent
6610 // base (and therefore couldn't do the check) and a
6611 // nested-name-qualifier (and therefore could do the lookup).
6612 NamedDecl *FirstQualifierInScope = 0;
6613
John McCall9ae2f072010-08-23 23:25:46 +00006614 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006615 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006616 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006617 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006618 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006619 Member,
John McCall6bb80172010-03-30 21:47:33 +00006620 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006621 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006622 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006623 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006624}
Mike Stump1eb44332009-09-09 15:08:12 +00006625
Douglas Gregorb98b1992009-08-11 05:31:07 +00006626template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006627ExprResult
John McCall454feb92009-12-08 09:21:05 +00006628TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006629 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006630 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006631 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006632
John McCall60d7b3a2010-08-24 06:29:42 +00006633 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006634 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006635 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006636
Douglas Gregorb98b1992009-08-11 05:31:07 +00006637 if (!getDerived().AlwaysRebuild() &&
6638 LHS.get() == E->getLHS() &&
6639 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006640 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006641
Lang Hamesbe9af122012-10-02 04:45:10 +00006642 Sema::FPContractStateRAII FPContractState(getSema());
6643 getSema().FPFeatures.fp_contract = E->isFPContractable();
6644
Douglas Gregorb98b1992009-08-11 05:31:07 +00006645 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006646 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006647}
6648
Mike Stump1eb44332009-09-09 15:08:12 +00006649template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006650ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006651TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006652 CompoundAssignOperator *E) {
6653 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006654}
Mike Stump1eb44332009-09-09 15:08:12 +00006655
Douglas Gregorb98b1992009-08-11 05:31:07 +00006656template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006657ExprResult TreeTransform<Derived>::
6658TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6659 // Just rebuild the common and RHS expressions and see whether we
6660 // get any changes.
6661
6662 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6663 if (commonExpr.isInvalid())
6664 return ExprError();
6665
6666 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6667 if (rhs.isInvalid())
6668 return ExprError();
6669
6670 if (!getDerived().AlwaysRebuild() &&
6671 commonExpr.get() == e->getCommon() &&
6672 rhs.get() == e->getFalseExpr())
6673 return SemaRef.Owned(e);
6674
6675 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6676 e->getQuestionLoc(),
6677 0,
6678 e->getColonLoc(),
6679 rhs.get());
6680}
6681
6682template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006683ExprResult
John McCall454feb92009-12-08 09:21:05 +00006684TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006685 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006686 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006687 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006688
John McCall60d7b3a2010-08-24 06:29:42 +00006689 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006690 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006691 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006692
John McCall60d7b3a2010-08-24 06:29:42 +00006693 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006694 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006695 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006696
Douglas Gregorb98b1992009-08-11 05:31:07 +00006697 if (!getDerived().AlwaysRebuild() &&
6698 Cond.get() == E->getCond() &&
6699 LHS.get() == E->getLHS() &&
6700 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006701 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006702
John McCall9ae2f072010-08-23 23:25:46 +00006703 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006704 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006705 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006706 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006707 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006708}
Mike Stump1eb44332009-09-09 15:08:12 +00006709
6710template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006711ExprResult
John McCall454feb92009-12-08 09:21:05 +00006712TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006713 // Implicit casts are eliminated during transformation, since they
6714 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006715 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006716}
Mike Stump1eb44332009-09-09 15:08:12 +00006717
Douglas Gregorb98b1992009-08-11 05:31:07 +00006718template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006719ExprResult
John McCall454feb92009-12-08 09:21:05 +00006720TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006721 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6722 if (!Type)
6723 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006724
John McCall60d7b3a2010-08-24 06:29:42 +00006725 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006726 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006727 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006728 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006729
Douglas Gregorb98b1992009-08-11 05:31:07 +00006730 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006731 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006732 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006733 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006734
John McCall9d125032010-01-15 18:39:57 +00006735 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006736 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006737 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006738 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006739}
Mike Stump1eb44332009-09-09 15:08:12 +00006740
Douglas Gregorb98b1992009-08-11 05:31:07 +00006741template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006742ExprResult
John McCall454feb92009-12-08 09:21:05 +00006743TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006744 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6745 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6746 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006747 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006748
John McCall60d7b3a2010-08-24 06:29:42 +00006749 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006750 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006751 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006752
Douglas Gregorb98b1992009-08-11 05:31:07 +00006753 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006754 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006755 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006756 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006757
John McCall1d7d8d62010-01-19 22:33:45 +00006758 // Note: the expression type doesn't necessarily match the
6759 // type-as-written, but that's okay, because it should always be
6760 // derivable from the initializer.
6761
John McCall42f56b52010-01-18 19:35:47 +00006762 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006763 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006764 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006765}
Mike Stump1eb44332009-09-09 15:08:12 +00006766
Douglas Gregorb98b1992009-08-11 05:31:07 +00006767template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006768ExprResult
John McCall454feb92009-12-08 09:21:05 +00006769TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006770 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006771 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006772 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006773
Douglas Gregorb98b1992009-08-11 05:31:07 +00006774 if (!getDerived().AlwaysRebuild() &&
6775 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006776 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006777
Douglas Gregorb98b1992009-08-11 05:31:07 +00006778 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006779 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006780 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006781 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006782 E->getAccessorLoc(),
6783 E->getAccessor());
6784}
Mike Stump1eb44332009-09-09 15:08:12 +00006785
Douglas Gregorb98b1992009-08-11 05:31:07 +00006786template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006787ExprResult
John McCall454feb92009-12-08 09:21:05 +00006788TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006789 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006790
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006791 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006792 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006793 Inits, &InitChanged))
6794 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006795
Douglas Gregorb98b1992009-08-11 05:31:07 +00006796 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006797 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006798
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006799 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006800 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006801}
Mike Stump1eb44332009-09-09 15:08:12 +00006802
Douglas Gregorb98b1992009-08-11 05:31:07 +00006803template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006804ExprResult
John McCall454feb92009-12-08 09:21:05 +00006805TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006806 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006807
Douglas Gregor43959a92009-08-20 07:17:43 +00006808 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006809 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006810 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006811 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006812
Douglas Gregor43959a92009-08-20 07:17:43 +00006813 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006814 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006815 bool ExprChanged = false;
6816 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6817 DEnd = E->designators_end();
6818 D != DEnd; ++D) {
6819 if (D->isFieldDesignator()) {
6820 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6821 D->getDotLoc(),
6822 D->getFieldLoc()));
6823 continue;
6824 }
Mike Stump1eb44332009-09-09 15:08:12 +00006825
Douglas Gregorb98b1992009-08-11 05:31:07 +00006826 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006827 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006828 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006829 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006830
6831 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006832 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006833
Douglas Gregorb98b1992009-08-11 05:31:07 +00006834 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6835 ArrayExprs.push_back(Index.release());
6836 continue;
6837 }
Mike Stump1eb44332009-09-09 15:08:12 +00006838
Douglas Gregorb98b1992009-08-11 05:31:07 +00006839 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006840 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006841 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6842 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006843 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006844
John McCall60d7b3a2010-08-24 06:29:42 +00006845 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006846 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006847 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006848
6849 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006850 End.get(),
6851 D->getLBracketLoc(),
6852 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006853
Douglas Gregorb98b1992009-08-11 05:31:07 +00006854 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6855 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006856
Douglas Gregorb98b1992009-08-11 05:31:07 +00006857 ArrayExprs.push_back(Start.release());
6858 ArrayExprs.push_back(End.release());
6859 }
Mike Stump1eb44332009-09-09 15:08:12 +00006860
Douglas Gregorb98b1992009-08-11 05:31:07 +00006861 if (!getDerived().AlwaysRebuild() &&
6862 Init.get() == E->getInit() &&
6863 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006864 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006865
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006866 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006867 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006868 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006869}
Mike Stump1eb44332009-09-09 15:08:12 +00006870
Douglas Gregorb98b1992009-08-11 05:31:07 +00006871template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006872ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006873TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006874 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006875 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006876
Douglas Gregor5557b252009-10-28 00:29:27 +00006877 // FIXME: Will we ever have proper type location here? Will we actually
6878 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006879 QualType T = getDerived().TransformType(E->getType());
6880 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006881 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006882
Douglas Gregorb98b1992009-08-11 05:31:07 +00006883 if (!getDerived().AlwaysRebuild() &&
6884 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006885 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006886
Douglas Gregorb98b1992009-08-11 05:31:07 +00006887 return getDerived().RebuildImplicitValueInitExpr(T);
6888}
Mike Stump1eb44332009-09-09 15:08:12 +00006889
Douglas Gregorb98b1992009-08-11 05:31:07 +00006890template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006891ExprResult
John McCall454feb92009-12-08 09:21:05 +00006892TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006893 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6894 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006895 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006896
John McCall60d7b3a2010-08-24 06:29:42 +00006897 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006898 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006899 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006900
Douglas Gregorb98b1992009-08-11 05:31:07 +00006901 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006902 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006903 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006904 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006905
John McCall9ae2f072010-08-23 23:25:46 +00006906 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006907 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006908}
6909
6910template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006911ExprResult
John McCall454feb92009-12-08 09:21:05 +00006912TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006913 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006914 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00006915 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6916 &ArgumentChanged))
6917 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006918
Douglas Gregorb98b1992009-08-11 05:31:07 +00006919 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006920 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006921 E->getRParenLoc());
6922}
Mike Stump1eb44332009-09-09 15:08:12 +00006923
Douglas Gregorb98b1992009-08-11 05:31:07 +00006924/// \brief Transform an address-of-label expression.
6925///
6926/// By default, the transformation of an address-of-label expression always
6927/// rebuilds the expression, so that the label identifier can be resolved to
6928/// the corresponding label statement by semantic analysis.
6929template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006930ExprResult
John McCall454feb92009-12-08 09:21:05 +00006931TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006932 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6933 E->getLabel());
6934 if (!LD)
6935 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006936
Douglas Gregorb98b1992009-08-11 05:31:07 +00006937 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006938 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006939}
Mike Stump1eb44332009-09-09 15:08:12 +00006940
6941template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006942ExprResult
John McCall454feb92009-12-08 09:21:05 +00006943TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006944 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006945 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006946 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006947 if (SubStmt.isInvalid()) {
6948 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006949 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006950 }
Mike Stump1eb44332009-09-09 15:08:12 +00006951
Douglas Gregorb98b1992009-08-11 05:31:07 +00006952 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006953 SubStmt.get() == E->getSubStmt()) {
6954 // Calling this an 'error' is unintuitive, but it does the right thing.
6955 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006956 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006957 }
Mike Stump1eb44332009-09-09 15:08:12 +00006958
6959 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006960 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006961 E->getRParenLoc());
6962}
Mike Stump1eb44332009-09-09 15:08:12 +00006963
Douglas Gregorb98b1992009-08-11 05:31:07 +00006964template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006965ExprResult
John McCall454feb92009-12-08 09:21:05 +00006966TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006967 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006968 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006969 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006970
John McCall60d7b3a2010-08-24 06:29:42 +00006971 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006972 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006973 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006974
John McCall60d7b3a2010-08-24 06:29:42 +00006975 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006976 if (RHS.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 Cond.get() == E->getCond() &&
6981 LHS.get() == E->getLHS() &&
6982 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006983 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006984
Douglas Gregorb98b1992009-08-11 05:31:07 +00006985 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006986 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006987 E->getRParenLoc());
6988}
Mike Stump1eb44332009-09-09 15:08:12 +00006989
Douglas Gregorb98b1992009-08-11 05:31:07 +00006990template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006991ExprResult
John McCall454feb92009-12-08 09:21:05 +00006992TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006993 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006994}
6995
6996template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006997ExprResult
John McCall454feb92009-12-08 09:21:05 +00006998TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006999 switch (E->getOperator()) {
7000 case OO_New:
7001 case OO_Delete:
7002 case OO_Array_New:
7003 case OO_Array_Delete:
7004 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00007005
Douglas Gregor668d6d92009-12-13 20:44:55 +00007006 case OO_Call: {
7007 // This is a call to an object's operator().
7008 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
7009
7010 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00007011 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00007012 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007013 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007014
7015 // FIXME: Poor location information
7016 SourceLocation FakeLParenLoc
7017 = SemaRef.PP.getLocForEndOfToken(
7018 static_cast<Expr *>(Object.get())->getLocEnd());
7019
7020 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007021 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007022 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007023 Args))
7024 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007025
John McCall9ae2f072010-08-23 23:25:46 +00007026 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007027 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00007028 E->getLocEnd());
7029 }
7030
7031#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7032 case OO_##Name:
7033#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7034#include "clang/Basic/OperatorKinds.def"
7035 case OO_Subscript:
7036 // Handled below.
7037 break;
7038
7039 case OO_Conditional:
7040 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007041
7042 case OO_None:
7043 case NUM_OVERLOADED_OPERATORS:
7044 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007045 }
7046
John McCall60d7b3a2010-08-24 06:29:42 +00007047 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007048 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007049 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007050
Richard Smithefeeccf2012-10-21 03:28:35 +00007051 ExprResult First;
7052 if (E->getOperator() == OO_Amp)
7053 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7054 else
7055 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007056 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007057 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007058
John McCall60d7b3a2010-08-24 06:29:42 +00007059 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007060 if (E->getNumArgs() == 2) {
7061 Second = getDerived().TransformExpr(E->getArg(1));
7062 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007063 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007064 }
Mike Stump1eb44332009-09-09 15:08:12 +00007065
Douglas Gregorb98b1992009-08-11 05:31:07 +00007066 if (!getDerived().AlwaysRebuild() &&
7067 Callee.get() == E->getCallee() &&
7068 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00007069 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00007070 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007071
Lang Hamesbe9af122012-10-02 04:45:10 +00007072 Sema::FPContractStateRAII FPContractState(getSema());
7073 getSema().FPFeatures.fp_contract = E->isFPContractable();
7074
Douglas Gregorb98b1992009-08-11 05:31:07 +00007075 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7076 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007077 Callee.get(),
7078 First.get(),
7079 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007080}
Mike Stump1eb44332009-09-09 15:08:12 +00007081
Douglas Gregorb98b1992009-08-11 05:31:07 +00007082template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007083ExprResult
John McCall454feb92009-12-08 09:21:05 +00007084TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7085 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007086}
Mike Stump1eb44332009-09-09 15:08:12 +00007087
Douglas Gregorb98b1992009-08-11 05:31:07 +00007088template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007089ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00007090TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7091 // Transform the callee.
7092 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7093 if (Callee.isInvalid())
7094 return ExprError();
7095
7096 // Transform exec config.
7097 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7098 if (EC.isInvalid())
7099 return ExprError();
7100
7101 // Transform arguments.
7102 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007103 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007104 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007105 &ArgChanged))
7106 return ExprError();
7107
7108 if (!getDerived().AlwaysRebuild() &&
7109 Callee.get() == E->getCallee() &&
7110 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007111 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00007112
7113 // FIXME: Wrong source location information for the '('.
7114 SourceLocation FakeLParenLoc
7115 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7116 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007117 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007118 E->getRParenLoc(), EC.get());
7119}
7120
7121template<typename Derived>
7122ExprResult
John McCall454feb92009-12-08 09:21:05 +00007123TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007124 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7125 if (!Type)
7126 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007127
John McCall60d7b3a2010-08-24 06:29:42 +00007128 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007129 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007130 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007131 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007132
Douglas Gregorb98b1992009-08-11 05:31:07 +00007133 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007134 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007135 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007136 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007137 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007138 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007139 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007140 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007141 E->getAngleBrackets().getEnd(),
7142 // FIXME. this should be '(' location
7143 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007144 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007145 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007146}
Mike Stump1eb44332009-09-09 15:08:12 +00007147
Douglas Gregorb98b1992009-08-11 05:31:07 +00007148template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007149ExprResult
John McCall454feb92009-12-08 09:21:05 +00007150TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7151 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007152}
Mike Stump1eb44332009-09-09 15:08:12 +00007153
7154template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007155ExprResult
John McCall454feb92009-12-08 09:21:05 +00007156TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7157 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007158}
7159
Douglas Gregorb98b1992009-08-11 05:31:07 +00007160template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007161ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007162TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007163 CXXReinterpretCastExpr *E) {
7164 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007165}
Mike Stump1eb44332009-09-09 15:08:12 +00007166
Douglas Gregorb98b1992009-08-11 05:31:07 +00007167template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007168ExprResult
John McCall454feb92009-12-08 09:21:05 +00007169TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7170 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007171}
Mike Stump1eb44332009-09-09 15:08:12 +00007172
Douglas Gregorb98b1992009-08-11 05:31:07 +00007173template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007174ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007175TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007176 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007177 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7178 if (!Type)
7179 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007180
John McCall60d7b3a2010-08-24 06:29:42 +00007181 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007182 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007183 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007184 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007185
Douglas Gregorb98b1992009-08-11 05:31:07 +00007186 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007187 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007188 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007189 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007190
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007191 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007192 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007193 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007194 E->getRParenLoc());
7195}
Mike Stump1eb44332009-09-09 15:08:12 +00007196
Douglas Gregorb98b1992009-08-11 05:31:07 +00007197template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007198ExprResult
John McCall454feb92009-12-08 09:21:05 +00007199TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007200 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007201 TypeSourceInfo *TInfo
7202 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7203 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007204 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007205
Douglas Gregorb98b1992009-08-11 05:31:07 +00007206 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007207 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007208 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007209
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007210 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7211 E->getLocStart(),
7212 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007213 E->getLocEnd());
7214 }
Mike Stump1eb44332009-09-09 15:08:12 +00007215
Eli Friedmanef331b72012-01-20 01:26:23 +00007216 // We don't know whether the subexpression is potentially evaluated until
7217 // after we perform semantic analysis. We speculatively assume it is
7218 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007219 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007220 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7221 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007222
John McCall60d7b3a2010-08-24 06:29:42 +00007223 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007224 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007225 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007226
Douglas Gregorb98b1992009-08-11 05:31:07 +00007227 if (!getDerived().AlwaysRebuild() &&
7228 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007229 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007230
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007231 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7232 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007233 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007234 E->getLocEnd());
7235}
7236
7237template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007238ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007239TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7240 if (E->isTypeOperand()) {
7241 TypeSourceInfo *TInfo
7242 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7243 if (!TInfo)
7244 return ExprError();
7245
7246 if (!getDerived().AlwaysRebuild() &&
7247 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007248 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007249
Douglas Gregor3c52a212011-03-06 17:40:41 +00007250 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007251 E->getLocStart(),
7252 TInfo,
7253 E->getLocEnd());
7254 }
7255
Francois Pichet01b7c302010-09-08 12:20:18 +00007256 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7257
7258 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7259 if (SubExpr.isInvalid())
7260 return ExprError();
7261
7262 if (!getDerived().AlwaysRebuild() &&
7263 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007264 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007265
7266 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7267 E->getLocStart(),
7268 SubExpr.get(),
7269 E->getLocEnd());
7270}
7271
7272template<typename Derived>
7273ExprResult
John McCall454feb92009-12-08 09:21:05 +00007274TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007275 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007276}
Mike Stump1eb44332009-09-09 15:08:12 +00007277
Douglas Gregorb98b1992009-08-11 05:31:07 +00007278template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007279ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007280TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007281 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007282 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007283}
Mike Stump1eb44332009-09-09 15:08:12 +00007284
Douglas Gregorb98b1992009-08-11 05:31:07 +00007285template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007286ExprResult
John McCall454feb92009-12-08 09:21:05 +00007287TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithcafeb942013-06-07 02:33:37 +00007288 QualType T = getSema().getCurrentThisType();
Mike Stump1eb44332009-09-09 15:08:12 +00007289
Douglas Gregorec79d872012-02-24 17:41:38 +00007290 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7291 // Make sure that we capture 'this'.
7292 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007293 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007294 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007295
Douglas Gregor828a1972010-01-07 23:12:05 +00007296 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007297}
Mike Stump1eb44332009-09-09 15:08:12 +00007298
Douglas Gregorb98b1992009-08-11 05:31:07 +00007299template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007300ExprResult
John McCall454feb92009-12-08 09:21:05 +00007301TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007302 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007303 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007304 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007305
Douglas Gregorb98b1992009-08-11 05:31:07 +00007306 if (!getDerived().AlwaysRebuild() &&
7307 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007308 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007309
Douglas Gregorbca01b42011-07-06 22:04:06 +00007310 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7311 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007312}
Mike Stump1eb44332009-09-09 15:08:12 +00007313
Douglas Gregorb98b1992009-08-11 05:31:07 +00007314template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007315ExprResult
John McCall454feb92009-12-08 09:21:05 +00007316TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007317 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007318 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7319 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007320 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007321 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007322
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007323 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007324 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007325 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007326
Douglas Gregor036aed12009-12-23 23:03:06 +00007327 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007328}
Mike Stump1eb44332009-09-09 15:08:12 +00007329
Douglas Gregorb98b1992009-08-11 05:31:07 +00007330template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007331ExprResult
Richard Smithc3bf52c2013-04-20 22:23:05 +00007332TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7333 FieldDecl *Field
7334 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7335 E->getField()));
7336 if (!Field)
7337 return ExprError();
7338
7339 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7340 return SemaRef.Owned(E);
7341
7342 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7343}
7344
7345template<typename Derived>
7346ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007347TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7348 CXXScalarValueInitExpr *E) {
7349 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7350 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007351 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007352
Douglas Gregorb98b1992009-08-11 05:31:07 +00007353 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007354 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007355 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007356
Chad Rosier4a9d7952012-08-08 18:46:20 +00007357 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007358 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007359 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007360}
Mike Stump1eb44332009-09-09 15:08:12 +00007361
Douglas Gregorb98b1992009-08-11 05:31:07 +00007362template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007363ExprResult
John McCall454feb92009-12-08 09:21:05 +00007364TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007365 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007366 TypeSourceInfo *AllocTypeInfo
7367 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7368 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007369 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007370
Douglas Gregorb98b1992009-08-11 05:31:07 +00007371 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007372 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007373 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007374 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007375
Douglas Gregorb98b1992009-08-11 05:31:07 +00007376 // Transform the placement arguments (if any).
7377 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007378 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007379 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007380 E->getNumPlacementArgs(), true,
7381 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007382 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007383
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007384 // Transform the initializer (if any).
7385 Expr *OldInit = E->getInitializer();
7386 ExprResult NewInit;
7387 if (OldInit)
7388 NewInit = getDerived().TransformExpr(OldInit);
7389 if (NewInit.isInvalid())
7390 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007391
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007392 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007393 FunctionDecl *OperatorNew = 0;
7394 if (E->getOperatorNew()) {
7395 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007396 getDerived().TransformDecl(E->getLocStart(),
7397 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007398 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007399 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007400 }
7401
7402 FunctionDecl *OperatorDelete = 0;
7403 if (E->getOperatorDelete()) {
7404 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007405 getDerived().TransformDecl(E->getLocStart(),
7406 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007407 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007408 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007409 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007410
Douglas Gregorb98b1992009-08-11 05:31:07 +00007411 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007412 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007413 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007414 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007415 OperatorNew == E->getOperatorNew() &&
7416 OperatorDelete == E->getOperatorDelete() &&
7417 !ArgumentChanged) {
7418 // Mark any declarations we need as referenced.
7419 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007420 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007421 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007422 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007423 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007424
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007425 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007426 QualType ElementType
7427 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7428 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7429 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7430 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007431 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007432 }
7433 }
7434 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007435
John McCall3fa5cae2010-10-26 07:05:15 +00007436 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007437 }
Mike Stump1eb44332009-09-09 15:08:12 +00007438
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007439 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007440 if (!ArraySize.get()) {
7441 // If no array size was specified, but the new expression was
7442 // instantiated with an array type (e.g., "new T" where T is
7443 // instantiated with "int[4]"), extract the outer bound from the
7444 // array type as our array size. We do this with constant and
7445 // dependently-sized array types.
7446 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7447 if (!ArrayT) {
7448 // Do nothing
7449 } else if (const ConstantArrayType *ConsArrayT
7450 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007451 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007452 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007453 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007454 SemaRef.Context.getSizeType(),
7455 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007456 AllocType = ConsArrayT->getElementType();
7457 } else if (const DependentSizedArrayType *DepArrayT
7458 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7459 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007460 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007461 AllocType = DepArrayT->getElementType();
7462 }
7463 }
7464 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007465
Douglas Gregorb98b1992009-08-11 05:31:07 +00007466 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7467 E->isGlobalNew(),
7468 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007469 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007470 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007471 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007472 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007473 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007474 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007475 E->getDirectInitRange(),
7476 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007477}
Mike Stump1eb44332009-09-09 15:08:12 +00007478
Douglas Gregorb98b1992009-08-11 05:31:07 +00007479template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007480ExprResult
John McCall454feb92009-12-08 09:21:05 +00007481TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007482 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007483 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007484 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007485
Douglas Gregor1af74512010-02-26 00:38:10 +00007486 // Transform the delete operator, if known.
7487 FunctionDecl *OperatorDelete = 0;
7488 if (E->getOperatorDelete()) {
7489 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007490 getDerived().TransformDecl(E->getLocStart(),
7491 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007492 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007493 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007494 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007495
Douglas Gregorb98b1992009-08-11 05:31:07 +00007496 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007497 Operand.get() == E->getArgument() &&
7498 OperatorDelete == E->getOperatorDelete()) {
7499 // Mark any declarations we need as referenced.
7500 // FIXME: instantiation-specific.
7501 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007502 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007503
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007504 if (!E->getArgument()->isTypeDependent()) {
7505 QualType Destroyed = SemaRef.Context.getBaseElementType(
7506 E->getDestroyedType());
7507 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7508 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007509 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007510 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007511 }
7512 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007513
John McCall3fa5cae2010-10-26 07:05:15 +00007514 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007515 }
Mike Stump1eb44332009-09-09 15:08:12 +00007516
Douglas Gregorb98b1992009-08-11 05:31:07 +00007517 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7518 E->isGlobalDelete(),
7519 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007520 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007521}
Mike Stump1eb44332009-09-09 15:08:12 +00007522
Douglas Gregorb98b1992009-08-11 05:31:07 +00007523template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007524ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007525TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007526 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007527 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007528 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007529 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007530
John McCallb3d87482010-08-24 05:47:05 +00007531 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007532 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007533 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007534 E->getOperatorLoc(),
7535 E->isArrow()? tok::arrow : tok::period,
7536 ObjectTypePtr,
7537 MayBePseudoDestructor);
7538 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007539 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007540
John McCallb3d87482010-08-24 05:47:05 +00007541 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007542 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7543 if (QualifierLoc) {
7544 QualifierLoc
7545 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7546 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007547 return ExprError();
7548 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007549 CXXScopeSpec SS;
7550 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007551
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007552 PseudoDestructorTypeStorage Destroyed;
7553 if (E->getDestroyedTypeInfo()) {
7554 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007555 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007556 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007557 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007558 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007559 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007560 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007561 // We aren't likely to be able to resolve the identifier down to a type
7562 // now anyway, so just retain the identifier.
7563 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7564 E->getDestroyedTypeLoc());
7565 } else {
7566 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007567 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007568 *E->getDestroyedTypeIdentifier(),
7569 E->getDestroyedTypeLoc(),
7570 /*Scope=*/0,
7571 SS, ObjectTypePtr,
7572 false);
7573 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007574 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007575
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007576 Destroyed
7577 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7578 E->getDestroyedTypeLoc());
7579 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007580
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007581 TypeSourceInfo *ScopeTypeInfo = 0;
7582 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007583 CXXScopeSpec EmptySS;
7584 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7585 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007586 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007587 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007588 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007589
John McCall9ae2f072010-08-23 23:25:46 +00007590 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007591 E->getOperatorLoc(),
7592 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007593 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007594 ScopeTypeInfo,
7595 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007596 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007597 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007598}
Mike Stump1eb44332009-09-09 15:08:12 +00007599
Douglas Gregora71d8192009-09-04 17:36:40 +00007600template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007601ExprResult
John McCallba135432009-11-21 08:51:07 +00007602TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007603 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007604 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7605 Sema::LookupOrdinaryName);
7606
7607 // Transform all the decls.
7608 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7609 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007610 NamedDecl *InstD = static_cast<NamedDecl*>(
7611 getDerived().TransformDecl(Old->getNameLoc(),
7612 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007613 if (!InstD) {
7614 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7615 // This can happen because of dependent hiding.
7616 if (isa<UsingShadowDecl>(*I))
7617 continue;
7618 else
John McCallf312b1e2010-08-26 23:41:50 +00007619 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007620 }
John McCallf7a1a742009-11-24 19:00:30 +00007621
7622 // Expand using declarations.
7623 if (isa<UsingDecl>(InstD)) {
7624 UsingDecl *UD = cast<UsingDecl>(InstD);
7625 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7626 E = UD->shadow_end(); I != E; ++I)
7627 R.addDecl(*I);
7628 continue;
7629 }
7630
7631 R.addDecl(InstD);
7632 }
7633
7634 // Resolve a kind, but don't do any further analysis. If it's
7635 // ambiguous, the callee needs to deal with it.
7636 R.resolveKind();
7637
7638 // Rebuild the nested-name qualifier, if present.
7639 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007640 if (Old->getQualifierLoc()) {
7641 NestedNameSpecifierLoc QualifierLoc
7642 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7643 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007644 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007645
Douglas Gregor4c9be892011-02-28 20:01:57 +00007646 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007647 }
7648
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007649 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007650 CXXRecordDecl *NamingClass
7651 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7652 Old->getNameLoc(),
7653 Old->getNamingClass()));
7654 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007655 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007656
Douglas Gregor66c45152010-04-27 16:10:10 +00007657 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007658 }
7659
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007660 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7661
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007662 // If we have neither explicit template arguments, nor the template keyword,
7663 // it's a normal declaration name.
7664 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007665 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7666
7667 // If we have template arguments, rebuild them, then rebuild the
7668 // templateid expression.
7669 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007670 if (Old->hasExplicitTemplateArgs() &&
7671 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007672 Old->getNumTemplateArgs(),
7673 TransArgs))
7674 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007675
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007676 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007677 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007678}
Mike Stump1eb44332009-09-09 15:08:12 +00007679
Douglas Gregorb98b1992009-08-11 05:31:07 +00007680template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007681ExprResult
John McCall454feb92009-12-08 09:21:05 +00007682TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007683 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7684 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007685 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007686
Douglas Gregorb98b1992009-08-11 05:31:07 +00007687 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007688 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007689 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007690
Mike Stump1eb44332009-09-09 15:08:12 +00007691 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007692 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007693 T,
7694 E->getLocEnd());
7695}
Mike Stump1eb44332009-09-09 15:08:12 +00007696
Douglas Gregorb98b1992009-08-11 05:31:07 +00007697template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007698ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007699TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7700 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7701 if (!LhsT)
7702 return ExprError();
7703
7704 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7705 if (!RhsT)
7706 return ExprError();
7707
7708 if (!getDerived().AlwaysRebuild() &&
7709 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7710 return SemaRef.Owned(E);
7711
7712 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7713 E->getLocStart(),
7714 LhsT, RhsT,
7715 E->getLocEnd());
7716}
7717
7718template<typename Derived>
7719ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007720TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7721 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007722 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007723 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7724 TypeSourceInfo *From = E->getArg(I);
7725 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007726 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007727 TypeLocBuilder TLB;
7728 TLB.reserve(FromTL.getFullDataSize());
7729 QualType To = getDerived().TransformType(TLB, FromTL);
7730 if (To.isNull())
7731 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007732
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007733 if (To == From->getType())
7734 Args.push_back(From);
7735 else {
7736 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7737 ArgChanged = true;
7738 }
7739 continue;
7740 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007741
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007742 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007743
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007744 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007745 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007746 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7747 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7748 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007749
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007750 // Determine whether the set of unexpanded parameter packs can and should
7751 // be expanded.
7752 bool Expand = true;
7753 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007754 Optional<unsigned> OrigNumExpansions =
7755 ExpansionTL.getTypePtr()->getNumExpansions();
7756 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007757 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7758 PatternTL.getSourceRange(),
7759 Unexpanded,
7760 Expand, RetainExpansion,
7761 NumExpansions))
7762 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007763
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007764 if (!Expand) {
7765 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007766 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007767 // expansion.
7768 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007769
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007770 TypeLocBuilder TLB;
7771 TLB.reserve(From->getTypeLoc().getFullDataSize());
7772
7773 QualType To = getDerived().TransformType(TLB, PatternTL);
7774 if (To.isNull())
7775 return ExprError();
7776
Chad Rosier4a9d7952012-08-08 18:46:20 +00007777 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007778 PatternTL.getSourceRange(),
7779 ExpansionTL.getEllipsisLoc(),
7780 NumExpansions);
7781 if (To.isNull())
7782 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007783
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007784 PackExpansionTypeLoc ToExpansionTL
7785 = TLB.push<PackExpansionTypeLoc>(To);
7786 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7787 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7788 continue;
7789 }
7790
7791 // Expand the pack expansion by substituting for each argument in the
7792 // pack(s).
7793 for (unsigned I = 0; I != *NumExpansions; ++I) {
7794 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7795 TypeLocBuilder TLB;
7796 TLB.reserve(PatternTL.getFullDataSize());
7797 QualType To = getDerived().TransformType(TLB, PatternTL);
7798 if (To.isNull())
7799 return ExprError();
7800
7801 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7802 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007803
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007804 if (!RetainExpansion)
7805 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007806
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007807 // If we're supposed to retain a pack expansion, do so by temporarily
7808 // forgetting the partially-substituted parameter pack.
7809 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7810
7811 TypeLocBuilder TLB;
7812 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007813
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007814 QualType To = getDerived().TransformType(TLB, PatternTL);
7815 if (To.isNull())
7816 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007817
7818 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007819 PatternTL.getSourceRange(),
7820 ExpansionTL.getEllipsisLoc(),
7821 NumExpansions);
7822 if (To.isNull())
7823 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007824
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007825 PackExpansionTypeLoc ToExpansionTL
7826 = TLB.push<PackExpansionTypeLoc>(To);
7827 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7828 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7829 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007830
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007831 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7832 return SemaRef.Owned(E);
7833
7834 return getDerived().RebuildTypeTrait(E->getTrait(),
7835 E->getLocStart(),
7836 Args,
7837 E->getLocEnd());
7838}
7839
7840template<typename Derived>
7841ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007842TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7843 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7844 if (!T)
7845 return ExprError();
7846
7847 if (!getDerived().AlwaysRebuild() &&
7848 T == E->getQueriedTypeSourceInfo())
7849 return SemaRef.Owned(E);
7850
7851 ExprResult SubExpr;
7852 {
7853 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7854 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7855 if (SubExpr.isInvalid())
7856 return ExprError();
7857
7858 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7859 return SemaRef.Owned(E);
7860 }
7861
7862 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7863 E->getLocStart(),
7864 T,
7865 SubExpr.get(),
7866 E->getLocEnd());
7867}
7868
7869template<typename Derived>
7870ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007871TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7872 ExprResult SubExpr;
7873 {
7874 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7875 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7876 if (SubExpr.isInvalid())
7877 return ExprError();
7878
7879 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7880 return SemaRef.Owned(E);
7881 }
7882
7883 return getDerived().RebuildExpressionTrait(
7884 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7885}
7886
7887template<typename Derived>
7888ExprResult
John McCall865d4472009-11-19 22:55:06 +00007889TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007890 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00007891 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
7892}
7893
7894template<typename Derived>
7895ExprResult
7896TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
7897 DependentScopeDeclRefExpr *E,
7898 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007899 NestedNameSpecifierLoc QualifierLoc
7900 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7901 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007902 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007903 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007904
John McCall43fed0d2010-11-12 08:19:04 +00007905 // TODO: If this is a conversion-function-id, verify that the
7906 // destination type name (if present) resolves the same way after
7907 // instantiation as it did in the local scope.
7908
Abramo Bagnara25777432010-08-11 22:01:17 +00007909 DeclarationNameInfo NameInfo
7910 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7911 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007912 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007913
John McCallf7a1a742009-11-24 19:00:30 +00007914 if (!E->hasExplicitTemplateArgs()) {
7915 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007916 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007917 // Note: it is sufficient to compare the Name component of NameInfo:
7918 // if name has not changed, DNLoc has not changed either.
7919 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007920 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007921
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007922 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007923 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007924 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007925 /*TemplateArgs*/ 0,
7926 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007927 }
John McCalld5532b62009-11-23 01:53:49 +00007928
7929 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007930 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7931 E->getNumTemplateArgs(),
7932 TransArgs))
7933 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007934
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007935 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007936 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007937 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007938 &TransArgs,
7939 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007940}
7941
7942template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007943ExprResult
John McCall454feb92009-12-08 09:21:05 +00007944TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00007945 // CXXConstructExprs other than for list-initialization and
7946 // CXXTemporaryObjectExpr are always implicit, so when we have
7947 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00007948 if ((E->getNumArgs() == 1 ||
7949 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00007950 (!getDerived().DropCallArgument(E->getArg(0))) &&
7951 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00007952 return getDerived().TransformExpr(E->getArg(0));
7953
Douglas Gregorb98b1992009-08-11 05:31:07 +00007954 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7955
7956 QualType T = getDerived().TransformType(E->getType());
7957 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007958 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007959
7960 CXXConstructorDecl *Constructor
7961 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007962 getDerived().TransformDecl(E->getLocStart(),
7963 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007964 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007965 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007966
Douglas Gregorb98b1992009-08-11 05:31:07 +00007967 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007968 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007969 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007970 &ArgumentChanged))
7971 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007972
Douglas Gregorb98b1992009-08-11 05:31:07 +00007973 if (!getDerived().AlwaysRebuild() &&
7974 T == E->getType() &&
7975 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007976 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007977 // Mark the constructor as referenced.
7978 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007979 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007980 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007981 }
Mike Stump1eb44332009-09-09 15:08:12 +00007982
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007983 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7984 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007985 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007986 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00007987 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007988 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007989 E->getConstructionKind(),
7990 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007991}
Mike Stump1eb44332009-09-09 15:08:12 +00007992
Douglas Gregorb98b1992009-08-11 05:31:07 +00007993/// \brief Transform a C++ temporary-binding expression.
7994///
Douglas Gregor51326552009-12-24 18:51:59 +00007995/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7996/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007997template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007998ExprResult
John McCall454feb92009-12-08 09:21:05 +00007999TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008000 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008001}
Mike Stump1eb44332009-09-09 15:08:12 +00008002
John McCall4765fa02010-12-06 08:20:24 +00008003/// \brief Transform a C++ expression that contains cleanups that should
8004/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008005///
John McCall4765fa02010-12-06 08:20:24 +00008006/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00008007/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00008008template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008009ExprResult
John McCall4765fa02010-12-06 08:20:24 +00008010TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00008011 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008012}
Mike Stump1eb44332009-09-09 15:08:12 +00008013
Douglas Gregorb98b1992009-08-11 05:31:07 +00008014template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008015ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008016TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00008017 CXXTemporaryObjectExpr *E) {
8018 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8019 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008020 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008021
Douglas Gregorb98b1992009-08-11 05:31:07 +00008022 CXXConstructorDecl *Constructor
8023 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008024 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008025 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008026 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008027 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008028
Douglas Gregorb98b1992009-08-11 05:31:07 +00008029 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008030 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00008031 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008032 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008033 &ArgumentChanged))
8034 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008035
Douglas Gregorb98b1992009-08-11 05:31:07 +00008036 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008037 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008038 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00008039 !ArgumentChanged) {
8040 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008041 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008042 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00008043 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008044
Richard Smithc83c2302012-12-19 01:39:02 +00008045 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00008046 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8047 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008048 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008049 E->getLocEnd());
8050}
Mike Stump1eb44332009-09-09 15:08:12 +00008051
Douglas Gregorb98b1992009-08-11 05:31:07 +00008052template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008053ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00008054TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00008055 // Transform the type of the lambda parameters and start the definition of
8056 // the lambda itself.
8057 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00008058 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00008059 if (!MethodTy)
8060 return ExprError();
8061
Eli Friedman8da8a662012-09-19 01:18:11 +00008062 // Create the local class that will describe the lambda.
8063 CXXRecordDecl *Class
8064 = getSema().createLambdaClosureType(E->getIntroducerRange(),
8065 MethodTy,
8066 /*KnownDependent=*/false);
8067 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8068
Douglas Gregorc6889e72012-02-14 22:28:59 +00008069 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008070 SmallVector<QualType, 4> ParamTypes;
8071 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00008072 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
8073 E->getCallOperator()->param_begin(),
8074 E->getCallOperator()->param_size(),
8075 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00008076 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00008077
Douglas Gregordfca6f52012-02-13 22:00:16 +00008078 // Build the call operator.
8079 CXXMethodDecl *CallOperator
8080 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008081 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00008082 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008083 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008084 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00008085
Richard Smith612409e2012-07-25 03:56:55 +00008086 return getDerived().TransformLambdaScope(E, CallOperator);
8087}
8088
8089template<typename Derived>
8090ExprResult
8091TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8092 CXXMethodDecl *CallOperator) {
Richard Smith0d8e9642013-05-16 06:20:58 +00008093 bool Invalid = false;
8094
8095 // Transform any init-capture expressions before entering the scope of the
8096 // lambda.
8097 llvm::SmallVector<ExprResult, 8> InitCaptureExprs;
8098 InitCaptureExprs.resize(E->explicit_capture_end() -
8099 E->explicit_capture_begin());
8100 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8101 CEnd = E->capture_end();
8102 C != CEnd; ++C) {
8103 if (!C->isInitCapture())
8104 continue;
8105 InitCaptureExprs[C - E->capture_begin()] =
8106 getDerived().TransformExpr(E->getInitCaptureInit(C));
8107 }
8108
Douglas Gregord5387e82012-02-14 00:00:48 +00008109 // Introduce the context of the call operator.
8110 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8111
Douglas Gregordfca6f52012-02-13 22:00:16 +00008112 // Enter the scope of the lambda.
8113 sema::LambdaScopeInfo *LSI
8114 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
8115 E->getCaptureDefault(),
8116 E->hasExplicitParameters(),
8117 E->hasExplicitResultType(),
8118 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008119
Douglas Gregordfca6f52012-02-13 22:00:16 +00008120 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00008121 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008122 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008123 CEnd = E->capture_end();
8124 C != CEnd; ++C) {
8125 // When we hit the first implicit capture, tell Sema that we've finished
8126 // the list of explicit captures.
8127 if (!FinishedExplicitCaptures && C->isImplicit()) {
8128 getSema().finishLambdaExplicitCaptures(LSI);
8129 FinishedExplicitCaptures = true;
8130 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008131
Douglas Gregordfca6f52012-02-13 22:00:16 +00008132 // Capturing 'this' is trivial.
8133 if (C->capturesThis()) {
8134 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8135 continue;
8136 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008137
Richard Smith0d8e9642013-05-16 06:20:58 +00008138 // Rebuild init-captures, including the implied field declaration.
8139 if (C->isInitCapture()) {
8140 ExprResult Init = InitCaptureExprs[C - E->capture_begin()];
8141 if (Init.isInvalid()) {
8142 Invalid = true;
8143 continue;
8144 }
8145 FieldDecl *OldFD = C->getInitCaptureField();
8146 FieldDecl *NewFD = getSema().checkInitCapture(
8147 C->getLocation(), OldFD->getType()->isReferenceType(),
8148 OldFD->getIdentifier(), Init.take());
8149 if (!NewFD)
8150 Invalid = true;
8151 else
8152 getDerived().transformedLocalDecl(OldFD, NewFD);
8153 continue;
8154 }
8155
8156 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8157
Douglas Gregora7365242012-02-14 19:27:52 +00008158 // Determine the capture kind for Sema.
8159 Sema::TryCaptureKind Kind
8160 = C->isImplicit()? Sema::TryCapture_Implicit
8161 : C->getCaptureKind() == LCK_ByCopy
8162 ? Sema::TryCapture_ExplicitByVal
8163 : Sema::TryCapture_ExplicitByRef;
8164 SourceLocation EllipsisLoc;
8165 if (C->isPackExpansion()) {
8166 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8167 bool ShouldExpand = false;
8168 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008169 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008170 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8171 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008172 Unexpanded,
8173 ShouldExpand, RetainExpansion,
Richard Smith0d8e9642013-05-16 06:20:58 +00008174 NumExpansions)) {
8175 Invalid = true;
8176 continue;
8177 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008178
Douglas Gregora7365242012-02-14 19:27:52 +00008179 if (ShouldExpand) {
8180 // The transform has determined that we should perform an expansion;
8181 // transform and capture each of the arguments.
8182 // expansion of the pattern. Do so.
8183 VarDecl *Pack = C->getCapturedVar();
8184 for (unsigned I = 0; I != *NumExpansions; ++I) {
8185 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8186 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008187 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008188 Pack));
8189 if (!CapturedVar) {
8190 Invalid = true;
8191 continue;
8192 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008193
Douglas Gregora7365242012-02-14 19:27:52 +00008194 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008195 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8196 }
Douglas Gregora7365242012-02-14 19:27:52 +00008197 continue;
8198 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008199
Douglas Gregora7365242012-02-14 19:27:52 +00008200 EllipsisLoc = C->getEllipsisLoc();
8201 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008202
Douglas Gregordfca6f52012-02-13 22:00:16 +00008203 // Transform the captured variable.
8204 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008205 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008206 C->getCapturedVar()));
8207 if (!CapturedVar) {
8208 Invalid = true;
8209 continue;
8210 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008211
Douglas Gregordfca6f52012-02-13 22:00:16 +00008212 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008213 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008214 }
8215 if (!FinishedExplicitCaptures)
8216 getSema().finishLambdaExplicitCaptures(LSI);
8217
Douglas Gregordfca6f52012-02-13 22:00:16 +00008218
8219 // Enter a new evaluation context to insulate the lambda from any
8220 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008221 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008222
8223 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008224 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008225 /*IsInstantiation=*/true);
8226 return ExprError();
8227 }
8228
8229 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008230 StmtResult Body = getDerived().TransformStmt(E->getBody());
8231 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008232 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008233 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008234 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008235 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008236
Chad Rosier4a9d7952012-08-08 18:46:20 +00008237 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008238 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008239}
8240
8241template<typename Derived>
8242ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008243TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008244 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008245 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8246 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008247 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008248
Douglas Gregorb98b1992009-08-11 05:31:07 +00008249 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008250 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008251 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008252 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008253 &ArgumentChanged))
8254 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008255
Douglas Gregorb98b1992009-08-11 05:31:07 +00008256 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008257 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008258 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008259 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008260
Douglas Gregorb98b1992009-08-11 05:31:07 +00008261 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008262 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008263 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008264 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008265 E->getRParenLoc());
8266}
Mike Stump1eb44332009-09-09 15:08:12 +00008267
Douglas Gregorb98b1992009-08-11 05:31:07 +00008268template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008269ExprResult
John McCall865d4472009-11-19 22:55:06 +00008270TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008271 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008272 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008273 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008274 Expr *OldBase;
8275 QualType BaseType;
8276 QualType ObjectType;
8277 if (!E->isImplicitAccess()) {
8278 OldBase = E->getBase();
8279 Base = getDerived().TransformExpr(OldBase);
8280 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008281 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008282
John McCallaa81e162009-12-01 22:10:20 +00008283 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008284 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008285 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008286 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008287 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008288 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008289 ObjectTy,
8290 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008291 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008292 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008293
John McCallb3d87482010-08-24 05:47:05 +00008294 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008295 BaseType = ((Expr*) Base.get())->getType();
8296 } else {
8297 OldBase = 0;
8298 BaseType = getDerived().TransformType(E->getBaseType());
8299 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8300 }
Mike Stump1eb44332009-09-09 15:08:12 +00008301
Douglas Gregor6cd21982009-10-20 05:58:46 +00008302 // Transform the first part of the nested-name-specifier that qualifies
8303 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008304 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008305 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008306 E->getFirstQualifierFoundInScope(),
8307 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008308
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008309 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008310 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008311 QualifierLoc
8312 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8313 ObjectType,
8314 FirstQualifierInScope);
8315 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008316 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008317 }
Mike Stump1eb44332009-09-09 15:08:12 +00008318
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008319 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8320
John McCall43fed0d2010-11-12 08:19:04 +00008321 // TODO: If this is a conversion-function-id, verify that the
8322 // destination type name (if present) resolves the same way after
8323 // instantiation as it did in the local scope.
8324
Abramo Bagnara25777432010-08-11 22:01:17 +00008325 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008326 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008327 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008328 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008329
John McCallaa81e162009-12-01 22:10:20 +00008330 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008331 // This is a reference to a member without an explicitly-specified
8332 // template argument list. Optimize for this common case.
8333 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008334 Base.get() == OldBase &&
8335 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008336 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008337 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008338 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008339 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008340
John McCall9ae2f072010-08-23 23:25:46 +00008341 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008342 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008343 E->isArrow(),
8344 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008345 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008346 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008347 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008348 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008349 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008350 }
8351
John McCalld5532b62009-11-23 01:53:49 +00008352 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008353 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8354 E->getNumTemplateArgs(),
8355 TransArgs))
8356 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008357
John McCall9ae2f072010-08-23 23:25:46 +00008358 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008359 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008360 E->isArrow(),
8361 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008362 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008363 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008364 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008365 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008366 &TransArgs);
8367}
8368
8369template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008370ExprResult
John McCall454feb92009-12-08 09:21:05 +00008371TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008372 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008373 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008374 QualType BaseType;
8375 if (!Old->isImplicitAccess()) {
8376 Base = getDerived().TransformExpr(Old->getBase());
8377 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008378 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008379 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8380 Old->isArrow());
8381 if (Base.isInvalid())
8382 return ExprError();
8383 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008384 } else {
8385 BaseType = getDerived().TransformType(Old->getBaseType());
8386 }
John McCall129e2df2009-11-30 22:42:35 +00008387
Douglas Gregor4c9be892011-02-28 20:01:57 +00008388 NestedNameSpecifierLoc QualifierLoc;
8389 if (Old->getQualifierLoc()) {
8390 QualifierLoc
8391 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8392 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008393 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008394 }
8395
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008396 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8397
Abramo Bagnara25777432010-08-11 22:01:17 +00008398 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008399 Sema::LookupOrdinaryName);
8400
8401 // Transform all the decls.
8402 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8403 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008404 NamedDecl *InstD = static_cast<NamedDecl*>(
8405 getDerived().TransformDecl(Old->getMemberLoc(),
8406 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008407 if (!InstD) {
8408 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8409 // This can happen because of dependent hiding.
8410 if (isa<UsingShadowDecl>(*I))
8411 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008412 else {
8413 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008414 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008415 }
John McCall9f54ad42009-12-10 09:41:52 +00008416 }
John McCall129e2df2009-11-30 22:42:35 +00008417
8418 // Expand using declarations.
8419 if (isa<UsingDecl>(InstD)) {
8420 UsingDecl *UD = cast<UsingDecl>(InstD);
8421 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8422 E = UD->shadow_end(); I != E; ++I)
8423 R.addDecl(*I);
8424 continue;
8425 }
8426
8427 R.addDecl(InstD);
8428 }
8429
8430 R.resolveKind();
8431
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008432 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008433 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008434 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008435 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008436 Old->getMemberLoc(),
8437 Old->getNamingClass()));
8438 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008439 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008440
Douglas Gregor66c45152010-04-27 16:10:10 +00008441 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008442 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008443
John McCall129e2df2009-11-30 22:42:35 +00008444 TemplateArgumentListInfo TransArgs;
8445 if (Old->hasExplicitTemplateArgs()) {
8446 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8447 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008448 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8449 Old->getNumTemplateArgs(),
8450 TransArgs))
8451 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008452 }
John McCallc2233c52010-01-15 08:34:02 +00008453
8454 // FIXME: to do this check properly, we will need to preserve the
8455 // first-qualifier-in-scope here, just in case we had a dependent
8456 // base (and therefore couldn't do the check) and a
8457 // nested-name-qualifier (and therefore could do the lookup).
8458 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008459
John McCall9ae2f072010-08-23 23:25:46 +00008460 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008461 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008462 Old->getOperatorLoc(),
8463 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008464 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008465 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008466 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008467 R,
8468 (Old->hasExplicitTemplateArgs()
8469 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008470}
8471
8472template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008473ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008474TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008475 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008476 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8477 if (SubExpr.isInvalid())
8478 return ExprError();
8479
8480 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008481 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008482
8483 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8484}
8485
8486template<typename Derived>
8487ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008488TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008489 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8490 if (Pattern.isInvalid())
8491 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008492
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008493 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8494 return SemaRef.Owned(E);
8495
Douglas Gregor67fd1252011-01-14 21:20:45 +00008496 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8497 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008498}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008499
8500template<typename Derived>
8501ExprResult
8502TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8503 // If E is not value-dependent, then nothing will change when we transform it.
8504 // Note: This is an instantiation-centric view.
8505 if (!E->isValueDependent())
8506 return SemaRef.Owned(E);
8507
8508 // Note: None of the implementations of TryExpandParameterPacks can ever
8509 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008510 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008511 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8512 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008513 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008514 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008515 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008516 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008517 ShouldExpand, RetainExpansion,
8518 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008519 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008520
Douglas Gregor089e8932011-10-10 18:59:29 +00008521 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008522 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008523
Douglas Gregor089e8932011-10-10 18:59:29 +00008524 NamedDecl *Pack = E->getPack();
8525 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008526 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008527 Pack));
8528 if (!Pack)
8529 return ExprError();
8530 }
8531
Chad Rosier4a9d7952012-08-08 18:46:20 +00008532
Douglas Gregoree8aff02011-01-04 17:33:58 +00008533 // We now know the length of the parameter pack, so build a new expression
8534 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008535 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8536 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008537 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008538}
8539
Douglas Gregorbe230c32011-01-03 17:17:50 +00008540template<typename Derived>
8541ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008542TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8543 SubstNonTypeTemplateParmPackExpr *E) {
8544 // Default behavior is to do nothing with this transformation.
8545 return SemaRef.Owned(E);
8546}
8547
8548template<typename Derived>
8549ExprResult
John McCall91a57552011-07-15 05:09:51 +00008550TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8551 SubstNonTypeTemplateParmExpr *E) {
8552 // Default behavior is to do nothing with this transformation.
8553 return SemaRef.Owned(E);
8554}
8555
8556template<typename Derived>
8557ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008558TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8559 // Default behavior is to do nothing with this transformation.
8560 return SemaRef.Owned(E);
8561}
8562
8563template<typename Derived>
8564ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008565TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8566 MaterializeTemporaryExpr *E) {
8567 return getDerived().TransformExpr(E->GetTemporaryExpr());
8568}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008569
Douglas Gregor03e80032011-06-21 17:03:29 +00008570template<typename Derived>
8571ExprResult
Richard Smith7c3e6152013-06-12 22:31:48 +00008572TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8573 CXXStdInitializerListExpr *E) {
8574 return getDerived().TransformExpr(E->getSubExpr());
8575}
8576
8577template<typename Derived>
8578ExprResult
John McCall454feb92009-12-08 09:21:05 +00008579TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008580 return SemaRef.MaybeBindToTemporary(E);
8581}
8582
8583template<typename Derived>
8584ExprResult
8585TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008586 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008587}
8588
8589template<typename Derived>
8590ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008591TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8592 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8593 if (SubExpr.isInvalid())
8594 return ExprError();
8595
8596 if (!getDerived().AlwaysRebuild() &&
8597 SubExpr.get() == E->getSubExpr())
8598 return SemaRef.Owned(E);
8599
8600 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008601}
8602
8603template<typename Derived>
8604ExprResult
8605TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8606 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008607 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008608 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008609 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008610 /*IsCall=*/false, Elements, &ArgChanged))
8611 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008612
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008613 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8614 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008615
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008616 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8617 Elements.data(),
8618 Elements.size());
8619}
8620
8621template<typename Derived>
8622ExprResult
8623TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008624 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008625 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008626 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008627 bool ArgChanged = false;
8628 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8629 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008630
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008631 if (OrigElement.isPackExpansion()) {
8632 // This key/value element is a pack expansion.
8633 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8634 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8635 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8636 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8637
8638 // Determine whether the set of unexpanded parameter packs can
8639 // and should be expanded.
8640 bool Expand = true;
8641 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008642 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8643 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008644 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8645 OrigElement.Value->getLocEnd());
8646 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8647 PatternRange,
8648 Unexpanded,
8649 Expand, RetainExpansion,
8650 NumExpansions))
8651 return ExprError();
8652
8653 if (!Expand) {
8654 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008655 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008656 // expansion.
8657 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8658 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8659 if (Key.isInvalid())
8660 return ExprError();
8661
8662 if (Key.get() != OrigElement.Key)
8663 ArgChanged = true;
8664
8665 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8666 if (Value.isInvalid())
8667 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008668
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008669 if (Value.get() != OrigElement.Value)
8670 ArgChanged = true;
8671
Chad Rosier4a9d7952012-08-08 18:46:20 +00008672 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008673 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8674 };
8675 Elements.push_back(Expansion);
8676 continue;
8677 }
8678
8679 // Record right away that the argument was changed. This needs
8680 // to happen even if the array expands to nothing.
8681 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008682
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008683 // The transform has determined that we should perform an elementwise
8684 // expansion of the pattern. Do so.
8685 for (unsigned I = 0; I != *NumExpansions; ++I) {
8686 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8687 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8688 if (Key.isInvalid())
8689 return ExprError();
8690
8691 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8692 if (Value.isInvalid())
8693 return ExprError();
8694
Chad Rosier4a9d7952012-08-08 18:46:20 +00008695 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008696 Key.get(), Value.get(), SourceLocation(), NumExpansions
8697 };
8698
8699 // If any unexpanded parameter packs remain, we still have a
8700 // pack expansion.
8701 if (Key.get()->containsUnexpandedParameterPack() ||
8702 Value.get()->containsUnexpandedParameterPack())
8703 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008704
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008705 Elements.push_back(Element);
8706 }
8707
8708 // We've finished with this pack expansion.
8709 continue;
8710 }
8711
8712 // Transform and check key.
8713 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8714 if (Key.isInvalid())
8715 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008716
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008717 if (Key.get() != OrigElement.Key)
8718 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008719
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008720 // Transform and check value.
8721 ExprResult Value
8722 = getDerived().TransformExpr(OrigElement.Value);
8723 if (Value.isInvalid())
8724 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008725
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008726 if (Value.get() != OrigElement.Value)
8727 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008728
8729 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00008730 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008731 };
8732 Elements.push_back(Element);
8733 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008734
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008735 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8736 return SemaRef.MaybeBindToTemporary(E);
8737
8738 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8739 Elements.data(),
8740 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008741}
8742
Mike Stump1eb44332009-09-09 15:08:12 +00008743template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008744ExprResult
John McCall454feb92009-12-08 09:21:05 +00008745TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008746 TypeSourceInfo *EncodedTypeInfo
8747 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8748 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008749 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008750
Douglas Gregorb98b1992009-08-11 05:31:07 +00008751 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008752 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008753 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008754
8755 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008756 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008757 E->getRParenLoc());
8758}
Mike Stump1eb44332009-09-09 15:08:12 +00008759
Douglas Gregorb98b1992009-08-11 05:31:07 +00008760template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008761ExprResult TreeTransform<Derived>::
8762TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCall93b64572013-04-11 02:14:26 +00008763 // This is a kind of implicit conversion, and it needs to get dropped
8764 // and recomputed for the same general reasons that ImplicitCastExprs
8765 // do, as well a more specific one: this expression is only valid when
8766 // it appears *immediately* as an argument expression.
8767 return getDerived().TransformExpr(E->getSubExpr());
John McCallf85e1932011-06-15 23:02:42 +00008768}
8769
8770template<typename Derived>
8771ExprResult TreeTransform<Derived>::
8772TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008773 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008774 = getDerived().TransformType(E->getTypeInfoAsWritten());
8775 if (!TSInfo)
8776 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008777
John McCallf85e1932011-06-15 23:02:42 +00008778 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008779 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008780 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008781
John McCallf85e1932011-06-15 23:02:42 +00008782 if (!getDerived().AlwaysRebuild() &&
8783 TSInfo == E->getTypeInfoAsWritten() &&
8784 Result.get() == E->getSubExpr())
8785 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008786
John McCallf85e1932011-06-15 23:02:42 +00008787 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008788 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008789 Result.get());
8790}
8791
8792template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008793ExprResult
John McCall454feb92009-12-08 09:21:05 +00008794TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008795 // Transform arguments.
8796 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008797 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008798 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008799 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008800 &ArgChanged))
8801 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008802
Douglas Gregor92e986e2010-04-22 16:44:27 +00008803 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8804 // Class message: transform the receiver type.
8805 TypeSourceInfo *ReceiverTypeInfo
8806 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8807 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008808 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008809
Douglas Gregor92e986e2010-04-22 16:44:27 +00008810 // If nothing changed, just retain the existing message send.
8811 if (!getDerived().AlwaysRebuild() &&
8812 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008813 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008814
8815 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008816 SmallVector<SourceLocation, 16> SelLocs;
8817 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008818 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8819 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008820 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008821 E->getMethodDecl(),
8822 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008823 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008824 E->getRightLoc());
8825 }
8826
8827 // Instance message: transform the receiver
8828 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8829 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008830 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008831 = getDerived().TransformExpr(E->getInstanceReceiver());
8832 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008833 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008834
8835 // If nothing changed, just retain the existing message send.
8836 if (!getDerived().AlwaysRebuild() &&
8837 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008838 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008839
Douglas Gregor92e986e2010-04-22 16:44:27 +00008840 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008841 SmallVector<SourceLocation, 16> SelLocs;
8842 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008843 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008844 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008845 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008846 E->getMethodDecl(),
8847 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008848 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008849 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008850}
8851
Mike Stump1eb44332009-09-09 15:08:12 +00008852template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008853ExprResult
John McCall454feb92009-12-08 09:21:05 +00008854TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008855 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008856}
8857
Mike Stump1eb44332009-09-09 15:08:12 +00008858template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008859ExprResult
John McCall454feb92009-12-08 09:21:05 +00008860TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008861 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008862}
8863
Mike Stump1eb44332009-09-09 15:08:12 +00008864template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008865ExprResult
John McCall454feb92009-12-08 09:21:05 +00008866TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008867 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008868 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008869 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008870 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008871
8872 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008873
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008874 // If nothing changed, just retain the existing expression.
8875 if (!getDerived().AlwaysRebuild() &&
8876 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008877 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008878
John McCall9ae2f072010-08-23 23:25:46 +00008879 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008880 E->getLocation(),
8881 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008882}
8883
Mike Stump1eb44332009-09-09 15:08:12 +00008884template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008885ExprResult
John McCall454feb92009-12-08 09:21:05 +00008886TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008887 // 'super' and types never change. Property never changes. Just
8888 // retain the existing expression.
8889 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008890 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008891
Douglas Gregore3303542010-04-26 20:47:02 +00008892 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008893 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008894 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008895 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008896
Douglas Gregore3303542010-04-26 20:47:02 +00008897 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008898
Douglas Gregore3303542010-04-26 20:47:02 +00008899 // If nothing changed, just retain the existing expression.
8900 if (!getDerived().AlwaysRebuild() &&
8901 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008902 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008903
John McCall12f78a62010-12-02 01:19:52 +00008904 if (E->isExplicitProperty())
8905 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8906 E->getExplicitProperty(),
8907 E->getLocation());
8908
8909 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008910 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008911 E->getImplicitPropertyGetter(),
8912 E->getImplicitPropertySetter(),
8913 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008914}
8915
Mike Stump1eb44332009-09-09 15:08:12 +00008916template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008917ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008918TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8919 // Transform the base expression.
8920 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8921 if (Base.isInvalid())
8922 return ExprError();
8923
8924 // Transform the key expression.
8925 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8926 if (Key.isInvalid())
8927 return ExprError();
8928
8929 // If nothing changed, just retain the existing expression.
8930 if (!getDerived().AlwaysRebuild() &&
8931 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8932 return SemaRef.Owned(E);
8933
Chad Rosier4a9d7952012-08-08 18:46:20 +00008934 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008935 Base.get(), Key.get(),
8936 E->getAtIndexMethodDecl(),
8937 E->setAtIndexMethodDecl());
8938}
8939
8940template<typename Derived>
8941ExprResult
John McCall454feb92009-12-08 09:21:05 +00008942TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008943 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008944 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008945 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008946 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008947
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008948 // If nothing changed, just retain the existing expression.
8949 if (!getDerived().AlwaysRebuild() &&
8950 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008951 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008952
John McCall9ae2f072010-08-23 23:25:46 +00008953 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00008954 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008955 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008956}
8957
Mike Stump1eb44332009-09-09 15:08:12 +00008958template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008959ExprResult
John McCall454feb92009-12-08 09:21:05 +00008960TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008961 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008962 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008963 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008964 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008965 SubExprs, &ArgumentChanged))
8966 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008967
Douglas Gregorb98b1992009-08-11 05:31:07 +00008968 if (!getDerived().AlwaysRebuild() &&
8969 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008970 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008971
Douglas Gregorb98b1992009-08-11 05:31:07 +00008972 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008973 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008974 E->getRParenLoc());
8975}
8976
Mike Stump1eb44332009-09-09 15:08:12 +00008977template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008978ExprResult
John McCall454feb92009-12-08 09:21:05 +00008979TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008980 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008981
John McCallc6ac9c32011-02-04 18:33:18 +00008982 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8983 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8984
8985 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008986 blockScope->TheDecl->setBlockMissingReturnType(
8987 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008988
Chris Lattner686775d2011-07-20 06:58:45 +00008989 SmallVector<ParmVarDecl*, 4> params;
8990 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008991
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008992 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008993 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8994 oldBlock->param_begin(),
8995 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008996 0, paramTypes, &params)) {
8997 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008998 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008999 }
John McCallc6ac9c32011-02-04 18:33:18 +00009000
Jordan Rose09189892013-03-08 22:25:36 +00009001 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00009002 QualType exprResultType =
9003 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00009004
Jordan Rosebea522f2013-03-08 21:51:21 +00009005 QualType functionType =
9006 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009007 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00009008 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00009009
9010 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00009011 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00009012 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00009013
9014 if (!oldBlock->blockMissingReturnType()) {
9015 blockScope->HasImplicitReturnType = false;
9016 blockScope->ReturnType = exprResultType;
9017 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00009018
John McCall711c52b2011-01-05 12:14:39 +00009019 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00009020 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009021 if (body.isInvalid()) {
9022 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00009023 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009024 }
John McCall711c52b2011-01-05 12:14:39 +00009025
John McCallc6ac9c32011-02-04 18:33:18 +00009026#ifndef NDEBUG
9027 // In builds with assertions, make sure that we captured everything we
9028 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00009029 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9030 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9031 e = oldBlock->capture_end(); i != e; ++i) {
9032 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00009033
Douglas Gregorfc921372011-05-20 15:32:55 +00009034 // Ignore parameter packs.
9035 if (isa<ParmVarDecl>(oldCapture) &&
9036 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9037 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00009038
Douglas Gregorfc921372011-05-20 15:32:55 +00009039 VarDecl *newCapture =
9040 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9041 oldCapture));
9042 assert(blockScope->CaptureMap.count(newCapture));
9043 }
Douglas Gregorec79d872012-02-24 17:41:38 +00009044 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00009045 }
9046#endif
9047
9048 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9049 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009050}
9051
Mike Stump1eb44332009-09-09 15:08:12 +00009052template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009053ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009054TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00009055 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009056}
Eli Friedman276b0612011-10-11 02:20:01 +00009057
9058template<typename Derived>
9059ExprResult
9060TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009061 QualType RetTy = getDerived().TransformType(E->getType());
9062 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009063 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009064 SubExprs.reserve(E->getNumSubExprs());
9065 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9066 SubExprs, &ArgumentChanged))
9067 return ExprError();
9068
9069 if (!getDerived().AlwaysRebuild() &&
9070 !ArgumentChanged)
9071 return SemaRef.Owned(E);
9072
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009073 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009074 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00009075}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009076
Douglas Gregorb98b1992009-08-11 05:31:07 +00009077//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00009078// Type reconstruction
9079//===----------------------------------------------------------------------===//
9080
Mike Stump1eb44332009-09-09 15:08:12 +00009081template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009082QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9083 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009084 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009085 getDerived().getBaseEntity());
9086}
9087
Mike Stump1eb44332009-09-09 15:08:12 +00009088template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009089QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9090 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009091 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009092 getDerived().getBaseEntity());
9093}
9094
Mike Stump1eb44332009-09-09 15:08:12 +00009095template<typename Derived>
9096QualType
John McCall85737a72009-10-30 00:06:24 +00009097TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9098 bool WrittenAsLValue,
9099 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009100 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00009101 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009102}
9103
9104template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009105QualType
John McCall85737a72009-10-30 00:06:24 +00009106TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9107 QualType ClassType,
9108 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009109 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00009110 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009111}
9112
9113template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009114QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00009115TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9116 ArrayType::ArraySizeModifier SizeMod,
9117 const llvm::APInt *Size,
9118 Expr *SizeExpr,
9119 unsigned IndexTypeQuals,
9120 SourceRange BracketsRange) {
9121 if (SizeExpr || !Size)
9122 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9123 IndexTypeQuals, BracketsRange,
9124 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00009125
9126 QualType Types[] = {
9127 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9128 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9129 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00009130 };
9131 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
9132 QualType SizeType;
9133 for (unsigned I = 0; I != NumTypes; ++I)
9134 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9135 SizeType = Types[I];
9136 break;
9137 }
Mike Stump1eb44332009-09-09 15:08:12 +00009138
Eli Friedman01f276d2012-01-25 23:20:27 +00009139 // Note that we can return a VariableArrayType here in the case where
9140 // the element type was a dependent VariableArrayType.
9141 IntegerLiteral *ArraySize
9142 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9143 /*FIXME*/BracketsRange.getBegin());
9144 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009145 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00009146 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009147}
Mike Stump1eb44332009-09-09 15:08:12 +00009148
Douglas Gregor577f75a2009-08-04 16:50:30 +00009149template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009150QualType
9151TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009152 ArrayType::ArraySizeModifier SizeMod,
9153 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009154 unsigned IndexTypeQuals,
9155 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009156 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009157 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009158}
9159
9160template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009161QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009162TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009163 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009164 unsigned IndexTypeQuals,
9165 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009166 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009167 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009168}
Mike Stump1eb44332009-09-09 15:08:12 +00009169
Douglas Gregor577f75a2009-08-04 16:50:30 +00009170template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009171QualType
9172TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009173 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009174 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009175 unsigned IndexTypeQuals,
9176 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009177 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009178 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009179 IndexTypeQuals, BracketsRange);
9180}
9181
9182template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009183QualType
9184TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009185 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009186 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009187 unsigned IndexTypeQuals,
9188 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009189 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009190 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009191 IndexTypeQuals, BracketsRange);
9192}
9193
9194template<typename Derived>
9195QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009196 unsigned NumElements,
9197 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009198 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009199 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009200}
Mike Stump1eb44332009-09-09 15:08:12 +00009201
Douglas Gregor577f75a2009-08-04 16:50:30 +00009202template<typename Derived>
9203QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9204 unsigned NumElements,
9205 SourceLocation AttributeLoc) {
9206 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9207 NumElements, true);
9208 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009209 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9210 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009211 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009212}
Mike Stump1eb44332009-09-09 15:08:12 +00009213
Douglas Gregor577f75a2009-08-04 16:50:30 +00009214template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009215QualType
9216TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009217 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009218 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009219 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009220}
Mike Stump1eb44332009-09-09 15:08:12 +00009221
Douglas Gregor577f75a2009-08-04 16:50:30 +00009222template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009223QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9224 QualType T,
9225 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009226 const FunctionProtoType::ExtProtoInfo &EPI) {
9227 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009228 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009229 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009230 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009231}
Mike Stump1eb44332009-09-09 15:08:12 +00009232
Douglas Gregor577f75a2009-08-04 16:50:30 +00009233template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009234QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9235 return SemaRef.Context.getFunctionNoProtoType(T);
9236}
9237
9238template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009239QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9240 assert(D && "no decl found");
9241 if (D->isInvalidDecl()) return QualType();
9242
Douglas Gregor92e986e2010-04-22 16:44:27 +00009243 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009244 TypeDecl *Ty;
9245 if (isa<UsingDecl>(D)) {
9246 UsingDecl *Using = cast<UsingDecl>(D);
9247 assert(Using->isTypeName() &&
9248 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9249
9250 // A valid resolved using typename decl points to exactly one type decl.
9251 assert(++Using->shadow_begin() == Using->shadow_end());
9252 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009253
John McCalled976492009-12-04 22:46:56 +00009254 } else {
9255 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9256 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9257 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9258 }
9259
9260 return SemaRef.Context.getTypeDeclType(Ty);
9261}
9262
9263template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009264QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9265 SourceLocation Loc) {
9266 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009267}
9268
9269template<typename Derived>
9270QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9271 return SemaRef.Context.getTypeOfType(Underlying);
9272}
9273
9274template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009275QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9276 SourceLocation Loc) {
9277 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009278}
9279
9280template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009281QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9282 UnaryTransformType::UTTKind UKind,
9283 SourceLocation Loc) {
9284 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9285}
9286
9287template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009288QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009289 TemplateName Template,
9290 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009291 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009292 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009293}
Mike Stump1eb44332009-09-09 15:08:12 +00009294
Douglas Gregordcee1a12009-08-06 05:28:30 +00009295template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009296QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9297 SourceLocation KWLoc) {
9298 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9299}
9300
9301template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009302TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009303TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009304 bool TemplateKW,
9305 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009306 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009307 Template);
9308}
9309
9310template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009311TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009312TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9313 const IdentifierInfo &Name,
9314 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009315 QualType ObjectType,
9316 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009317 UnqualifiedId TemplateName;
9318 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009319 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009320 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009321 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009322 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009323 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009324 /*EnteringContext=*/false,
9325 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009326 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009327}
Mike Stump1eb44332009-09-09 15:08:12 +00009328
Douglas Gregorb98b1992009-08-11 05:31:07 +00009329template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009330TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009331TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009332 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009333 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009334 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009335 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009336 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009337 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009338 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009339 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009340 Sema::TemplateTy Template;
9341 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009342 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009343 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009344 /*EnteringContext=*/false,
9345 Template);
9346 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009347}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009348
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009349template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009350ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009351TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9352 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009353 Expr *OrigCallee,
9354 Expr *First,
9355 Expr *Second) {
9356 Expr *Callee = OrigCallee->IgnoreParenCasts();
9357 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009358
Douglas Gregorb98b1992009-08-11 05:31:07 +00009359 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009360 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009361 if (!First->getType()->isOverloadableType() &&
9362 !Second->getType()->isOverloadableType())
9363 return getSema().CreateBuiltinArraySubscriptExpr(First,
9364 Callee->getLocStart(),
9365 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009366 } else if (Op == OO_Arrow) {
9367 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009368 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9369 } else if (Second == 0 || isPostIncDec) {
9370 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009371 // The argument is not of overloadable type, so try to create a
9372 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009373 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009374 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009375
John McCall9ae2f072010-08-23 23:25:46 +00009376 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009377 }
9378 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009379 if (!First->getType()->isOverloadableType() &&
9380 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009381 // Neither of the arguments is an overloadable type, so try to
9382 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009383 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009384 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009385 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009386 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009387 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009388
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009389 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009390 }
9391 }
Mike Stump1eb44332009-09-09 15:08:12 +00009392
9393 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009394 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009395 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009396
John McCall9ae2f072010-08-23 23:25:46 +00009397 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009398 assert(ULE->requiresADL());
9399
9400 // FIXME: Do we have to check
9401 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009402 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009403 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009404 // If we've resolved this to a particular non-member function, just call
9405 // that function. If we resolved it to a member function,
9406 // CreateOverloaded* will find that function for us.
9407 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9408 if (!isa<CXXMethodDecl>(ND))
9409 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009410 }
Mike Stump1eb44332009-09-09 15:08:12 +00009411
Douglas Gregorb98b1992009-08-11 05:31:07 +00009412 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009413 Expr *Args[2] = { First, Second };
9414 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009415
Douglas Gregorb98b1992009-08-11 05:31:07 +00009416 // Create the overloaded operator invocation for unary operators.
9417 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009418 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009419 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009420 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009421 }
Mike Stump1eb44332009-09-09 15:08:12 +00009422
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009423 if (Op == OO_Subscript) {
9424 SourceLocation LBrace;
9425 SourceLocation RBrace;
9426
9427 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9428 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9429 LBrace = SourceLocation::getFromRawEncoding(
9430 NameLoc.CXXOperatorName.BeginOpNameLoc);
9431 RBrace = SourceLocation::getFromRawEncoding(
9432 NameLoc.CXXOperatorName.EndOpNameLoc);
9433 } else {
9434 LBrace = Callee->getLocStart();
9435 RBrace = OpLoc;
9436 }
9437
9438 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9439 First, Second);
9440 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009441
Douglas Gregorb98b1992009-08-11 05:31:07 +00009442 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009443 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009444 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009445 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9446 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009447 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009448
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009449 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009450}
Mike Stump1eb44332009-09-09 15:08:12 +00009451
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009452template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009453ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009454TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009455 SourceLocation OperatorLoc,
9456 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009457 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009458 TypeSourceInfo *ScopeType,
9459 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009460 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009461 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009462 QualType BaseType = Base->getType();
9463 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009464 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009465 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009466 !BaseType->getAs<PointerType>()->getPointeeType()
9467 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009468 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009469 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009470 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009471 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009472 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009473 /*FIXME?*/true);
9474 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009475
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009476 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009477 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9478 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9479 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9480 NameInfo.setNamedTypeInfo(DestroyedType);
9481
Richard Smith6314db92012-05-15 06:15:11 +00009482 // The scope type is now known to be a valid nested name specifier
9483 // component. Tack it on to the end of the nested name specifier.
9484 if (ScopeType)
9485 SS.Extend(SemaRef.Context, SourceLocation(),
9486 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009487
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009488 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009489 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009490 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009491 SS, TemplateKWLoc,
9492 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009493 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009494 /*TemplateArgs*/ 0);
9495}
9496
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009497template<typename Derived>
9498StmtResult
9499TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan9fd6b8f2013-05-04 03:59:06 +00009500 SourceLocation Loc = S->getLocStart();
9501 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9502 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9503 S->getCapturedRegionKind(), NumParams);
9504 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9505
9506 if (Body.isInvalid()) {
9507 getSema().ActOnCapturedRegionError();
9508 return StmtError();
9509 }
9510
9511 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009512}
9513
Douglas Gregor577f75a2009-08-04 16:50:30 +00009514} // end namespace clang
9515
9516#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H