blob: 1fd206bbc20828e850f6c1fb2be78e6c86d92f3c [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
Chad Rosier4a9d7952012-08-08 18:46:20 +00003236 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
Douglas Gregorcded4f62011-01-14 17:04:44 +00003237 getSema().Context);
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>
John McCalla2becad2009-10-21 00:40:46 +00003589QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003590 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003591 QualType PointeeType
3592 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003593 if (PointeeType.isNull())
3594 return QualType();
3595
3596 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003597 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003598 // A dependent pointer type 'T *' has is being transformed such
3599 // that an Objective-C class type is being replaced for 'T'. The
3600 // resulting pointer type is an ObjCObjectPointerType, not a
3601 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003602 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003603
John McCallc12c5bb2010-05-15 11:32:37 +00003604 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3605 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003606 return Result;
3607 }
John McCall43fed0d2010-11-12 08:19:04 +00003608
Douglas Gregor92e986e2010-04-22 16:44:27 +00003609 if (getDerived().AlwaysRebuild() ||
3610 PointeeType != TL.getPointeeLoc().getType()) {
3611 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3612 if (Result.isNull())
3613 return QualType();
3614 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003615
John McCallf85e1932011-06-15 23:02:42 +00003616 // Objective-C ARC can add lifetime qualifiers to the type that we're
3617 // pointing to.
3618 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003619
Douglas Gregor92e986e2010-04-22 16:44:27 +00003620 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3621 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003622 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003623}
Mike Stump1eb44332009-09-09 15:08:12 +00003624
3625template<typename Derived>
3626QualType
John McCalla2becad2009-10-21 00:40:46 +00003627TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003628 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003629 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003630 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3631 if (PointeeType.isNull())
3632 return QualType();
3633
3634 QualType Result = TL.getType();
3635 if (getDerived().AlwaysRebuild() ||
3636 PointeeType != TL.getPointeeLoc().getType()) {
3637 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003638 TL.getSigilLoc());
3639 if (Result.isNull())
3640 return QualType();
3641 }
3642
Douglas Gregor39968ad2010-04-22 16:50:51 +00003643 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003644 NewT.setSigilLoc(TL.getSigilLoc());
3645 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003646}
3647
John McCall85737a72009-10-30 00:06:24 +00003648/// Transforms a reference type. Note that somewhat paradoxically we
3649/// don't care whether the type itself is an l-value type or an r-value
3650/// type; we only care if the type was *written* as an l-value type
3651/// or an r-value type.
3652template<typename Derived>
3653QualType
3654TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003655 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003656 const ReferenceType *T = TL.getTypePtr();
3657
3658 // Note that this works with the pointee-as-written.
3659 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3660 if (PointeeType.isNull())
3661 return QualType();
3662
3663 QualType Result = TL.getType();
3664 if (getDerived().AlwaysRebuild() ||
3665 PointeeType != T->getPointeeTypeAsWritten()) {
3666 Result = getDerived().RebuildReferenceType(PointeeType,
3667 T->isSpelledAsLValue(),
3668 TL.getSigilLoc());
3669 if (Result.isNull())
3670 return QualType();
3671 }
3672
John McCallf85e1932011-06-15 23:02:42 +00003673 // Objective-C ARC can add lifetime qualifiers to the type that we're
3674 // referring to.
3675 TLB.TypeWasModifiedSafely(
3676 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3677
John McCall85737a72009-10-30 00:06:24 +00003678 // r-value references can be rebuilt as l-value references.
3679 ReferenceTypeLoc NewTL;
3680 if (isa<LValueReferenceType>(Result))
3681 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3682 else
3683 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3684 NewTL.setSigilLoc(TL.getSigilLoc());
3685
3686 return Result;
3687}
3688
Mike Stump1eb44332009-09-09 15:08:12 +00003689template<typename Derived>
3690QualType
John McCalla2becad2009-10-21 00:40:46 +00003691TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003692 LValueReferenceTypeLoc TL) {
3693 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003694}
3695
Mike Stump1eb44332009-09-09 15:08:12 +00003696template<typename Derived>
3697QualType
John McCalla2becad2009-10-21 00:40:46 +00003698TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003699 RValueReferenceTypeLoc TL) {
3700 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003701}
Mike Stump1eb44332009-09-09 15:08:12 +00003702
Douglas Gregor577f75a2009-08-04 16:50:30 +00003703template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003704QualType
John McCalla2becad2009-10-21 00:40:46 +00003705TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003706 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003707 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003708 if (PointeeType.isNull())
3709 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003710
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003711 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3712 TypeSourceInfo* NewClsTInfo = 0;
3713 if (OldClsTInfo) {
3714 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3715 if (!NewClsTInfo)
3716 return QualType();
3717 }
3718
3719 const MemberPointerType *T = TL.getTypePtr();
3720 QualType OldClsType = QualType(T->getClass(), 0);
3721 QualType NewClsType;
3722 if (NewClsTInfo)
3723 NewClsType = NewClsTInfo->getType();
3724 else {
3725 NewClsType = getDerived().TransformType(OldClsType);
3726 if (NewClsType.isNull())
3727 return QualType();
3728 }
Mike Stump1eb44332009-09-09 15:08:12 +00003729
John McCalla2becad2009-10-21 00:40:46 +00003730 QualType Result = TL.getType();
3731 if (getDerived().AlwaysRebuild() ||
3732 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003733 NewClsType != OldClsType) {
3734 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003735 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003736 if (Result.isNull())
3737 return QualType();
3738 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003739
John McCalla2becad2009-10-21 00:40:46 +00003740 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3741 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003742 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003743
3744 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003745}
3746
Mike Stump1eb44332009-09-09 15:08:12 +00003747template<typename Derived>
3748QualType
John McCalla2becad2009-10-21 00:40:46 +00003749TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003750 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003751 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003752 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003753 if (ElementType.isNull())
3754 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003755
John McCalla2becad2009-10-21 00:40:46 +00003756 QualType Result = TL.getType();
3757 if (getDerived().AlwaysRebuild() ||
3758 ElementType != T->getElementType()) {
3759 Result = getDerived().RebuildConstantArrayType(ElementType,
3760 T->getSizeModifier(),
3761 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003762 T->getIndexTypeCVRQualifiers(),
3763 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003764 if (Result.isNull())
3765 return QualType();
3766 }
Eli Friedman457a3772012-01-25 22:19:07 +00003767
3768 // We might have either a ConstantArrayType or a VariableArrayType now:
3769 // a ConstantArrayType is allowed to have an element type which is a
3770 // VariableArrayType if the type is dependent. Fortunately, all array
3771 // types have the same location layout.
3772 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003773 NewTL.setLBracketLoc(TL.getLBracketLoc());
3774 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003775
John McCalla2becad2009-10-21 00:40:46 +00003776 Expr *Size = TL.getSizeExpr();
3777 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003778 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3779 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003780 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003781 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003782 }
3783 NewTL.setSizeExpr(Size);
3784
3785 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003786}
Mike Stump1eb44332009-09-09 15:08:12 +00003787
Douglas Gregor577f75a2009-08-04 16:50:30 +00003788template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003789QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003790 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003791 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003792 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003793 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003794 if (ElementType.isNull())
3795 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003796
John McCalla2becad2009-10-21 00:40:46 +00003797 QualType Result = TL.getType();
3798 if (getDerived().AlwaysRebuild() ||
3799 ElementType != T->getElementType()) {
3800 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003801 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003802 T->getIndexTypeCVRQualifiers(),
3803 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003804 if (Result.isNull())
3805 return QualType();
3806 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003807
John McCalla2becad2009-10-21 00:40:46 +00003808 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3809 NewTL.setLBracketLoc(TL.getLBracketLoc());
3810 NewTL.setRBracketLoc(TL.getRBracketLoc());
3811 NewTL.setSizeExpr(0);
3812
3813 return Result;
3814}
3815
3816template<typename Derived>
3817QualType
3818TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003819 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003820 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003821 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3822 if (ElementType.isNull())
3823 return QualType();
3824
John McCall60d7b3a2010-08-24 06:29:42 +00003825 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003826 = getDerived().TransformExpr(T->getSizeExpr());
3827 if (SizeResult.isInvalid())
3828 return QualType();
3829
John McCall9ae2f072010-08-23 23:25:46 +00003830 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003831
3832 QualType Result = TL.getType();
3833 if (getDerived().AlwaysRebuild() ||
3834 ElementType != T->getElementType() ||
3835 Size != T->getSizeExpr()) {
3836 Result = getDerived().RebuildVariableArrayType(ElementType,
3837 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003838 Size,
John McCalla2becad2009-10-21 00:40:46 +00003839 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003840 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003841 if (Result.isNull())
3842 return QualType();
3843 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003844
John McCalla2becad2009-10-21 00:40:46 +00003845 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3846 NewTL.setLBracketLoc(TL.getLBracketLoc());
3847 NewTL.setRBracketLoc(TL.getRBracketLoc());
3848 NewTL.setSizeExpr(Size);
3849
3850 return Result;
3851}
3852
3853template<typename Derived>
3854QualType
3855TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003856 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003857 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003858 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3859 if (ElementType.isNull())
3860 return QualType();
3861
Richard Smithf6702a32011-12-20 02:08:33 +00003862 // Array bounds are constant expressions.
3863 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3864 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003865
John McCall3b657512011-01-19 10:06:00 +00003866 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3867 Expr *origSize = TL.getSizeExpr();
3868 if (!origSize) origSize = T->getSizeExpr();
3869
3870 ExprResult sizeResult
3871 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003872 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003873 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003874 return QualType();
3875
John McCall3b657512011-01-19 10:06:00 +00003876 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003877
3878 QualType Result = TL.getType();
3879 if (getDerived().AlwaysRebuild() ||
3880 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003881 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003882 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3883 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003884 size,
John McCalla2becad2009-10-21 00:40:46 +00003885 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003886 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003887 if (Result.isNull())
3888 return QualType();
3889 }
John McCalla2becad2009-10-21 00:40:46 +00003890
3891 // We might have any sort of array type now, but fortunately they
3892 // all have the same location layout.
3893 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3894 NewTL.setLBracketLoc(TL.getLBracketLoc());
3895 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003896 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003897
3898 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003899}
Mike Stump1eb44332009-09-09 15:08:12 +00003900
3901template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003902QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003903 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003904 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003905 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003906
3907 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003908 QualType ElementType = getDerived().TransformType(T->getElementType());
3909 if (ElementType.isNull())
3910 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003911
Richard Smithf6702a32011-12-20 02:08:33 +00003912 // Vector sizes are constant expressions.
3913 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3914 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003915
John McCall60d7b3a2010-08-24 06:29:42 +00003916 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003917 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003918 if (Size.isInvalid())
3919 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003920
John McCalla2becad2009-10-21 00:40:46 +00003921 QualType Result = TL.getType();
3922 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003923 ElementType != T->getElementType() ||
3924 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003925 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003926 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003927 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003928 if (Result.isNull())
3929 return QualType();
3930 }
John McCalla2becad2009-10-21 00:40:46 +00003931
3932 // Result might be dependent or not.
3933 if (isa<DependentSizedExtVectorType>(Result)) {
3934 DependentSizedExtVectorTypeLoc NewTL
3935 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3936 NewTL.setNameLoc(TL.getNameLoc());
3937 } else {
3938 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3939 NewTL.setNameLoc(TL.getNameLoc());
3940 }
3941
3942 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003943}
Mike Stump1eb44332009-09-09 15:08:12 +00003944
3945template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003946QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003947 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003948 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003949 QualType ElementType = getDerived().TransformType(T->getElementType());
3950 if (ElementType.isNull())
3951 return QualType();
3952
John McCalla2becad2009-10-21 00:40:46 +00003953 QualType Result = TL.getType();
3954 if (getDerived().AlwaysRebuild() ||
3955 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003956 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003957 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003958 if (Result.isNull())
3959 return QualType();
3960 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003961
John McCalla2becad2009-10-21 00:40:46 +00003962 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3963 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003964
John McCalla2becad2009-10-21 00:40:46 +00003965 return Result;
3966}
3967
3968template<typename Derived>
3969QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003970 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003971 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003972 QualType ElementType = getDerived().TransformType(T->getElementType());
3973 if (ElementType.isNull())
3974 return QualType();
3975
3976 QualType Result = TL.getType();
3977 if (getDerived().AlwaysRebuild() ||
3978 ElementType != T->getElementType()) {
3979 Result = getDerived().RebuildExtVectorType(ElementType,
3980 T->getNumElements(),
3981 /*FIXME*/ SourceLocation());
3982 if (Result.isNull())
3983 return QualType();
3984 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003985
John McCalla2becad2009-10-21 00:40:46 +00003986 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3987 NewTL.setNameLoc(TL.getNameLoc());
3988
3989 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003990}
Mike Stump1eb44332009-09-09 15:08:12 +00003991
David Blaikiedc84cd52013-02-20 22:23:23 +00003992template <typename Derived>
3993ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
3994 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
3995 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003996 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003997 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003998
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003999 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004000 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004001 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004002 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004003 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004004
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004005 TypeLocBuilder TLB;
4006 TypeLoc NewTL = OldDI->getTypeLoc();
4007 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004008
4009 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004010 OldExpansionTL.getPatternLoc());
4011 if (Result.isNull())
4012 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004013
4014 Result = RebuildPackExpansionType(Result,
4015 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004016 OldExpansionTL.getEllipsisLoc(),
4017 NumExpansions);
4018 if (Result.isNull())
4019 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004020
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004021 PackExpansionTypeLoc NewExpansionTL
4022 = TLB.push<PackExpansionTypeLoc>(Result);
4023 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4024 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4025 } else
4026 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00004027 if (!NewDI)
4028 return 0;
4029
John McCallfb44de92011-05-01 22:35:37 +00004030 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00004031 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00004032
4033 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4034 OldParm->getDeclContext(),
4035 OldParm->getInnerLocStart(),
4036 OldParm->getLocation(),
4037 OldParm->getIdentifier(),
4038 NewDI->getType(),
4039 NewDI,
4040 OldParm->getStorageClass(),
John McCallfb44de92011-05-01 22:35:37 +00004041 /* DefArg */ NULL);
4042 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4043 OldParm->getFunctionScopeIndex() + indexAdjustment);
4044 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004045}
4046
4047template<typename Derived>
4048bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004049 TransformFunctionTypeParams(SourceLocation Loc,
4050 ParmVarDecl **Params, unsigned NumParams,
4051 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004052 SmallVectorImpl<QualType> &OutParamTypes,
4053 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004054 int indexAdjustment = 0;
4055
Douglas Gregora009b592011-01-07 00:20:55 +00004056 for (unsigned i = 0; i != NumParams; ++i) {
4057 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004058 assert(OldParm->getFunctionScopeIndex() == i);
4059
David Blaikiedc84cd52013-02-20 22:23:23 +00004060 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004061 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004062 if (OldParm->isParameterPack()) {
4063 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004064 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004065
Douglas Gregor603cfb42011-01-05 23:12:31 +00004066 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004067 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004068 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004069 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4070 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004071 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4072
Douglas Gregor603cfb42011-01-05 23:12:31 +00004073 // Determine whether we should expand the parameter packs.
4074 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004075 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004076 Optional<unsigned> OrigNumExpansions =
4077 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004078 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004079 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4080 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004081 Unexpanded,
4082 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004083 RetainExpansion,
4084 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004085 return true;
4086 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004087
Douglas Gregor603cfb42011-01-05 23:12:31 +00004088 if (ShouldExpand) {
4089 // Expand the function parameter pack into multiple, separate
4090 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004091 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004092 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004093 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004094 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004095 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004096 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004097 OrigNumExpansions,
4098 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004099 if (!NewParm)
4100 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004101
Douglas Gregora009b592011-01-07 00:20:55 +00004102 OutParamTypes.push_back(NewParm->getType());
4103 if (PVars)
4104 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004105 }
Douglas Gregord3731192011-01-10 07:32:04 +00004106
4107 // If we're supposed to retain a pack expansion, do so by temporarily
4108 // forgetting the partially-substituted parameter pack.
4109 if (RetainExpansion) {
4110 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004111 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004112 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004113 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004114 OrigNumExpansions,
4115 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004116 if (!NewParm)
4117 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004118
Douglas Gregord3731192011-01-10 07:32:04 +00004119 OutParamTypes.push_back(NewParm->getType());
4120 if (PVars)
4121 PVars->push_back(NewParm);
4122 }
4123
John McCallfb44de92011-05-01 22:35:37 +00004124 // The next parameter should have the same adjustment as the
4125 // last thing we pushed, but we post-incremented indexAdjustment
4126 // on every push. Also, if we push nothing, the adjustment should
4127 // go down by one.
4128 indexAdjustment--;
4129
Douglas Gregor603cfb42011-01-05 23:12:31 +00004130 // We're done with the pack expansion.
4131 continue;
4132 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004133
4134 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004135 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004136 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4137 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004138 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004139 NumExpansions,
4140 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004141 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004142 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004143 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004144 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004145
John McCall21ef0fa2010-03-11 09:03:00 +00004146 if (!NewParm)
4147 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004148
Douglas Gregora009b592011-01-07 00:20:55 +00004149 OutParamTypes.push_back(NewParm->getType());
4150 if (PVars)
4151 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004152 continue;
4153 }
John McCall21ef0fa2010-03-11 09:03:00 +00004154
4155 // Deal with the possibility that we don't have a parameter
4156 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004157 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004158 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004159 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004160 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004161 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004162 = dyn_cast<PackExpansionType>(OldType)) {
4163 // We have a function parameter pack that may need to be expanded.
4164 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004165 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004166 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004167
Douglas Gregor603cfb42011-01-05 23:12:31 +00004168 // Determine whether we should expand the parameter packs.
4169 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004170 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004171 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004172 Unexpanded,
4173 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004174 RetainExpansion,
4175 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004176 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004177 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004178
Douglas Gregor603cfb42011-01-05 23:12:31 +00004179 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004180 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004181 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004182 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004183 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4184 QualType NewType = getDerived().TransformType(Pattern);
4185 if (NewType.isNull())
4186 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004187
Douglas Gregora009b592011-01-07 00:20:55 +00004188 OutParamTypes.push_back(NewType);
4189 if (PVars)
4190 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004191 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004192
Douglas Gregor603cfb42011-01-05 23:12:31 +00004193 // We're done with the pack expansion.
4194 continue;
4195 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004196
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004197 // If we're supposed to retain a pack expansion, do so by temporarily
4198 // forgetting the partially-substituted parameter pack.
4199 if (RetainExpansion) {
4200 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4201 QualType NewType = getDerived().TransformType(Pattern);
4202 if (NewType.isNull())
4203 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004204
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004205 OutParamTypes.push_back(NewType);
4206 if (PVars)
4207 PVars->push_back(0);
4208 }
Douglas Gregord3731192011-01-10 07:32:04 +00004209
Chad Rosier4a9d7952012-08-08 18:46:20 +00004210 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004211 // expansion.
4212 OldType = Expansion->getPattern();
4213 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004214 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4215 NewType = getDerived().TransformType(OldType);
4216 } else {
4217 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004218 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004219
Douglas Gregor603cfb42011-01-05 23:12:31 +00004220 if (NewType.isNull())
4221 return true;
4222
4223 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004224 NewType = getSema().Context.getPackExpansionType(NewType,
4225 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004226
Douglas Gregora009b592011-01-07 00:20:55 +00004227 OutParamTypes.push_back(NewType);
4228 if (PVars)
4229 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004230 }
4231
John McCallfb44de92011-05-01 22:35:37 +00004232#ifndef NDEBUG
4233 if (PVars) {
4234 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4235 if (ParmVarDecl *parm = (*PVars)[i])
4236 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004237 }
John McCallfb44de92011-05-01 22:35:37 +00004238#endif
4239
4240 return false;
4241}
John McCall21ef0fa2010-03-11 09:03:00 +00004242
4243template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004244QualType
John McCalla2becad2009-10-21 00:40:46 +00004245TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004246 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004247 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4248}
4249
4250template<typename Derived>
4251QualType
4252TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4253 FunctionProtoTypeLoc TL,
4254 CXXRecordDecl *ThisContext,
4255 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004256 // Transform the parameters and return type.
4257 //
Richard Smithe6975e92012-04-17 00:58:00 +00004258 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004259 // When the function has a trailing return type, we instantiate the
4260 // parameters before the return type, since the return type can then refer
4261 // to the parameters themselves (via decltype, sizeof, etc.).
4262 //
Chris Lattner686775d2011-07-20 06:58:45 +00004263 SmallVector<QualType, 4> ParamTypes;
4264 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004265 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004266
Douglas Gregordab60ad2010-10-01 18:44:50 +00004267 QualType ResultType;
4268
Richard Smith9fbf3272012-08-14 22:51:13 +00004269 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004270 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004271 TL.getParmArray(),
4272 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004273 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004274 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004275 return QualType();
4276
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004277 {
4278 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004279 // If a declaration declares a member function or member function
4280 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004281 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004282 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004283 // declarator.
4284 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004285
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004286 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4287 if (ResultType.isNull())
4288 return QualType();
4289 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004290 }
4291 else {
4292 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4293 if (ResultType.isNull())
4294 return QualType();
4295
Chad Rosier4a9d7952012-08-08 18:46:20 +00004296 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004297 TL.getParmArray(),
4298 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004299 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004300 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004301 return QualType();
4302 }
4303
Richard Smithe6975e92012-04-17 00:58:00 +00004304 // FIXME: Need to transform the exception-specification too.
4305
John McCalla2becad2009-10-21 00:40:46 +00004306 QualType Result = TL.getType();
4307 if (getDerived().AlwaysRebuild() ||
4308 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004309 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004310 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004311 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004312 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004313 if (Result.isNull())
4314 return QualType();
4315 }
Mike Stump1eb44332009-09-09 15:08:12 +00004316
John McCalla2becad2009-10-21 00:40:46 +00004317 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004318 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004319 NewTL.setLParenLoc(TL.getLParenLoc());
4320 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004321 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004322 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4323 NewTL.setArg(i, ParamDecls[i]);
4324
4325 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004326}
Mike Stump1eb44332009-09-09 15:08:12 +00004327
Douglas Gregor577f75a2009-08-04 16:50:30 +00004328template<typename Derived>
4329QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004330 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004331 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004332 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004333 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4334 if (ResultType.isNull())
4335 return QualType();
4336
4337 QualType Result = TL.getType();
4338 if (getDerived().AlwaysRebuild() ||
4339 ResultType != T->getResultType())
4340 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4341
4342 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004343 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004344 NewTL.setLParenLoc(TL.getLParenLoc());
4345 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004346 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004347
4348 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004349}
Mike Stump1eb44332009-09-09 15:08:12 +00004350
John McCalled976492009-12-04 22:46:56 +00004351template<typename Derived> QualType
4352TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004353 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004354 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004355 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004356 if (!D)
4357 return QualType();
4358
4359 QualType Result = TL.getType();
4360 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4361 Result = getDerived().RebuildUnresolvedUsingType(D);
4362 if (Result.isNull())
4363 return QualType();
4364 }
4365
4366 // We might get an arbitrary type spec type back. We should at
4367 // least always get a type spec type, though.
4368 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4369 NewTL.setNameLoc(TL.getNameLoc());
4370
4371 return Result;
4372}
4373
Douglas Gregor577f75a2009-08-04 16:50:30 +00004374template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004375QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004376 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004377 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004378 TypedefNameDecl *Typedef
4379 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4380 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004381 if (!Typedef)
4382 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004383
John McCalla2becad2009-10-21 00:40:46 +00004384 QualType Result = TL.getType();
4385 if (getDerived().AlwaysRebuild() ||
4386 Typedef != T->getDecl()) {
4387 Result = getDerived().RebuildTypedefType(Typedef);
4388 if (Result.isNull())
4389 return QualType();
4390 }
Mike Stump1eb44332009-09-09 15:08:12 +00004391
John McCalla2becad2009-10-21 00:40:46 +00004392 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4393 NewTL.setNameLoc(TL.getNameLoc());
4394
4395 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004396}
Mike Stump1eb44332009-09-09 15:08:12 +00004397
Douglas Gregor577f75a2009-08-04 16:50:30 +00004398template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004399QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004400 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004401 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004402 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4403 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004404
John McCall60d7b3a2010-08-24 06:29:42 +00004405 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004406 if (E.isInvalid())
4407 return QualType();
4408
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004409 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4410 if (E.isInvalid())
4411 return QualType();
4412
John McCalla2becad2009-10-21 00:40:46 +00004413 QualType Result = TL.getType();
4414 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004415 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004416 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004417 if (Result.isNull())
4418 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004419 }
John McCalla2becad2009-10-21 00:40:46 +00004420 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004421
John McCalla2becad2009-10-21 00:40:46 +00004422 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004423 NewTL.setTypeofLoc(TL.getTypeofLoc());
4424 NewTL.setLParenLoc(TL.getLParenLoc());
4425 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004426
4427 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004428}
Mike Stump1eb44332009-09-09 15:08:12 +00004429
4430template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004431QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004432 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004433 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4434 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4435 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004436 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004437
John McCalla2becad2009-10-21 00:40:46 +00004438 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004439 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4440 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004441 if (Result.isNull())
4442 return QualType();
4443 }
Mike Stump1eb44332009-09-09 15:08:12 +00004444
John McCalla2becad2009-10-21 00:40:46 +00004445 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004446 NewTL.setTypeofLoc(TL.getTypeofLoc());
4447 NewTL.setLParenLoc(TL.getLParenLoc());
4448 NewTL.setRParenLoc(TL.getRParenLoc());
4449 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004450
4451 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004452}
Mike Stump1eb44332009-09-09 15:08:12 +00004453
4454template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004455QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004456 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004457 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004458
Douglas Gregor670444e2009-08-04 22:27:00 +00004459 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004460 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4461 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004462
John McCall60d7b3a2010-08-24 06:29:42 +00004463 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004464 if (E.isInvalid())
4465 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004466
Richard Smith76f3f692012-02-22 02:04:18 +00004467 E = getSema().ActOnDecltypeExpression(E.take());
4468 if (E.isInvalid())
4469 return QualType();
4470
John McCalla2becad2009-10-21 00:40:46 +00004471 QualType Result = TL.getType();
4472 if (getDerived().AlwaysRebuild() ||
4473 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004474 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004475 if (Result.isNull())
4476 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004477 }
John McCalla2becad2009-10-21 00:40:46 +00004478 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004479
John McCalla2becad2009-10-21 00:40:46 +00004480 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4481 NewTL.setNameLoc(TL.getNameLoc());
4482
4483 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004484}
4485
4486template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004487QualType TreeTransform<Derived>::TransformUnaryTransformType(
4488 TypeLocBuilder &TLB,
4489 UnaryTransformTypeLoc TL) {
4490 QualType Result = TL.getType();
4491 if (Result->isDependentType()) {
4492 const UnaryTransformType *T = TL.getTypePtr();
4493 QualType NewBase =
4494 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4495 Result = getDerived().RebuildUnaryTransformType(NewBase,
4496 T->getUTTKind(),
4497 TL.getKWLoc());
4498 if (Result.isNull())
4499 return QualType();
4500 }
4501
4502 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4503 NewTL.setKWLoc(TL.getKWLoc());
4504 NewTL.setParensRange(TL.getParensRange());
4505 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4506 return Result;
4507}
4508
4509template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004510QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4511 AutoTypeLoc TL) {
4512 const AutoType *T = TL.getTypePtr();
4513 QualType OldDeduced = T->getDeducedType();
4514 QualType NewDeduced;
4515 if (!OldDeduced.isNull()) {
4516 NewDeduced = getDerived().TransformType(OldDeduced);
4517 if (NewDeduced.isNull())
4518 return QualType();
4519 }
4520
4521 QualType Result = TL.getType();
Richard Smithdc7a4f52013-04-30 13:56:41 +00004522 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4523 T->isDependentType()) {
Richard Smitha2c36462013-04-26 16:15:35 +00004524 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith34b41d92011-02-20 03:19:35 +00004525 if (Result.isNull())
4526 return QualType();
4527 }
4528
4529 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4530 NewTL.setNameLoc(TL.getNameLoc());
4531
4532 return Result;
4533}
4534
4535template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004536QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004537 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004538 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004539 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004540 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4541 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004542 if (!Record)
4543 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004544
John McCalla2becad2009-10-21 00:40:46 +00004545 QualType Result = TL.getType();
4546 if (getDerived().AlwaysRebuild() ||
4547 Record != T->getDecl()) {
4548 Result = getDerived().RebuildRecordType(Record);
4549 if (Result.isNull())
4550 return QualType();
4551 }
Mike Stump1eb44332009-09-09 15:08:12 +00004552
John McCalla2becad2009-10-21 00:40:46 +00004553 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4554 NewTL.setNameLoc(TL.getNameLoc());
4555
4556 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004557}
Mike Stump1eb44332009-09-09 15:08:12 +00004558
4559template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004560QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004561 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004562 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004563 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004564 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4565 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004566 if (!Enum)
4567 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004568
John McCalla2becad2009-10-21 00:40:46 +00004569 QualType Result = TL.getType();
4570 if (getDerived().AlwaysRebuild() ||
4571 Enum != T->getDecl()) {
4572 Result = getDerived().RebuildEnumType(Enum);
4573 if (Result.isNull())
4574 return QualType();
4575 }
Mike Stump1eb44332009-09-09 15:08:12 +00004576
John McCalla2becad2009-10-21 00:40:46 +00004577 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4578 NewTL.setNameLoc(TL.getNameLoc());
4579
4580 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004581}
John McCall7da24312009-09-05 00:15:47 +00004582
John McCall3cb0ebd2010-03-10 03:28:59 +00004583template<typename Derived>
4584QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4585 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004586 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004587 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4588 TL.getTypePtr()->getDecl());
4589 if (!D) return QualType();
4590
4591 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4592 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4593 return T;
4594}
4595
Douglas Gregor577f75a2009-08-04 16:50:30 +00004596template<typename Derived>
4597QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004598 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004599 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004600 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004601}
4602
Mike Stump1eb44332009-09-09 15:08:12 +00004603template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004604QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004605 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004606 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004607 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004608
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004609 // Substitute into the replacement type, which itself might involve something
4610 // that needs to be transformed. This only tends to occur with default
4611 // template arguments of template template parameters.
4612 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4613 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4614 if (Replacement.isNull())
4615 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004616
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004617 // Always canonicalize the replacement type.
4618 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4619 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004620 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004621 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004622
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004623 // Propagate type-source information.
4624 SubstTemplateTypeParmTypeLoc NewTL
4625 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4626 NewTL.setNameLoc(TL.getNameLoc());
4627 return Result;
4628
John McCall49a832b2009-10-18 09:09:24 +00004629}
4630
4631template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004632QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4633 TypeLocBuilder &TLB,
4634 SubstTemplateTypeParmPackTypeLoc TL) {
4635 return TransformTypeSpecType(TLB, TL);
4636}
4637
4638template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004639QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004640 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004641 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004642 const TemplateSpecializationType *T = TL.getTypePtr();
4643
Douglas Gregor1d752d72011-03-02 18:46:51 +00004644 // The nested-name-specifier never matters in a TemplateSpecializationType,
4645 // because we can't have a dependent nested-name-specifier anyway.
4646 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004647 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004648 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4649 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004650 if (Template.isNull())
4651 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004652
John McCall43fed0d2010-11-12 08:19:04 +00004653 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4654}
4655
Eli Friedmanb001de72011-10-06 23:00:33 +00004656template<typename Derived>
4657QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4658 AtomicTypeLoc TL) {
4659 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4660 if (ValueType.isNull())
4661 return QualType();
4662
4663 QualType Result = TL.getType();
4664 if (getDerived().AlwaysRebuild() ||
4665 ValueType != TL.getValueLoc().getType()) {
4666 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4667 if (Result.isNull())
4668 return QualType();
4669 }
4670
4671 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4672 NewTL.setKWLoc(TL.getKWLoc());
4673 NewTL.setLParenLoc(TL.getLParenLoc());
4674 NewTL.setRParenLoc(TL.getRParenLoc());
4675
4676 return Result;
4677}
4678
Chad Rosier4a9d7952012-08-08 18:46:20 +00004679 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004680 /// container that provides a \c getArgLoc() member function.
4681 ///
4682 /// This iterator is intended to be used with the iterator form of
4683 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4684 template<typename ArgLocContainer>
4685 class TemplateArgumentLocContainerIterator {
4686 ArgLocContainer *Container;
4687 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004688
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004689 public:
4690 typedef TemplateArgumentLoc value_type;
4691 typedef TemplateArgumentLoc reference;
4692 typedef int difference_type;
4693 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004694
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004695 class pointer {
4696 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004697
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004698 public:
4699 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004700
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004701 const TemplateArgumentLoc *operator->() const {
4702 return &Arg;
4703 }
4704 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004705
4706
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004707 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004708
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004709 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4710 unsigned Index)
4711 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004712
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004713 TemplateArgumentLocContainerIterator &operator++() {
4714 ++Index;
4715 return *this;
4716 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004717
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004718 TemplateArgumentLocContainerIterator operator++(int) {
4719 TemplateArgumentLocContainerIterator Old(*this);
4720 ++(*this);
4721 return Old;
4722 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004723
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004724 TemplateArgumentLoc operator*() const {
4725 return Container->getArgLoc(Index);
4726 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004727
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004728 pointer operator->() const {
4729 return pointer(Container->getArgLoc(Index));
4730 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004731
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004732 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004733 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004734 return X.Container == Y.Container && X.Index == Y.Index;
4735 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004736
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004737 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004738 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004739 return !(X == Y);
4740 }
4741 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004742
4743
John McCall43fed0d2010-11-12 08:19:04 +00004744template <typename Derived>
4745QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4746 TypeLocBuilder &TLB,
4747 TemplateSpecializationTypeLoc TL,
4748 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004749 TemplateArgumentListInfo NewTemplateArgs;
4750 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4751 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004752 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4753 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004754 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004755 ArgIterator(TL, TL.getNumArgs()),
4756 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004757 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004758
John McCall833ca992009-10-29 08:12:44 +00004759 // FIXME: maybe don't rebuild if all the template arguments are the same.
4760
4761 QualType Result =
4762 getDerived().RebuildTemplateSpecializationType(Template,
4763 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004764 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004765
4766 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004767 // Specializations of template template parameters are represented as
4768 // TemplateSpecializationTypes, and substitution of type alias templates
4769 // within a dependent context can transform them into
4770 // DependentTemplateSpecializationTypes.
4771 if (isa<DependentTemplateSpecializationType>(Result)) {
4772 DependentTemplateSpecializationTypeLoc NewTL
4773 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004774 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004775 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004776 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004777 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004778 NewTL.setLAngleLoc(TL.getLAngleLoc());
4779 NewTL.setRAngleLoc(TL.getRAngleLoc());
4780 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4781 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4782 return Result;
4783 }
4784
John McCall833ca992009-10-29 08:12:44 +00004785 TemplateSpecializationTypeLoc NewTL
4786 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004787 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004788 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4789 NewTL.setLAngleLoc(TL.getLAngleLoc());
4790 NewTL.setRAngleLoc(TL.getRAngleLoc());
4791 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4792 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004793 }
Mike Stump1eb44332009-09-09 15:08:12 +00004794
John McCall833ca992009-10-29 08:12:44 +00004795 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004796}
Mike Stump1eb44332009-09-09 15:08:12 +00004797
Douglas Gregora88f09f2011-02-28 17:23:35 +00004798template <typename Derived>
4799QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4800 TypeLocBuilder &TLB,
4801 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004802 TemplateName Template,
4803 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004804 TemplateArgumentListInfo NewTemplateArgs;
4805 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4806 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4807 typedef TemplateArgumentLocContainerIterator<
4808 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004809 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004810 ArgIterator(TL, TL.getNumArgs()),
4811 NewTemplateArgs))
4812 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004813
Douglas Gregora88f09f2011-02-28 17:23:35 +00004814 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004815
Douglas Gregora88f09f2011-02-28 17:23:35 +00004816 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4817 QualType Result
4818 = getSema().Context.getDependentTemplateSpecializationType(
4819 TL.getTypePtr()->getKeyword(),
4820 DTN->getQualifier(),
4821 DTN->getIdentifier(),
4822 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004823
Douglas Gregora88f09f2011-02-28 17:23:35 +00004824 DependentTemplateSpecializationTypeLoc NewTL
4825 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004826 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004827 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004828 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004829 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004830 NewTL.setLAngleLoc(TL.getLAngleLoc());
4831 NewTL.setRAngleLoc(TL.getRAngleLoc());
4832 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4833 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4834 return Result;
4835 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004836
4837 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004838 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004839 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004840 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004841
Douglas Gregora88f09f2011-02-28 17:23:35 +00004842 if (!Result.isNull()) {
4843 /// FIXME: Wrap this in an elaborated-type-specifier?
4844 TemplateSpecializationTypeLoc NewTL
4845 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004846 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004847 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004848 NewTL.setLAngleLoc(TL.getLAngleLoc());
4849 NewTL.setRAngleLoc(TL.getRAngleLoc());
4850 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4851 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4852 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004853
Douglas Gregora88f09f2011-02-28 17:23:35 +00004854 return Result;
4855}
4856
Mike Stump1eb44332009-09-09 15:08:12 +00004857template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004858QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004859TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004860 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004861 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004862
Douglas Gregor9e876872011-03-01 18:12:44 +00004863 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004864 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004865 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004866 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004867 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4868 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004869 return QualType();
4870 }
Mike Stump1eb44332009-09-09 15:08:12 +00004871
John McCall43fed0d2010-11-12 08:19:04 +00004872 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4873 if (NamedT.isNull())
4874 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004875
Richard Smith3e4c6c42011-05-05 21:57:07 +00004876 // C++0x [dcl.type.elab]p2:
4877 // If the identifier resolves to a typedef-name or the simple-template-id
4878 // resolves to an alias template specialization, the
4879 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004880 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4881 if (const TemplateSpecializationType *TST =
4882 NamedT->getAs<TemplateSpecializationType>()) {
4883 TemplateName Template = TST->getTemplateName();
4884 if (TypeAliasTemplateDecl *TAT =
4885 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4886 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4887 diag::err_tag_reference_non_tag) << 4;
4888 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4889 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004890 }
4891 }
4892
John McCalla2becad2009-10-21 00:40:46 +00004893 QualType Result = TL.getType();
4894 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004895 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004896 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004897 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004898 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004899 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004900 if (Result.isNull())
4901 return QualType();
4902 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004903
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004904 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004905 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004906 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004907 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004908}
Mike Stump1eb44332009-09-09 15:08:12 +00004909
4910template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004911QualType TreeTransform<Derived>::TransformAttributedType(
4912 TypeLocBuilder &TLB,
4913 AttributedTypeLoc TL) {
4914 const AttributedType *oldType = TL.getTypePtr();
4915 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4916 if (modifiedType.isNull())
4917 return QualType();
4918
4919 QualType result = TL.getType();
4920
4921 // FIXME: dependent operand expressions?
4922 if (getDerived().AlwaysRebuild() ||
4923 modifiedType != oldType->getModifiedType()) {
4924 // TODO: this is really lame; we should really be rebuilding the
4925 // equivalent type from first principles.
4926 QualType equivalentType
4927 = getDerived().TransformType(oldType->getEquivalentType());
4928 if (equivalentType.isNull())
4929 return QualType();
4930 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4931 modifiedType,
4932 equivalentType);
4933 }
4934
4935 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4936 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4937 if (TL.hasAttrOperand())
4938 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4939 if (TL.hasAttrExprOperand())
4940 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4941 else if (TL.hasAttrEnumOperand())
4942 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4943
4944 return result;
4945}
4946
4947template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004948QualType
4949TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4950 ParenTypeLoc TL) {
4951 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4952 if (Inner.isNull())
4953 return QualType();
4954
4955 QualType Result = TL.getType();
4956 if (getDerived().AlwaysRebuild() ||
4957 Inner != TL.getInnerLoc().getType()) {
4958 Result = getDerived().RebuildParenType(Inner);
4959 if (Result.isNull())
4960 return QualType();
4961 }
4962
4963 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4964 NewTL.setLParenLoc(TL.getLParenLoc());
4965 NewTL.setRParenLoc(TL.getRParenLoc());
4966 return Result;
4967}
4968
4969template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004970QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004971 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004972 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004973
Douglas Gregor2494dd02011-03-01 01:34:45 +00004974 NestedNameSpecifierLoc QualifierLoc
4975 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4976 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004977 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004978
John McCall33500952010-06-11 00:33:02 +00004979 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004980 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004981 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004982 QualifierLoc,
4983 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004984 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004985 if (Result.isNull())
4986 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004987
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004988 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4989 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004990 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4991
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004992 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004993 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004994 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004995 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004996 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004997 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004998 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004999 NewTL.setNameLoc(TL.getNameLoc());
5000 }
John McCalla2becad2009-10-21 00:40:46 +00005001 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00005002}
Mike Stump1eb44332009-09-09 15:08:12 +00005003
Douglas Gregor577f75a2009-08-04 16:50:30 +00005004template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00005005QualType TreeTransform<Derived>::
5006 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005007 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005008 NestedNameSpecifierLoc QualifierLoc;
5009 if (TL.getQualifierLoc()) {
5010 QualifierLoc
5011 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5012 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00005013 return QualType();
5014 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005015
John McCall43fed0d2010-11-12 08:19:04 +00005016 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005017 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00005018}
5019
5020template<typename Derived>
5021QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005022TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5023 DependentTemplateSpecializationTypeLoc TL,
5024 NestedNameSpecifierLoc QualifierLoc) {
5025 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005026
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005027 TemplateArgumentListInfo NewTemplateArgs;
5028 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5029 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005030
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005031 typedef TemplateArgumentLocContainerIterator<
5032 DependentTemplateSpecializationTypeLoc> ArgIterator;
5033 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5034 ArgIterator(TL, TL.getNumArgs()),
5035 NewTemplateArgs))
5036 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005037
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005038 QualType Result
5039 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5040 QualifierLoc,
5041 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005042 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005043 NewTemplateArgs);
5044 if (Result.isNull())
5045 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005046
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005047 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5048 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005049
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005050 // Copy information relevant to the template specialization.
5051 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005052 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005053 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005054 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005055 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5056 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005057 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005058 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005059
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005060 // Copy information relevant to the elaborated type.
5061 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005062 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005063 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005064 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5065 DependentTemplateSpecializationTypeLoc SpecTL
5066 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005067 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005068 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005069 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005070 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005071 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5072 SpecTL.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 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005075 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005076 TemplateSpecializationTypeLoc SpecTL
5077 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005078 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005079 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005080 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5081 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005082 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005083 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005084 }
5085 return Result;
5086}
5087
5088template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005089QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5090 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005091 QualType Pattern
5092 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005093 if (Pattern.isNull())
5094 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005095
5096 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005097 if (getDerived().AlwaysRebuild() ||
5098 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005099 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005100 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005101 TL.getEllipsisLoc(),
5102 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005103 if (Result.isNull())
5104 return QualType();
5105 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005106
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005107 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5108 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5109 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005110}
5111
5112template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005113QualType
5114TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005115 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005116 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005117 TLB.pushFullCopy(TL);
5118 return TL.getType();
5119}
5120
5121template<typename Derived>
5122QualType
5123TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005124 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005125 // ObjCObjectType is never dependent.
5126 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005127 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005128}
Mike Stump1eb44332009-09-09 15:08:12 +00005129
5130template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005131QualType
5132TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005133 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005134 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005135 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005136 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005137}
5138
Douglas Gregor577f75a2009-08-04 16:50:30 +00005139//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005140// Statement transformation
5141//===----------------------------------------------------------------------===//
5142template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005143StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005144TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005145 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005146}
5147
5148template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005149StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005150TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5151 return getDerived().TransformCompoundStmt(S, false);
5152}
5153
5154template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005155StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005156TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005157 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005158 Sema::CompoundScopeRAII CompoundScope(getSema());
5159
John McCall7114cba2010-08-27 19:56:05 +00005160 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005161 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005162 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005163 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5164 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005165 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005166 if (Result.isInvalid()) {
5167 // Immediately fail if this was a DeclStmt, since it's very
5168 // likely that this will cause problems for future statements.
5169 if (isa<DeclStmt>(*B))
5170 return StmtError();
5171
5172 // Otherwise, just keep processing substatements and fail later.
5173 SubStmtInvalid = true;
5174 continue;
5175 }
Mike Stump1eb44332009-09-09 15:08:12 +00005176
Douglas Gregor43959a92009-08-20 07:17:43 +00005177 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5178 Statements.push_back(Result.takeAs<Stmt>());
5179 }
Mike Stump1eb44332009-09-09 15:08:12 +00005180
John McCall7114cba2010-08-27 19:56:05 +00005181 if (SubStmtInvalid)
5182 return StmtError();
5183
Douglas Gregor43959a92009-08-20 07:17:43 +00005184 if (!getDerived().AlwaysRebuild() &&
5185 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005186 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005187
5188 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005189 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005190 S->getRBracLoc(),
5191 IsStmtExpr);
5192}
Mike Stump1eb44332009-09-09 15:08:12 +00005193
Douglas Gregor43959a92009-08-20 07:17:43 +00005194template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005195StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005196TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005197 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005198 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005199 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5200 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005201
Eli Friedman264c1f82009-11-19 03:14:00 +00005202 // Transform the left-hand case value.
5203 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005204 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005205 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005206 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005207
Eli Friedman264c1f82009-11-19 03:14:00 +00005208 // Transform the right-hand case value (for the GNU case-range extension).
5209 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005210 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005211 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005212 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005213 }
Mike Stump1eb44332009-09-09 15:08:12 +00005214
Douglas Gregor43959a92009-08-20 07:17:43 +00005215 // Build the case statement.
5216 // Case statements are always rebuilt so that they will attached to their
5217 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005218 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005219 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005220 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005221 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005222 S->getColonLoc());
5223 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005224 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005225
Douglas Gregor43959a92009-08-20 07:17:43 +00005226 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005227 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005228 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005229 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005230
Douglas Gregor43959a92009-08-20 07:17:43 +00005231 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005232 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005233}
5234
5235template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005236StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005237TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005238 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005239 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005240 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005241 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005242
Douglas Gregor43959a92009-08-20 07:17:43 +00005243 // Default statements are always rebuilt
5244 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005245 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005246}
Mike Stump1eb44332009-09-09 15:08:12 +00005247
Douglas Gregor43959a92009-08-20 07:17:43 +00005248template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005249StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005250TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005251 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005252 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005253 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005254
Chris Lattner57ad3782011-02-17 20:34:02 +00005255 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5256 S->getDecl());
5257 if (!LD)
5258 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005259
5260
Douglas Gregor43959a92009-08-20 07:17:43 +00005261 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005262 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005263 cast<LabelDecl>(LD), SourceLocation(),
5264 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005265}
Mike Stump1eb44332009-09-09 15:08:12 +00005266
Douglas Gregor43959a92009-08-20 07:17:43 +00005267template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005268StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005269TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5270 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5271 if (SubStmt.isInvalid())
5272 return StmtError();
5273
5274 // TODO: transform attributes
5275 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5276 return S;
5277
5278 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5279 S->getAttrs(),
5280 SubStmt.get());
5281}
5282
5283template<typename Derived>
5284StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005285TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005286 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005287 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005288 VarDecl *ConditionVar = 0;
5289 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005290 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005291 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005292 getDerived().TransformDefinition(
5293 S->getConditionVariable()->getLocation(),
5294 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005295 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005296 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005297 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005298 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005299
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005300 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005301 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005302
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005303 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005304 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005305 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005306 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005307 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005308 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005309
John McCall9ae2f072010-08-23 23:25:46 +00005310 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005311 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005312 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005313
John McCall9ae2f072010-08-23 23:25:46 +00005314 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5315 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005316 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005317
Douglas Gregor43959a92009-08-20 07:17:43 +00005318 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005319 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005320 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005321 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005322
Douglas Gregor43959a92009-08-20 07:17:43 +00005323 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005324 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005325 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005326 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005327
Douglas Gregor43959a92009-08-20 07:17:43 +00005328 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005329 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005330 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005331 Then.get() == S->getThen() &&
5332 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005333 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005334
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005335 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005336 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005337 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005338}
5339
5340template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005341StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005342TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005343 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005344 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005345 VarDecl *ConditionVar = 0;
5346 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005347 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005348 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005349 getDerived().TransformDefinition(
5350 S->getConditionVariable()->getLocation(),
5351 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005352 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005353 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005354 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005355 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005356
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005357 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005358 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005359 }
Mike Stump1eb44332009-09-09 15:08:12 +00005360
Douglas Gregor43959a92009-08-20 07:17:43 +00005361 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005362 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005363 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005364 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005365 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005366 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005367
Douglas Gregor43959a92009-08-20 07:17:43 +00005368 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005369 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005370 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005371 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005372
Douglas Gregor43959a92009-08-20 07:17:43 +00005373 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005374 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5375 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005376}
Mike Stump1eb44332009-09-09 15:08:12 +00005377
Douglas Gregor43959a92009-08-20 07:17:43 +00005378template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005379StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005380TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005381 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005382 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005383 VarDecl *ConditionVar = 0;
5384 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005385 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005386 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005387 getDerived().TransformDefinition(
5388 S->getConditionVariable()->getLocation(),
5389 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005390 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005391 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005392 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005393 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005394
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005395 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005396 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005397
5398 if (S->getCond()) {
5399 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005400 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005401 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005402 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005403 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005404 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005405 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005406 }
Mike Stump1eb44332009-09-09 15:08:12 +00005407
John McCall9ae2f072010-08-23 23:25:46 +00005408 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5409 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005410 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005411
Douglas Gregor43959a92009-08-20 07:17:43 +00005412 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005413 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005414 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005415 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005416
Douglas Gregor43959a92009-08-20 07:17:43 +00005417 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005418 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005419 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005420 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005421 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005422
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005423 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005424 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005425}
Mike Stump1eb44332009-09-09 15:08:12 +00005426
Douglas Gregor43959a92009-08-20 07:17:43 +00005427template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005428StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005429TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005430 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005431 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005432 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005433 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005434
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005435 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005436 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005437 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005438 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005439
Douglas Gregor43959a92009-08-20 07:17:43 +00005440 if (!getDerived().AlwaysRebuild() &&
5441 Cond.get() == S->getCond() &&
5442 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005443 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005444
John McCall9ae2f072010-08-23 23:25:46 +00005445 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5446 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005447 S->getRParenLoc());
5448}
Mike Stump1eb44332009-09-09 15:08:12 +00005449
Douglas Gregor43959a92009-08-20 07:17:43 +00005450template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005451StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005452TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005453 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005454 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005455 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005456 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005457
Douglas Gregor43959a92009-08-20 07:17:43 +00005458 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005459 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005460 VarDecl *ConditionVar = 0;
5461 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005462 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005463 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005464 getDerived().TransformDefinition(
5465 S->getConditionVariable()->getLocation(),
5466 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005467 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005468 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005469 } else {
5470 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005471
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005472 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005473 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005474
5475 if (S->getCond()) {
5476 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005477 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005478 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005479 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005480 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005481
John McCall9ae2f072010-08-23 23:25:46 +00005482 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005483 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005484 }
Mike Stump1eb44332009-09-09 15:08:12 +00005485
Chad Rosier4a9d7952012-08-08 18:46:20 +00005486 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005487 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005488 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005489
Douglas Gregor43959a92009-08-20 07:17:43 +00005490 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005491 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005492 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005493 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005494
Richard Smith41956372013-01-14 22:39:08 +00005495 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005496 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005497 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005498
Douglas Gregor43959a92009-08-20 07:17:43 +00005499 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005500 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005501 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005502 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005503
Douglas Gregor43959a92009-08-20 07:17:43 +00005504 if (!getDerived().AlwaysRebuild() &&
5505 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005506 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005507 Inc.get() == S->getInc() &&
5508 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005509 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005510
Douglas Gregor43959a92009-08-20 07:17:43 +00005511 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005512 Init.get(), FullCond, ConditionVar,
5513 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005514}
5515
5516template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005517StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005518TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005519 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5520 S->getLabel());
5521 if (!LD)
5522 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005523
Douglas Gregor43959a92009-08-20 07:17:43 +00005524 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005525 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005526 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005527}
5528
5529template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005530StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005531TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005532 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005533 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005534 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005535 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005536
Douglas Gregor43959a92009-08-20 07:17:43 +00005537 if (!getDerived().AlwaysRebuild() &&
5538 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005539 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005540
5541 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005542 Target.get());
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>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005548 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005549}
Mike Stump1eb44332009-09-09 15:08:12 +00005550
Douglas Gregor43959a92009-08-20 07:17:43 +00005551template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005552StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005553TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005554 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005555}
Mike Stump1eb44332009-09-09 15:08:12 +00005556
Douglas Gregor43959a92009-08-20 07:17:43 +00005557template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005558StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005559TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005560 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005561 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005562 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005563
Mike Stump1eb44332009-09-09 15:08:12 +00005564 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005565 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005566 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005567}
Mike Stump1eb44332009-09-09 15:08:12 +00005568
Douglas Gregor43959a92009-08-20 07:17:43 +00005569template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005570StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005571TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005572 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005573 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005574 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5575 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005576 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5577 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005578 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005579 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005580
Douglas Gregor43959a92009-08-20 07:17:43 +00005581 if (Transformed != *D)
5582 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005583
Douglas Gregor43959a92009-08-20 07:17:43 +00005584 Decls.push_back(Transformed);
5585 }
Mike Stump1eb44332009-09-09 15:08:12 +00005586
Douglas Gregor43959a92009-08-20 07:17:43 +00005587 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005588 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005589
5590 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005591 S->getStartLoc(), S->getEndLoc());
5592}
Mike Stump1eb44332009-09-09 15:08:12 +00005593
Douglas Gregor43959a92009-08-20 07:17:43 +00005594template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005595StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005596TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005597
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005598 SmallVector<Expr*, 8> Constraints;
5599 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005600 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005601
John McCall60d7b3a2010-08-24 06:29:42 +00005602 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005603 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005604
5605 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005606
Anders Carlsson703e3942010-01-24 05:50:09 +00005607 // Go through the outputs.
5608 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005609 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005610
Anders Carlsson703e3942010-01-24 05:50:09 +00005611 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005612 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005613
Anders Carlsson703e3942010-01-24 05:50:09 +00005614 // Transform the output expr.
5615 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005616 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005617 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005618 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005619
Anders Carlsson703e3942010-01-24 05:50:09 +00005620 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005621
John McCall9ae2f072010-08-23 23:25:46 +00005622 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005623 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005624
Anders Carlsson703e3942010-01-24 05:50:09 +00005625 // Go through the inputs.
5626 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005627 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005628
Anders Carlsson703e3942010-01-24 05:50:09 +00005629 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005630 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005631
Anders Carlsson703e3942010-01-24 05:50:09 +00005632 // Transform the input expr.
5633 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005634 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005635 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005636 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005637
Anders Carlsson703e3942010-01-24 05:50:09 +00005638 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005639
John McCall9ae2f072010-08-23 23:25:46 +00005640 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005641 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005642
Anders Carlsson703e3942010-01-24 05:50:09 +00005643 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005644 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005645
5646 // Go through the clobbers.
5647 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005648 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005649
5650 // No need to transform the asm string literal.
5651 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005652 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5653 S->isVolatile(), S->getNumOutputs(),
5654 S->getNumInputs(), Names.data(),
5655 Constraints, Exprs, AsmString.get(),
5656 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005657}
5658
Chad Rosier8cd64b42012-06-11 20:47:18 +00005659template<typename Derived>
5660StmtResult
5661TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005662 ArrayRef<Token> AsmToks =
5663 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005664
John McCallaeeacf72013-05-03 00:10:13 +00005665 bool HadError = false, HadChange = false;
5666
5667 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
5668 SmallVector<Expr*, 8> TransformedExprs;
5669 TransformedExprs.reserve(SrcExprs.size());
5670 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
5671 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
5672 if (!Result.isUsable()) {
5673 HadError = true;
5674 } else {
5675 HadChange |= (Result.get() != SrcExprs[i]);
5676 TransformedExprs.push_back(Result.take());
5677 }
5678 }
5679
5680 if (HadError) return StmtError();
5681 if (!HadChange && !getDerived().AlwaysRebuild())
5682 return Owned(S);
5683
Chad Rosier7bd092b2012-08-15 16:53:30 +00005684 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallaeeacf72013-05-03 00:10:13 +00005685 AsmToks, S->getAsmString(),
5686 S->getNumOutputs(), S->getNumInputs(),
5687 S->getAllConstraints(), S->getClobbers(),
5688 TransformedExprs, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005689}
Douglas Gregor43959a92009-08-20 07:17:43 +00005690
5691template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005692StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005693TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005694 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005695 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005696 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005697 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005698
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005699 // Transform the @catch statements (if present).
5700 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005701 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005702 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005703 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005704 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005705 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005706 if (Catch.get() != S->getCatchStmt(I))
5707 AnyCatchChanged = true;
5708 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005709 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005710
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005711 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005712 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005713 if (S->getFinallyStmt()) {
5714 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5715 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005716 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005717 }
5718
5719 // If nothing changed, just retain this statement.
5720 if (!getDerived().AlwaysRebuild() &&
5721 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005722 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005723 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005724 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005725
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005726 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005727 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005728 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005729}
Mike Stump1eb44332009-09-09 15:08:12 +00005730
Douglas Gregor43959a92009-08-20 07:17:43 +00005731template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005732StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005733TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005734 // Transform the @catch parameter, if there is one.
5735 VarDecl *Var = 0;
5736 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5737 TypeSourceInfo *TSInfo = 0;
5738 if (FromVar->getTypeSourceInfo()) {
5739 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5740 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005741 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005742 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005743
Douglas Gregorbe270a02010-04-26 17:57:08 +00005744 QualType T;
5745 if (TSInfo)
5746 T = TSInfo->getType();
5747 else {
5748 T = getDerived().TransformType(FromVar->getType());
5749 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005750 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005751 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005752
Douglas Gregorbe270a02010-04-26 17:57:08 +00005753 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5754 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005755 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005756 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005757
John McCall60d7b3a2010-08-24 06:29:42 +00005758 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005759 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005760 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005761
5762 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005763 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005764 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005765}
Mike Stump1eb44332009-09-09 15:08:12 +00005766
Douglas Gregor43959a92009-08-20 07:17:43 +00005767template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005768StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005769TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005770 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005771 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005772 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005773 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005774
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005775 // If nothing changed, just retain this statement.
5776 if (!getDerived().AlwaysRebuild() &&
5777 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005778 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005779
5780 // Build a new statement.
5781 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005782 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005783}
Mike Stump1eb44332009-09-09 15:08:12 +00005784
Douglas Gregor43959a92009-08-20 07:17:43 +00005785template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005786StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005787TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005788 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005789 if (S->getThrowExpr()) {
5790 Operand = getDerived().TransformExpr(S->getThrowExpr());
5791 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005792 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005793 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005794
Douglas Gregord1377b22010-04-22 21:44:01 +00005795 if (!getDerived().AlwaysRebuild() &&
5796 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005797 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005798
John McCall9ae2f072010-08-23 23:25:46 +00005799 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005800}
Mike Stump1eb44332009-09-09 15:08:12 +00005801
Douglas Gregor43959a92009-08-20 07:17:43 +00005802template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005803StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005804TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005805 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005806 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005807 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005808 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005809 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005810 Object =
5811 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5812 Object.get());
5813 if (Object.isInvalid())
5814 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005815
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005816 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005817 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005818 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005819 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005820
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005821 // If nothing change, just retain the current statement.
5822 if (!getDerived().AlwaysRebuild() &&
5823 Object.get() == S->getSynchExpr() &&
5824 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005825 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005826
5827 // Build a new statement.
5828 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005829 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005830}
5831
5832template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005833StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005834TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5835 ObjCAutoreleasePoolStmt *S) {
5836 // Transform the body.
5837 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5838 if (Body.isInvalid())
5839 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005840
John McCallf85e1932011-06-15 23:02:42 +00005841 // If nothing changed, just retain this statement.
5842 if (!getDerived().AlwaysRebuild() &&
5843 Body.get() == S->getSubStmt())
5844 return SemaRef.Owned(S);
5845
5846 // Build a new statement.
5847 return getDerived().RebuildObjCAutoreleasePoolStmt(
5848 S->getAtLoc(), Body.get());
5849}
5850
5851template<typename Derived>
5852StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005853TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005854 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005855 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005856 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005857 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005858 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005859
Douglas Gregorc3203e72010-04-22 23:10:45 +00005860 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005861 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005862 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005863 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005864
Douglas Gregorc3203e72010-04-22 23:10:45 +00005865 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005866 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005867 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005868 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005869
Douglas Gregorc3203e72010-04-22 23:10:45 +00005870 // If nothing changed, just retain this statement.
5871 if (!getDerived().AlwaysRebuild() &&
5872 Element.get() == S->getElement() &&
5873 Collection.get() == S->getCollection() &&
5874 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005875 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005876
Douglas Gregorc3203e72010-04-22 23:10:45 +00005877 // Build a new statement.
5878 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005879 Element.get(),
5880 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005881 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005882 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005883}
5884
5885
5886template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005887StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005888TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5889 // Transform the exception declaration, if any.
5890 VarDecl *Var = 0;
5891 if (S->getExceptionDecl()) {
5892 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005893 TypeSourceInfo *T = getDerived().TransformType(
5894 ExceptionDecl->getTypeSourceInfo());
5895 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005896 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005897
Douglas Gregor83cb9422010-09-09 17:09:21 +00005898 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005899 ExceptionDecl->getInnerLocStart(),
5900 ExceptionDecl->getLocation(),
5901 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005902 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005903 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005904 }
Mike Stump1eb44332009-09-09 15:08:12 +00005905
Douglas Gregor43959a92009-08-20 07:17:43 +00005906 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005907 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005908 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005909 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005910
Douglas Gregor43959a92009-08-20 07:17:43 +00005911 if (!getDerived().AlwaysRebuild() &&
5912 !Var &&
5913 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005914 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005915
5916 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5917 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005918 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005919}
Mike Stump1eb44332009-09-09 15:08:12 +00005920
Douglas Gregor43959a92009-08-20 07:17:43 +00005921template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005922StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005923TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5924 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005925 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005926 = getDerived().TransformCompoundStmt(S->getTryBlock());
5927 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005928 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005929
Douglas Gregor43959a92009-08-20 07:17:43 +00005930 // Transform the handlers.
5931 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005932 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00005933 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005934 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005935 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5936 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005937 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005938
Douglas Gregor43959a92009-08-20 07:17:43 +00005939 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5940 Handlers.push_back(Handler.takeAs<Stmt>());
5941 }
Mike Stump1eb44332009-09-09 15:08:12 +00005942
Douglas Gregor43959a92009-08-20 07:17:43 +00005943 if (!getDerived().AlwaysRebuild() &&
5944 TryBlock.get() == S->getTryBlock() &&
5945 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005946 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005947
John McCall9ae2f072010-08-23 23:25:46 +00005948 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005949 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00005950}
Mike Stump1eb44332009-09-09 15:08:12 +00005951
Richard Smithad762fc2011-04-14 22:09:26 +00005952template<typename Derived>
5953StmtResult
5954TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5955 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5956 if (Range.isInvalid())
5957 return StmtError();
5958
5959 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5960 if (BeginEnd.isInvalid())
5961 return StmtError();
5962
5963 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5964 if (Cond.isInvalid())
5965 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005966 if (Cond.get())
5967 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5968 if (Cond.isInvalid())
5969 return StmtError();
5970 if (Cond.get())
5971 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005972
5973 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5974 if (Inc.isInvalid())
5975 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005976 if (Inc.get())
5977 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005978
5979 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5980 if (LoopVar.isInvalid())
5981 return StmtError();
5982
5983 StmtResult NewStmt = S;
5984 if (getDerived().AlwaysRebuild() ||
5985 Range.get() != S->getRangeStmt() ||
5986 BeginEnd.get() != S->getBeginEndStmt() ||
5987 Cond.get() != S->getCond() ||
5988 Inc.get() != S->getInc() ||
Douglas Gregor39b60dc2013-05-02 18:35:56 +00005989 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smithad762fc2011-04-14 22:09:26 +00005990 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5991 S->getColonLoc(), Range.get(),
5992 BeginEnd.get(), Cond.get(),
5993 Inc.get(), LoopVar.get(),
5994 S->getRParenLoc());
Douglas Gregor39b60dc2013-05-02 18:35:56 +00005995 if (NewStmt.isInvalid())
5996 return StmtError();
5997 }
Richard Smithad762fc2011-04-14 22:09:26 +00005998
5999 StmtResult Body = getDerived().TransformStmt(S->getBody());
6000 if (Body.isInvalid())
6001 return StmtError();
6002
6003 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6004 // it now so we have a new statement to attach the body to.
Douglas Gregor39b60dc2013-05-02 18:35:56 +00006005 if (Body.get() != S->getBody() && NewStmt.get() == S) {
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 if (NewStmt.get() == S)
6016 return SemaRef.Owned(S);
6017
6018 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6019}
6020
John Wiegley28bbe4b2011-04-28 01:08:34 +00006021template<typename Derived>
6022StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00006023TreeTransform<Derived>::TransformMSDependentExistsStmt(
6024 MSDependentExistsStmt *S) {
6025 // Transform the nested-name-specifier, if any.
6026 NestedNameSpecifierLoc QualifierLoc;
6027 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006028 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00006029 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6030 if (!QualifierLoc)
6031 return StmtError();
6032 }
6033
6034 // Transform the declaration name.
6035 DeclarationNameInfo NameInfo = S->getNameInfo();
6036 if (NameInfo.getName()) {
6037 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6038 if (!NameInfo.getName())
6039 return StmtError();
6040 }
6041
6042 // Check whether anything changed.
6043 if (!getDerived().AlwaysRebuild() &&
6044 QualifierLoc == S->getQualifierLoc() &&
6045 NameInfo.getName() == S->getNameInfo().getName())
6046 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006047
Douglas Gregorba0513d2011-10-25 01:33:02 +00006048 // Determine whether this name exists, if we can.
6049 CXXScopeSpec SS;
6050 SS.Adopt(QualifierLoc);
6051 bool Dependent = false;
6052 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6053 case Sema::IER_Exists:
6054 if (S->isIfExists())
6055 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006056
Douglas Gregorba0513d2011-10-25 01:33:02 +00006057 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6058
6059 case Sema::IER_DoesNotExist:
6060 if (S->isIfNotExists())
6061 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006062
Douglas Gregorba0513d2011-10-25 01:33:02 +00006063 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006064
Douglas Gregorba0513d2011-10-25 01:33:02 +00006065 case Sema::IER_Dependent:
6066 Dependent = true;
6067 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006068
Douglas Gregor65019ac2011-10-25 03:44:56 +00006069 case Sema::IER_Error:
6070 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006071 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006072
Douglas Gregorba0513d2011-10-25 01:33:02 +00006073 // We need to continue with the instantiation, so do so now.
6074 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6075 if (SubStmt.isInvalid())
6076 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006077
Douglas Gregorba0513d2011-10-25 01:33:02 +00006078 // If we have resolved the name, just transform to the substatement.
6079 if (!Dependent)
6080 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006081
Douglas Gregorba0513d2011-10-25 01:33:02 +00006082 // The name is still dependent, so build a dependent expression again.
6083 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6084 S->isIfExists(),
6085 QualifierLoc,
6086 NameInfo,
6087 SubStmt.get());
6088}
6089
6090template<typename Derived>
John McCall76da55d2013-04-16 07:28:30 +00006091ExprResult
6092TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6093 NestedNameSpecifierLoc QualifierLoc;
6094 if (E->getQualifierLoc()) {
6095 QualifierLoc
6096 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6097 if (!QualifierLoc)
6098 return ExprError();
6099 }
6100
6101 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6102 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6103 if (!PD)
6104 return ExprError();
6105
6106 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6107 if (Base.isInvalid())
6108 return ExprError();
6109
6110 return new (SemaRef.getASTContext())
6111 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6112 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6113 QualifierLoc, E->getMemberLoc());
6114}
6115
6116template<typename Derived>
Douglas Gregorba0513d2011-10-25 01:33:02 +00006117StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006118TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6119 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6120 if(TryBlock.isInvalid()) return StmtError();
6121
6122 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6123 if(!getDerived().AlwaysRebuild() &&
6124 TryBlock.get() == S->getTryBlock() &&
6125 Handler.get() == S->getHandler())
6126 return SemaRef.Owned(S);
6127
6128 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6129 S->getTryLoc(),
6130 TryBlock.take(),
6131 Handler.take());
6132}
6133
6134template<typename Derived>
6135StmtResult
6136TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6137 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6138 if(Block.isInvalid()) return StmtError();
6139
6140 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6141 Block.take());
6142}
6143
6144template<typename Derived>
6145StmtResult
6146TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6147 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6148 if(FilterExpr.isInvalid()) return StmtError();
6149
6150 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6151 if(Block.isInvalid()) return StmtError();
6152
6153 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6154 FilterExpr.take(),
6155 Block.take());
6156}
6157
6158template<typename Derived>
6159StmtResult
6160TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6161 if(isa<SEHFinallyStmt>(Handler))
6162 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6163 else
6164 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6165}
6166
Douglas Gregor43959a92009-08-20 07:17:43 +00006167//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006168// Expression transformation
6169//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006170template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006171ExprResult
John McCall454feb92009-12-08 09:21:05 +00006172TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006173 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006174}
Mike Stump1eb44332009-09-09 15:08:12 +00006175
6176template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006177ExprResult
John McCall454feb92009-12-08 09:21:05 +00006178TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006179 NestedNameSpecifierLoc QualifierLoc;
6180 if (E->getQualifierLoc()) {
6181 QualifierLoc
6182 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6183 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006184 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006185 }
John McCalldbd872f2009-12-08 09:08:17 +00006186
6187 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006188 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6189 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006190 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006191 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006192
John McCallec8045d2010-08-17 21:27:17 +00006193 DeclarationNameInfo NameInfo = E->getNameInfo();
6194 if (NameInfo.getName()) {
6195 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6196 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006197 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006198 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006199
6200 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006201 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006202 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006203 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006204 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006205
6206 // Mark it referenced in the new context regardless.
6207 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006208 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006209
John McCall3fa5cae2010-10-26 07:05:15 +00006210 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006211 }
John McCalldbd872f2009-12-08 09:08:17 +00006212
6213 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006214 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006215 TemplateArgs = &TransArgs;
6216 TransArgs.setLAngleLoc(E->getLAngleLoc());
6217 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006218 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6219 E->getNumTemplateArgs(),
6220 TransArgs))
6221 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006222 }
6223
Chad Rosier4a9d7952012-08-08 18:46:20 +00006224 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006225 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006226}
Mike Stump1eb44332009-09-09 15:08:12 +00006227
Douglas Gregorb98b1992009-08-11 05:31:07 +00006228template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006229ExprResult
John McCall454feb92009-12-08 09:21:05 +00006230TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006231 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006232}
Mike Stump1eb44332009-09-09 15:08:12 +00006233
Douglas Gregorb98b1992009-08-11 05:31:07 +00006234template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006235ExprResult
John McCall454feb92009-12-08 09:21:05 +00006236TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006237 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006238}
Mike Stump1eb44332009-09-09 15:08:12 +00006239
Douglas Gregorb98b1992009-08-11 05:31:07 +00006240template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006241ExprResult
John McCall454feb92009-12-08 09:21:05 +00006242TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006243 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006244}
Mike Stump1eb44332009-09-09 15:08:12 +00006245
Douglas Gregorb98b1992009-08-11 05:31:07 +00006246template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006247ExprResult
John McCall454feb92009-12-08 09:21:05 +00006248TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006249 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006250}
Mike Stump1eb44332009-09-09 15:08:12 +00006251
Douglas Gregorb98b1992009-08-11 05:31:07 +00006252template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006253ExprResult
John McCall454feb92009-12-08 09:21:05 +00006254TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006255 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006256}
6257
6258template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006259ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006260TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis391ca9f2013-04-09 01:17:02 +00006261 if (FunctionDecl *FD = E->getDirectCallee())
6262 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smith9fcce652012-03-07 08:35:16 +00006263 return SemaRef.MaybeBindToTemporary(E);
6264}
6265
6266template<typename Derived>
6267ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006268TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6269 ExprResult ControllingExpr =
6270 getDerived().TransformExpr(E->getControllingExpr());
6271 if (ControllingExpr.isInvalid())
6272 return ExprError();
6273
Chris Lattner686775d2011-07-20 06:58:45 +00006274 SmallVector<Expr *, 4> AssocExprs;
6275 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006276 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6277 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6278 if (TS) {
6279 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6280 if (!AssocType)
6281 return ExprError();
6282 AssocTypes.push_back(AssocType);
6283 } else {
6284 AssocTypes.push_back(0);
6285 }
6286
6287 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6288 if (AssocExpr.isInvalid())
6289 return ExprError();
6290 AssocExprs.push_back(AssocExpr.release());
6291 }
6292
6293 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6294 E->getDefaultLoc(),
6295 E->getRParenLoc(),
6296 ControllingExpr.release(),
Dmitri Gribenko80613222013-05-10 13:06:58 +00006297 AssocTypes,
6298 AssocExprs);
Peter Collingbournef111d932011-04-15 00:35:48 +00006299}
6300
6301template<typename Derived>
6302ExprResult
John McCall454feb92009-12-08 09:21:05 +00006303TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006304 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006305 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006306 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006307
Douglas Gregorb98b1992009-08-11 05:31:07 +00006308 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006309 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006310
John McCall9ae2f072010-08-23 23:25:46 +00006311 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006312 E->getRParen());
6313}
6314
Richard Smithefeeccf2012-10-21 03:28:35 +00006315/// \brief The operand of a unary address-of operator has special rules: it's
6316/// allowed to refer to a non-static member of a class even if there's no 'this'
6317/// object available.
6318template<typename Derived>
6319ExprResult
6320TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6321 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6322 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6323 else
6324 return getDerived().TransformExpr(E);
6325}
6326
Mike Stump1eb44332009-09-09 15:08:12 +00006327template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006328ExprResult
John McCall454feb92009-12-08 09:21:05 +00006329TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smith82b00012013-05-21 23:29:46 +00006330 ExprResult SubExpr;
6331 if (E->getOpcode() == UO_AddrOf)
6332 SubExpr = TransformAddressOfOperand(E->getSubExpr());
6333 else
6334 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006335 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006336 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006337
Douglas Gregorb98b1992009-08-11 05:31:07 +00006338 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006339 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006340
Douglas Gregorb98b1992009-08-11 05:31:07 +00006341 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6342 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006343 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006344}
Mike Stump1eb44332009-09-09 15:08:12 +00006345
Douglas Gregorb98b1992009-08-11 05:31:07 +00006346template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006347ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006348TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6349 // Transform the type.
6350 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6351 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006352 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006353
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006354 // Transform all of the components into components similar to what the
6355 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006356 // FIXME: It would be slightly more efficient in the non-dependent case to
6357 // just map FieldDecls, rather than requiring the rebuilder to look for
6358 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006359 // template code that we don't care.
6360 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006361 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006362 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006363 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006364 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6365 const Node &ON = E->getComponent(I);
6366 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006367 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006368 Comp.LocStart = ON.getSourceRange().getBegin();
6369 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006370 switch (ON.getKind()) {
6371 case Node::Array: {
6372 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006373 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006374 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006375 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006376
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006377 ExprChanged = ExprChanged || Index.get() != FromIndex;
6378 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006379 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006380 break;
6381 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006382
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006383 case Node::Field:
6384 case Node::Identifier:
6385 Comp.isBrackets = false;
6386 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006387 if (!Comp.U.IdentInfo)
6388 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006389
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006390 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006391
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006392 case Node::Base:
6393 // Will be recomputed during the rebuild.
6394 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006395 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006396
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006397 Components.push_back(Comp);
6398 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006399
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006400 // If nothing changed, retain the existing expression.
6401 if (!getDerived().AlwaysRebuild() &&
6402 Type == E->getTypeSourceInfo() &&
6403 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006404 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006405
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006406 // Build a new offsetof expression.
6407 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6408 Components.data(), Components.size(),
6409 E->getRParenLoc());
6410}
6411
6412template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006413ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006414TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6415 assert(getDerived().AlreadyTransformed(E->getType()) &&
6416 "opaque value expression requires transformation");
6417 return SemaRef.Owned(E);
6418}
6419
6420template<typename Derived>
6421ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006422TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006423 // Rebuild the syntactic form. The original syntactic form has
6424 // opaque-value expressions in it, so strip those away and rebuild
6425 // the result. This is a really awful way of doing this, but the
6426 // better solution (rebuilding the semantic expressions and
6427 // rebinding OVEs as necessary) doesn't work; we'd need
6428 // TreeTransform to not strip away implicit conversions.
6429 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6430 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006431 if (result.isInvalid()) return ExprError();
6432
6433 // If that gives us a pseudo-object result back, the pseudo-object
6434 // expression must have been an lvalue-to-rvalue conversion which we
6435 // should reapply.
6436 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6437 result = SemaRef.checkPseudoObjectRValue(result.take());
6438
6439 return result;
6440}
6441
6442template<typename Derived>
6443ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006444TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6445 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006446 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006447 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006448
John McCalla93c9342009-12-07 02:54:59 +00006449 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006450 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006451 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006452
John McCall5ab75172009-11-04 07:28:41 +00006453 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006454 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006455
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006456 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6457 E->getKind(),
6458 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006459 }
Mike Stump1eb44332009-09-09 15:08:12 +00006460
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006461 // C++0x [expr.sizeof]p1:
6462 // The operand is either an expression, which is an unevaluated operand
6463 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006464 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6465 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006466
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006467 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6468 if (SubExpr.isInvalid())
6469 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006470
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006471 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6472 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006473
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006474 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6475 E->getOperatorLoc(),
6476 E->getKind(),
6477 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006478}
Mike Stump1eb44332009-09-09 15:08:12 +00006479
Douglas Gregorb98b1992009-08-11 05:31:07 +00006480template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006481ExprResult
John McCall454feb92009-12-08 09:21:05 +00006482TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006483 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006484 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006485 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006486
John McCall60d7b3a2010-08-24 06:29:42 +00006487 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006488 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006489 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006490
6491
Douglas Gregorb98b1992009-08-11 05:31:07 +00006492 if (!getDerived().AlwaysRebuild() &&
6493 LHS.get() == E->getLHS() &&
6494 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006495 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006496
John McCall9ae2f072010-08-23 23:25:46 +00006497 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006498 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006499 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006500 E->getRBracketLoc());
6501}
Mike Stump1eb44332009-09-09 15:08:12 +00006502
6503template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006504ExprResult
John McCall454feb92009-12-08 09:21:05 +00006505TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006506 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006507 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006508 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006509 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006510
6511 // Transform arguments.
6512 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006513 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006514 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006515 &ArgChanged))
6516 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006517
Douglas Gregorb98b1992009-08-11 05:31:07 +00006518 if (!getDerived().AlwaysRebuild() &&
6519 Callee.get() == E->getCallee() &&
6520 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006521 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006522
Douglas Gregorb98b1992009-08-11 05:31:07 +00006523 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006524 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006525 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006526 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006527 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006528 E->getRParenLoc());
6529}
Mike Stump1eb44332009-09-09 15:08:12 +00006530
6531template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006532ExprResult
John McCall454feb92009-12-08 09:21:05 +00006533TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006534 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006535 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006536 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006537
Douglas Gregor40d96a62011-02-28 21:54:11 +00006538 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006539 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006540 QualifierLoc
6541 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006542
Douglas Gregor40d96a62011-02-28 21:54:11 +00006543 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006544 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006545 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006546 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006547
Eli Friedmanf595cc42009-12-04 06:40:45 +00006548 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006549 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6550 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006551 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006552 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006553
John McCall6bb80172010-03-30 21:47:33 +00006554 NamedDecl *FoundDecl = E->getFoundDecl();
6555 if (FoundDecl == E->getMemberDecl()) {
6556 FoundDecl = Member;
6557 } else {
6558 FoundDecl = cast_or_null<NamedDecl>(
6559 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6560 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006561 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006562 }
6563
Douglas Gregorb98b1992009-08-11 05:31:07 +00006564 if (!getDerived().AlwaysRebuild() &&
6565 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006566 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006567 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006568 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006569 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006570
Anders Carlsson1f240322009-12-22 05:24:09 +00006571 // Mark it referenced in the new context regardless.
6572 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006573 SemaRef.MarkMemberReferenced(E);
6574
John McCall3fa5cae2010-10-26 07:05:15 +00006575 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006576 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006577
John McCalld5532b62009-11-23 01:53:49 +00006578 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006579 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006580 TransArgs.setLAngleLoc(E->getLAngleLoc());
6581 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006582 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6583 E->getNumTemplateArgs(),
6584 TransArgs))
6585 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006586 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006587
Douglas Gregorb98b1992009-08-11 05:31:07 +00006588 // FIXME: Bogus source location for the operator
6589 SourceLocation FakeOperatorLoc
6590 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6591
John McCallc2233c52010-01-15 08:34:02 +00006592 // FIXME: to do this check properly, we will need to preserve the
6593 // first-qualifier-in-scope here, just in case we had a dependent
6594 // base (and therefore couldn't do the check) and a
6595 // nested-name-qualifier (and therefore could do the lookup).
6596 NamedDecl *FirstQualifierInScope = 0;
6597
John McCall9ae2f072010-08-23 23:25:46 +00006598 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006599 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006600 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006601 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006602 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006603 Member,
John McCall6bb80172010-03-30 21:47:33 +00006604 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006605 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006606 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006607 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006608}
Mike Stump1eb44332009-09-09 15:08:12 +00006609
Douglas Gregorb98b1992009-08-11 05:31:07 +00006610template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006611ExprResult
John McCall454feb92009-12-08 09:21:05 +00006612TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006613 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006614 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006615 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006616
John McCall60d7b3a2010-08-24 06:29:42 +00006617 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006618 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006619 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006620
Douglas Gregorb98b1992009-08-11 05:31:07 +00006621 if (!getDerived().AlwaysRebuild() &&
6622 LHS.get() == E->getLHS() &&
6623 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006624 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006625
Lang Hamesbe9af122012-10-02 04:45:10 +00006626 Sema::FPContractStateRAII FPContractState(getSema());
6627 getSema().FPFeatures.fp_contract = E->isFPContractable();
6628
Douglas Gregorb98b1992009-08-11 05:31:07 +00006629 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006630 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006631}
6632
Mike Stump1eb44332009-09-09 15:08:12 +00006633template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006634ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006636 CompoundAssignOperator *E) {
6637 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006638}
Mike Stump1eb44332009-09-09 15:08:12 +00006639
Douglas Gregorb98b1992009-08-11 05:31:07 +00006640template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006641ExprResult TreeTransform<Derived>::
6642TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6643 // Just rebuild the common and RHS expressions and see whether we
6644 // get any changes.
6645
6646 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6647 if (commonExpr.isInvalid())
6648 return ExprError();
6649
6650 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6651 if (rhs.isInvalid())
6652 return ExprError();
6653
6654 if (!getDerived().AlwaysRebuild() &&
6655 commonExpr.get() == e->getCommon() &&
6656 rhs.get() == e->getFalseExpr())
6657 return SemaRef.Owned(e);
6658
6659 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6660 e->getQuestionLoc(),
6661 0,
6662 e->getColonLoc(),
6663 rhs.get());
6664}
6665
6666template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006667ExprResult
John McCall454feb92009-12-08 09:21:05 +00006668TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006669 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006670 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006671 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006672
John McCall60d7b3a2010-08-24 06:29:42 +00006673 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006674 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006675 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006676
John McCall60d7b3a2010-08-24 06:29:42 +00006677 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006678 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006679 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006680
Douglas Gregorb98b1992009-08-11 05:31:07 +00006681 if (!getDerived().AlwaysRebuild() &&
6682 Cond.get() == E->getCond() &&
6683 LHS.get() == E->getLHS() &&
6684 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006685 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006686
John McCall9ae2f072010-08-23 23:25:46 +00006687 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006688 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006689 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006690 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006691 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006692}
Mike Stump1eb44332009-09-09 15:08:12 +00006693
6694template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006695ExprResult
John McCall454feb92009-12-08 09:21:05 +00006696TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006697 // Implicit casts are eliminated during transformation, since they
6698 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006699 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006700}
Mike Stump1eb44332009-09-09 15:08:12 +00006701
Douglas Gregorb98b1992009-08-11 05:31:07 +00006702template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006703ExprResult
John McCall454feb92009-12-08 09:21:05 +00006704TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006705 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6706 if (!Type)
6707 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006708
John McCall60d7b3a2010-08-24 06:29:42 +00006709 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006710 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006711 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006712 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006713
Douglas Gregorb98b1992009-08-11 05:31:07 +00006714 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006715 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006716 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006717 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006718
John McCall9d125032010-01-15 18:39:57 +00006719 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006720 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006721 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006722 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006723}
Mike Stump1eb44332009-09-09 15:08:12 +00006724
Douglas Gregorb98b1992009-08-11 05:31:07 +00006725template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006726ExprResult
John McCall454feb92009-12-08 09:21:05 +00006727TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006728 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6729 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6730 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006731 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006732
John McCall60d7b3a2010-08-24 06:29:42 +00006733 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006734 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006735 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006736
Douglas Gregorb98b1992009-08-11 05:31:07 +00006737 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006738 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006739 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006740 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006741
John McCall1d7d8d62010-01-19 22:33:45 +00006742 // Note: the expression type doesn't necessarily match the
6743 // type-as-written, but that's okay, because it should always be
6744 // derivable from the initializer.
6745
John McCall42f56b52010-01-18 19:35:47 +00006746 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006747 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006748 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006749}
Mike Stump1eb44332009-09-09 15:08:12 +00006750
Douglas Gregorb98b1992009-08-11 05:31:07 +00006751template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006752ExprResult
John McCall454feb92009-12-08 09:21:05 +00006753TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006754 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006755 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006756 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006757
Douglas Gregorb98b1992009-08-11 05:31:07 +00006758 if (!getDerived().AlwaysRebuild() &&
6759 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006760 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006761
Douglas Gregorb98b1992009-08-11 05:31:07 +00006762 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006763 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006764 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006765 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006766 E->getAccessorLoc(),
6767 E->getAccessor());
6768}
Mike Stump1eb44332009-09-09 15:08:12 +00006769
Douglas Gregorb98b1992009-08-11 05:31:07 +00006770template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006771ExprResult
John McCall454feb92009-12-08 09:21:05 +00006772TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006773 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006774
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006775 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006776 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006777 Inits, &InitChanged))
6778 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006779
Douglas Gregorb98b1992009-08-11 05:31:07 +00006780 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006781 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006782
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006783 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006784 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006785}
Mike Stump1eb44332009-09-09 15:08:12 +00006786
Douglas Gregorb98b1992009-08-11 05:31:07 +00006787template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006788ExprResult
John McCall454feb92009-12-08 09:21:05 +00006789TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006790 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006791
Douglas Gregor43959a92009-08-20 07:17:43 +00006792 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006793 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006794 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006795 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006796
Douglas Gregor43959a92009-08-20 07:17:43 +00006797 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006798 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006799 bool ExprChanged = false;
6800 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6801 DEnd = E->designators_end();
6802 D != DEnd; ++D) {
6803 if (D->isFieldDesignator()) {
6804 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6805 D->getDotLoc(),
6806 D->getFieldLoc()));
6807 continue;
6808 }
Mike Stump1eb44332009-09-09 15:08:12 +00006809
Douglas Gregorb98b1992009-08-11 05:31:07 +00006810 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006811 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006812 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006813 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006814
6815 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006816 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006817
Douglas Gregorb98b1992009-08-11 05:31:07 +00006818 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6819 ArrayExprs.push_back(Index.release());
6820 continue;
6821 }
Mike Stump1eb44332009-09-09 15:08:12 +00006822
Douglas Gregorb98b1992009-08-11 05:31:07 +00006823 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006824 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006825 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6826 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006827 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006828
John McCall60d7b3a2010-08-24 06:29:42 +00006829 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006830 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006831 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006832
6833 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006834 End.get(),
6835 D->getLBracketLoc(),
6836 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006837
Douglas Gregorb98b1992009-08-11 05:31:07 +00006838 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6839 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006840
Douglas Gregorb98b1992009-08-11 05:31:07 +00006841 ArrayExprs.push_back(Start.release());
6842 ArrayExprs.push_back(End.release());
6843 }
Mike Stump1eb44332009-09-09 15:08:12 +00006844
Douglas Gregorb98b1992009-08-11 05:31:07 +00006845 if (!getDerived().AlwaysRebuild() &&
6846 Init.get() == E->getInit() &&
6847 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006848 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006849
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006850 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006851 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006852 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006853}
Mike Stump1eb44332009-09-09 15:08:12 +00006854
Douglas Gregorb98b1992009-08-11 05:31:07 +00006855template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006856ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006857TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006858 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006859 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006860
Douglas Gregor5557b252009-10-28 00:29:27 +00006861 // FIXME: Will we ever have proper type location here? Will we actually
6862 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006863 QualType T = getDerived().TransformType(E->getType());
6864 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006865 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006866
Douglas Gregorb98b1992009-08-11 05:31:07 +00006867 if (!getDerived().AlwaysRebuild() &&
6868 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006869 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006870
Douglas Gregorb98b1992009-08-11 05:31:07 +00006871 return getDerived().RebuildImplicitValueInitExpr(T);
6872}
Mike Stump1eb44332009-09-09 15:08:12 +00006873
Douglas Gregorb98b1992009-08-11 05:31:07 +00006874template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006875ExprResult
John McCall454feb92009-12-08 09:21:05 +00006876TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006877 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6878 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006879 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006880
John McCall60d7b3a2010-08-24 06:29:42 +00006881 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006882 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006883 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006884
Douglas Gregorb98b1992009-08-11 05:31:07 +00006885 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006886 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006887 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006888 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006889
John McCall9ae2f072010-08-23 23:25:46 +00006890 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006891 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006892}
6893
6894template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006895ExprResult
John McCall454feb92009-12-08 09:21:05 +00006896TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006897 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006898 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00006899 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6900 &ArgumentChanged))
6901 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006902
Douglas Gregorb98b1992009-08-11 05:31:07 +00006903 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006904 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006905 E->getRParenLoc());
6906}
Mike Stump1eb44332009-09-09 15:08:12 +00006907
Douglas Gregorb98b1992009-08-11 05:31:07 +00006908/// \brief Transform an address-of-label expression.
6909///
6910/// By default, the transformation of an address-of-label expression always
6911/// rebuilds the expression, so that the label identifier can be resolved to
6912/// the corresponding label statement by semantic analysis.
6913template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006914ExprResult
John McCall454feb92009-12-08 09:21:05 +00006915TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006916 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6917 E->getLabel());
6918 if (!LD)
6919 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006920
Douglas Gregorb98b1992009-08-11 05:31:07 +00006921 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006922 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006923}
Mike Stump1eb44332009-09-09 15:08:12 +00006924
6925template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006926ExprResult
John McCall454feb92009-12-08 09:21:05 +00006927TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006928 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006929 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006930 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006931 if (SubStmt.isInvalid()) {
6932 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006933 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006934 }
Mike Stump1eb44332009-09-09 15:08:12 +00006935
Douglas Gregorb98b1992009-08-11 05:31:07 +00006936 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006937 SubStmt.get() == E->getSubStmt()) {
6938 // Calling this an 'error' is unintuitive, but it does the right thing.
6939 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006940 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006941 }
Mike Stump1eb44332009-09-09 15:08:12 +00006942
6943 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006944 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006945 E->getRParenLoc());
6946}
Mike Stump1eb44332009-09-09 15:08:12 +00006947
Douglas Gregorb98b1992009-08-11 05:31:07 +00006948template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006949ExprResult
John McCall454feb92009-12-08 09:21:05 +00006950TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006951 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006952 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006953 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006954
John McCall60d7b3a2010-08-24 06:29:42 +00006955 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006956 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006957 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006958
John McCall60d7b3a2010-08-24 06:29:42 +00006959 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006960 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006961 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006962
Douglas Gregorb98b1992009-08-11 05:31:07 +00006963 if (!getDerived().AlwaysRebuild() &&
6964 Cond.get() == E->getCond() &&
6965 LHS.get() == E->getLHS() &&
6966 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006967 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006968
Douglas Gregorb98b1992009-08-11 05:31:07 +00006969 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006970 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006971 E->getRParenLoc());
6972}
Mike Stump1eb44332009-09-09 15:08:12 +00006973
Douglas Gregorb98b1992009-08-11 05:31:07 +00006974template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006975ExprResult
John McCall454feb92009-12-08 09:21:05 +00006976TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006977 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006978}
6979
6980template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006981ExprResult
John McCall454feb92009-12-08 09:21:05 +00006982TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006983 switch (E->getOperator()) {
6984 case OO_New:
6985 case OO_Delete:
6986 case OO_Array_New:
6987 case OO_Array_Delete:
6988 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006989
Douglas Gregor668d6d92009-12-13 20:44:55 +00006990 case OO_Call: {
6991 // This is a call to an object's operator().
6992 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6993
6994 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006995 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006996 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006997 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006998
6999 // FIXME: Poor location information
7000 SourceLocation FakeLParenLoc
7001 = SemaRef.PP.getLocForEndOfToken(
7002 static_cast<Expr *>(Object.get())->getLocEnd());
7003
7004 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007005 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007006 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007007 Args))
7008 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00007009
John McCall9ae2f072010-08-23 23:25:46 +00007010 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007011 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00007012 E->getLocEnd());
7013 }
7014
7015#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
7016 case OO_##Name:
7017#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
7018#include "clang/Basic/OperatorKinds.def"
7019 case OO_Subscript:
7020 // Handled below.
7021 break;
7022
7023 case OO_Conditional:
7024 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007025
7026 case OO_None:
7027 case NUM_OVERLOADED_OPERATORS:
7028 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00007029 }
7030
John McCall60d7b3a2010-08-24 06:29:42 +00007031 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007032 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007033 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007034
Richard Smithefeeccf2012-10-21 03:28:35 +00007035 ExprResult First;
7036 if (E->getOperator() == OO_Amp)
7037 First = getDerived().TransformAddressOfOperand(E->getArg(0));
7038 else
7039 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007040 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007041 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007042
John McCall60d7b3a2010-08-24 06:29:42 +00007043 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007044 if (E->getNumArgs() == 2) {
7045 Second = getDerived().TransformExpr(E->getArg(1));
7046 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007047 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007048 }
Mike Stump1eb44332009-09-09 15:08:12 +00007049
Douglas Gregorb98b1992009-08-11 05:31:07 +00007050 if (!getDerived().AlwaysRebuild() &&
7051 Callee.get() == E->getCallee() &&
7052 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00007053 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00007054 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007055
Lang Hamesbe9af122012-10-02 04:45:10 +00007056 Sema::FPContractStateRAII FPContractState(getSema());
7057 getSema().FPFeatures.fp_contract = E->isFPContractable();
7058
Douglas Gregorb98b1992009-08-11 05:31:07 +00007059 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7060 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007061 Callee.get(),
7062 First.get(),
7063 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007064}
Mike Stump1eb44332009-09-09 15:08:12 +00007065
Douglas Gregorb98b1992009-08-11 05:31:07 +00007066template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007067ExprResult
John McCall454feb92009-12-08 09:21:05 +00007068TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7069 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007070}
Mike Stump1eb44332009-09-09 15:08:12 +00007071
Douglas Gregorb98b1992009-08-11 05:31:07 +00007072template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007073ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00007074TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7075 // Transform the callee.
7076 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7077 if (Callee.isInvalid())
7078 return ExprError();
7079
7080 // Transform exec config.
7081 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7082 if (EC.isInvalid())
7083 return ExprError();
7084
7085 // Transform arguments.
7086 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007087 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007088 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007089 &ArgChanged))
7090 return ExprError();
7091
7092 if (!getDerived().AlwaysRebuild() &&
7093 Callee.get() == E->getCallee() &&
7094 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007095 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00007096
7097 // FIXME: Wrong source location information for the '('.
7098 SourceLocation FakeLParenLoc
7099 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7100 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007101 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007102 E->getRParenLoc(), EC.get());
7103}
7104
7105template<typename Derived>
7106ExprResult
John McCall454feb92009-12-08 09:21:05 +00007107TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007108 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7109 if (!Type)
7110 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007111
John McCall60d7b3a2010-08-24 06:29:42 +00007112 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007113 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007114 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007115 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007116
Douglas Gregorb98b1992009-08-11 05:31:07 +00007117 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007118 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007119 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007120 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007121 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007122 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007123 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007124 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007125 E->getAngleBrackets().getEnd(),
7126 // FIXME. this should be '(' location
7127 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007128 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007129 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007130}
Mike Stump1eb44332009-09-09 15:08:12 +00007131
Douglas Gregorb98b1992009-08-11 05:31:07 +00007132template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007133ExprResult
John McCall454feb92009-12-08 09:21:05 +00007134TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7135 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007136}
Mike Stump1eb44332009-09-09 15:08:12 +00007137
7138template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007139ExprResult
John McCall454feb92009-12-08 09:21:05 +00007140TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7141 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007142}
7143
Douglas Gregorb98b1992009-08-11 05:31:07 +00007144template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007145ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007146TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007147 CXXReinterpretCastExpr *E) {
7148 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007149}
Mike Stump1eb44332009-09-09 15:08:12 +00007150
Douglas Gregorb98b1992009-08-11 05:31:07 +00007151template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007152ExprResult
John McCall454feb92009-12-08 09:21:05 +00007153TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7154 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007155}
Mike Stump1eb44332009-09-09 15:08:12 +00007156
Douglas Gregorb98b1992009-08-11 05:31:07 +00007157template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007158ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007159TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007160 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007161 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7162 if (!Type)
7163 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007164
John McCall60d7b3a2010-08-24 06:29:42 +00007165 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007166 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007167 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007168 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007169
Douglas Gregorb98b1992009-08-11 05:31:07 +00007170 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007171 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007172 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007173 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007174
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007175 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007176 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007177 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007178 E->getRParenLoc());
7179}
Mike Stump1eb44332009-09-09 15:08:12 +00007180
Douglas Gregorb98b1992009-08-11 05:31:07 +00007181template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007182ExprResult
John McCall454feb92009-12-08 09:21:05 +00007183TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007184 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007185 TypeSourceInfo *TInfo
7186 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7187 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007188 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007189
Douglas Gregorb98b1992009-08-11 05:31:07 +00007190 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007191 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007192 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007193
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007194 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7195 E->getLocStart(),
7196 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007197 E->getLocEnd());
7198 }
Mike Stump1eb44332009-09-09 15:08:12 +00007199
Eli Friedmanef331b72012-01-20 01:26:23 +00007200 // We don't know whether the subexpression is potentially evaluated until
7201 // after we perform semantic analysis. We speculatively assume it is
7202 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007203 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007204 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7205 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007206
John McCall60d7b3a2010-08-24 06:29:42 +00007207 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007208 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007209 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007210
Douglas Gregorb98b1992009-08-11 05:31:07 +00007211 if (!getDerived().AlwaysRebuild() &&
7212 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007213 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007214
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007215 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7216 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007217 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007218 E->getLocEnd());
7219}
7220
7221template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007222ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007223TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7224 if (E->isTypeOperand()) {
7225 TypeSourceInfo *TInfo
7226 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7227 if (!TInfo)
7228 return ExprError();
7229
7230 if (!getDerived().AlwaysRebuild() &&
7231 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007232 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007233
Douglas Gregor3c52a212011-03-06 17:40:41 +00007234 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007235 E->getLocStart(),
7236 TInfo,
7237 E->getLocEnd());
7238 }
7239
Francois Pichet01b7c302010-09-08 12:20:18 +00007240 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7241
7242 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7243 if (SubExpr.isInvalid())
7244 return ExprError();
7245
7246 if (!getDerived().AlwaysRebuild() &&
7247 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007248 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007249
7250 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7251 E->getLocStart(),
7252 SubExpr.get(),
7253 E->getLocEnd());
7254}
7255
7256template<typename Derived>
7257ExprResult
John McCall454feb92009-12-08 09:21:05 +00007258TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007259 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007260}
Mike Stump1eb44332009-09-09 15:08:12 +00007261
Douglas Gregorb98b1992009-08-11 05:31:07 +00007262template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007263ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007264TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007265 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007266 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007267}
Mike Stump1eb44332009-09-09 15:08:12 +00007268
Douglas Gregorb98b1992009-08-11 05:31:07 +00007269template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007270ExprResult
John McCall454feb92009-12-08 09:21:05 +00007271TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithcafeb942013-06-07 02:33:37 +00007272 QualType T = getSema().getCurrentThisType();
Mike Stump1eb44332009-09-09 15:08:12 +00007273
Douglas Gregorec79d872012-02-24 17:41:38 +00007274 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7275 // Make sure that we capture 'this'.
7276 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007277 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007278 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007279
Douglas Gregor828a1972010-01-07 23:12:05 +00007280 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007281}
Mike Stump1eb44332009-09-09 15:08:12 +00007282
Douglas Gregorb98b1992009-08-11 05:31:07 +00007283template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007284ExprResult
John McCall454feb92009-12-08 09:21:05 +00007285TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007286 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007287 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007288 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007289
Douglas Gregorb98b1992009-08-11 05:31:07 +00007290 if (!getDerived().AlwaysRebuild() &&
7291 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007292 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007293
Douglas Gregorbca01b42011-07-06 22:04:06 +00007294 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7295 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007296}
Mike Stump1eb44332009-09-09 15:08:12 +00007297
Douglas Gregorb98b1992009-08-11 05:31:07 +00007298template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007299ExprResult
John McCall454feb92009-12-08 09:21:05 +00007300TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007301 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007302 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7303 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007304 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007305 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007306
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007307 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007308 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007309 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007310
Douglas Gregor036aed12009-12-23 23:03:06 +00007311 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
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
Richard Smithc3bf52c2013-04-20 22:23:05 +00007316TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7317 FieldDecl *Field
7318 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7319 E->getField()));
7320 if (!Field)
7321 return ExprError();
7322
7323 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7324 return SemaRef.Owned(E);
7325
7326 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7327}
7328
7329template<typename Derived>
7330ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007331TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7332 CXXScalarValueInitExpr *E) {
7333 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7334 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007335 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007336
Douglas Gregorb98b1992009-08-11 05:31:07 +00007337 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007338 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007339 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007340
Chad Rosier4a9d7952012-08-08 18:46:20 +00007341 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007342 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007343 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007344}
Mike Stump1eb44332009-09-09 15:08:12 +00007345
Douglas Gregorb98b1992009-08-11 05:31:07 +00007346template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007347ExprResult
John McCall454feb92009-12-08 09:21:05 +00007348TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007349 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007350 TypeSourceInfo *AllocTypeInfo
7351 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7352 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007353 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007354
Douglas Gregorb98b1992009-08-11 05:31:07 +00007355 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007356 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007357 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007358 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007359
Douglas Gregorb98b1992009-08-11 05:31:07 +00007360 // Transform the placement arguments (if any).
7361 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007362 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007363 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007364 E->getNumPlacementArgs(), true,
7365 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007366 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007367
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007368 // Transform the initializer (if any).
7369 Expr *OldInit = E->getInitializer();
7370 ExprResult NewInit;
7371 if (OldInit)
7372 NewInit = getDerived().TransformExpr(OldInit);
7373 if (NewInit.isInvalid())
7374 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007375
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007376 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007377 FunctionDecl *OperatorNew = 0;
7378 if (E->getOperatorNew()) {
7379 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007380 getDerived().TransformDecl(E->getLocStart(),
7381 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007382 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007383 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007384 }
7385
7386 FunctionDecl *OperatorDelete = 0;
7387 if (E->getOperatorDelete()) {
7388 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007389 getDerived().TransformDecl(E->getLocStart(),
7390 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007391 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007392 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007393 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007394
Douglas Gregorb98b1992009-08-11 05:31:07 +00007395 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007396 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007397 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007398 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007399 OperatorNew == E->getOperatorNew() &&
7400 OperatorDelete == E->getOperatorDelete() &&
7401 !ArgumentChanged) {
7402 // Mark any declarations we need as referenced.
7403 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007404 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007405 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007406 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007407 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007408
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007409 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007410 QualType ElementType
7411 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7412 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7413 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7414 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007415 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007416 }
7417 }
7418 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007419
John McCall3fa5cae2010-10-26 07:05:15 +00007420 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007421 }
Mike Stump1eb44332009-09-09 15:08:12 +00007422
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007423 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007424 if (!ArraySize.get()) {
7425 // If no array size was specified, but the new expression was
7426 // instantiated with an array type (e.g., "new T" where T is
7427 // instantiated with "int[4]"), extract the outer bound from the
7428 // array type as our array size. We do this with constant and
7429 // dependently-sized array types.
7430 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7431 if (!ArrayT) {
7432 // Do nothing
7433 } else if (const ConstantArrayType *ConsArrayT
7434 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007435 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007436 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007437 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007438 SemaRef.Context.getSizeType(),
7439 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007440 AllocType = ConsArrayT->getElementType();
7441 } else if (const DependentSizedArrayType *DepArrayT
7442 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7443 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007444 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007445 AllocType = DepArrayT->getElementType();
7446 }
7447 }
7448 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007449
Douglas Gregorb98b1992009-08-11 05:31:07 +00007450 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7451 E->isGlobalNew(),
7452 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007453 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007454 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007455 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007456 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007457 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007458 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007459 E->getDirectInitRange(),
7460 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007461}
Mike Stump1eb44332009-09-09 15:08:12 +00007462
Douglas Gregorb98b1992009-08-11 05:31:07 +00007463template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007464ExprResult
John McCall454feb92009-12-08 09:21:05 +00007465TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007466 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007467 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007468 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007469
Douglas Gregor1af74512010-02-26 00:38:10 +00007470 // Transform the delete operator, if known.
7471 FunctionDecl *OperatorDelete = 0;
7472 if (E->getOperatorDelete()) {
7473 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007474 getDerived().TransformDecl(E->getLocStart(),
7475 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007476 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007477 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007478 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007479
Douglas Gregorb98b1992009-08-11 05:31:07 +00007480 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007481 Operand.get() == E->getArgument() &&
7482 OperatorDelete == E->getOperatorDelete()) {
7483 // Mark any declarations we need as referenced.
7484 // FIXME: instantiation-specific.
7485 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007486 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007487
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007488 if (!E->getArgument()->isTypeDependent()) {
7489 QualType Destroyed = SemaRef.Context.getBaseElementType(
7490 E->getDestroyedType());
7491 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7492 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007493 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007494 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007495 }
7496 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007497
John McCall3fa5cae2010-10-26 07:05:15 +00007498 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007499 }
Mike Stump1eb44332009-09-09 15:08:12 +00007500
Douglas Gregorb98b1992009-08-11 05:31:07 +00007501 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7502 E->isGlobalDelete(),
7503 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007504 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007505}
Mike Stump1eb44332009-09-09 15:08:12 +00007506
Douglas Gregorb98b1992009-08-11 05:31:07 +00007507template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007508ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007509TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007510 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007511 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007512 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007513 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007514
John McCallb3d87482010-08-24 05:47:05 +00007515 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007516 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007517 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007518 E->getOperatorLoc(),
7519 E->isArrow()? tok::arrow : tok::period,
7520 ObjectTypePtr,
7521 MayBePseudoDestructor);
7522 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007523 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007524
John McCallb3d87482010-08-24 05:47:05 +00007525 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007526 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7527 if (QualifierLoc) {
7528 QualifierLoc
7529 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7530 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007531 return ExprError();
7532 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007533 CXXScopeSpec SS;
7534 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007535
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007536 PseudoDestructorTypeStorage Destroyed;
7537 if (E->getDestroyedTypeInfo()) {
7538 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007539 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007540 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007541 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007542 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007543 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007544 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007545 // We aren't likely to be able to resolve the identifier down to a type
7546 // now anyway, so just retain the identifier.
7547 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7548 E->getDestroyedTypeLoc());
7549 } else {
7550 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007551 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007552 *E->getDestroyedTypeIdentifier(),
7553 E->getDestroyedTypeLoc(),
7554 /*Scope=*/0,
7555 SS, ObjectTypePtr,
7556 false);
7557 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007558 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007559
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007560 Destroyed
7561 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7562 E->getDestroyedTypeLoc());
7563 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007564
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007565 TypeSourceInfo *ScopeTypeInfo = 0;
7566 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007567 CXXScopeSpec EmptySS;
7568 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7569 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007570 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007571 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007572 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007573
John McCall9ae2f072010-08-23 23:25:46 +00007574 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007575 E->getOperatorLoc(),
7576 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007577 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007578 ScopeTypeInfo,
7579 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007580 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007581 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007582}
Mike Stump1eb44332009-09-09 15:08:12 +00007583
Douglas Gregora71d8192009-09-04 17:36:40 +00007584template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007585ExprResult
John McCallba135432009-11-21 08:51:07 +00007586TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007587 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007588 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7589 Sema::LookupOrdinaryName);
7590
7591 // Transform all the decls.
7592 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7593 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007594 NamedDecl *InstD = static_cast<NamedDecl*>(
7595 getDerived().TransformDecl(Old->getNameLoc(),
7596 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007597 if (!InstD) {
7598 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7599 // This can happen because of dependent hiding.
7600 if (isa<UsingShadowDecl>(*I))
7601 continue;
7602 else
John McCallf312b1e2010-08-26 23:41:50 +00007603 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007604 }
John McCallf7a1a742009-11-24 19:00:30 +00007605
7606 // Expand using declarations.
7607 if (isa<UsingDecl>(InstD)) {
7608 UsingDecl *UD = cast<UsingDecl>(InstD);
7609 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7610 E = UD->shadow_end(); I != E; ++I)
7611 R.addDecl(*I);
7612 continue;
7613 }
7614
7615 R.addDecl(InstD);
7616 }
7617
7618 // Resolve a kind, but don't do any further analysis. If it's
7619 // ambiguous, the callee needs to deal with it.
7620 R.resolveKind();
7621
7622 // Rebuild the nested-name qualifier, if present.
7623 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007624 if (Old->getQualifierLoc()) {
7625 NestedNameSpecifierLoc QualifierLoc
7626 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7627 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007628 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007629
Douglas Gregor4c9be892011-02-28 20:01:57 +00007630 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007631 }
7632
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007633 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007634 CXXRecordDecl *NamingClass
7635 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7636 Old->getNameLoc(),
7637 Old->getNamingClass()));
7638 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007639 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007640
Douglas Gregor66c45152010-04-27 16:10:10 +00007641 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007642 }
7643
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007644 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7645
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007646 // If we have neither explicit template arguments, nor the template keyword,
7647 // it's a normal declaration name.
7648 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007649 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7650
7651 // If we have template arguments, rebuild them, then rebuild the
7652 // templateid expression.
7653 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007654 if (Old->hasExplicitTemplateArgs() &&
7655 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007656 Old->getNumTemplateArgs(),
7657 TransArgs))
7658 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007659
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007660 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007661 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007662}
Mike Stump1eb44332009-09-09 15:08:12 +00007663
Douglas Gregorb98b1992009-08-11 05:31:07 +00007664template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007665ExprResult
John McCall454feb92009-12-08 09:21:05 +00007666TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007667 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7668 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007669 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007670
Douglas Gregorb98b1992009-08-11 05:31:07 +00007671 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007672 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007673 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007674
Mike Stump1eb44332009-09-09 15:08:12 +00007675 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007676 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007677 T,
7678 E->getLocEnd());
7679}
Mike Stump1eb44332009-09-09 15:08:12 +00007680
Douglas Gregorb98b1992009-08-11 05:31:07 +00007681template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007682ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007683TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7684 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7685 if (!LhsT)
7686 return ExprError();
7687
7688 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7689 if (!RhsT)
7690 return ExprError();
7691
7692 if (!getDerived().AlwaysRebuild() &&
7693 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7694 return SemaRef.Owned(E);
7695
7696 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7697 E->getLocStart(),
7698 LhsT, RhsT,
7699 E->getLocEnd());
7700}
7701
7702template<typename Derived>
7703ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007704TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7705 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007706 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007707 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7708 TypeSourceInfo *From = E->getArg(I);
7709 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007710 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007711 TypeLocBuilder TLB;
7712 TLB.reserve(FromTL.getFullDataSize());
7713 QualType To = getDerived().TransformType(TLB, FromTL);
7714 if (To.isNull())
7715 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007716
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007717 if (To == From->getType())
7718 Args.push_back(From);
7719 else {
7720 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7721 ArgChanged = true;
7722 }
7723 continue;
7724 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007725
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007726 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007727
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007728 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007729 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007730 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7731 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7732 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007733
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007734 // Determine whether the set of unexpanded parameter packs can and should
7735 // be expanded.
7736 bool Expand = true;
7737 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007738 Optional<unsigned> OrigNumExpansions =
7739 ExpansionTL.getTypePtr()->getNumExpansions();
7740 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007741 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7742 PatternTL.getSourceRange(),
7743 Unexpanded,
7744 Expand, RetainExpansion,
7745 NumExpansions))
7746 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007747
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007748 if (!Expand) {
7749 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007750 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007751 // expansion.
7752 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007753
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007754 TypeLocBuilder TLB;
7755 TLB.reserve(From->getTypeLoc().getFullDataSize());
7756
7757 QualType To = getDerived().TransformType(TLB, PatternTL);
7758 if (To.isNull())
7759 return ExprError();
7760
Chad Rosier4a9d7952012-08-08 18:46:20 +00007761 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007762 PatternTL.getSourceRange(),
7763 ExpansionTL.getEllipsisLoc(),
7764 NumExpansions);
7765 if (To.isNull())
7766 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007767
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007768 PackExpansionTypeLoc ToExpansionTL
7769 = TLB.push<PackExpansionTypeLoc>(To);
7770 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7771 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7772 continue;
7773 }
7774
7775 // Expand the pack expansion by substituting for each argument in the
7776 // pack(s).
7777 for (unsigned I = 0; I != *NumExpansions; ++I) {
7778 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7779 TypeLocBuilder TLB;
7780 TLB.reserve(PatternTL.getFullDataSize());
7781 QualType To = getDerived().TransformType(TLB, PatternTL);
7782 if (To.isNull())
7783 return ExprError();
7784
7785 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7786 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007787
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007788 if (!RetainExpansion)
7789 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007790
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007791 // If we're supposed to retain a pack expansion, do so by temporarily
7792 // forgetting the partially-substituted parameter pack.
7793 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7794
7795 TypeLocBuilder TLB;
7796 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007797
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007798 QualType To = getDerived().TransformType(TLB, PatternTL);
7799 if (To.isNull())
7800 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007801
7802 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007803 PatternTL.getSourceRange(),
7804 ExpansionTL.getEllipsisLoc(),
7805 NumExpansions);
7806 if (To.isNull())
7807 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007808
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007809 PackExpansionTypeLoc ToExpansionTL
7810 = TLB.push<PackExpansionTypeLoc>(To);
7811 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7812 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7813 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007814
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007815 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7816 return SemaRef.Owned(E);
7817
7818 return getDerived().RebuildTypeTrait(E->getTrait(),
7819 E->getLocStart(),
7820 Args,
7821 E->getLocEnd());
7822}
7823
7824template<typename Derived>
7825ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007826TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7827 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7828 if (!T)
7829 return ExprError();
7830
7831 if (!getDerived().AlwaysRebuild() &&
7832 T == E->getQueriedTypeSourceInfo())
7833 return SemaRef.Owned(E);
7834
7835 ExprResult SubExpr;
7836 {
7837 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7838 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7839 if (SubExpr.isInvalid())
7840 return ExprError();
7841
7842 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7843 return SemaRef.Owned(E);
7844 }
7845
7846 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7847 E->getLocStart(),
7848 T,
7849 SubExpr.get(),
7850 E->getLocEnd());
7851}
7852
7853template<typename Derived>
7854ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007855TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7856 ExprResult SubExpr;
7857 {
7858 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7859 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7860 if (SubExpr.isInvalid())
7861 return ExprError();
7862
7863 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7864 return SemaRef.Owned(E);
7865 }
7866
7867 return getDerived().RebuildExpressionTrait(
7868 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7869}
7870
7871template<typename Derived>
7872ExprResult
John McCall865d4472009-11-19 22:55:06 +00007873TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007874 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00007875 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
7876}
7877
7878template<typename Derived>
7879ExprResult
7880TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
7881 DependentScopeDeclRefExpr *E,
7882 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007883 NestedNameSpecifierLoc QualifierLoc
7884 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7885 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007886 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007887 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007888
John McCall43fed0d2010-11-12 08:19:04 +00007889 // TODO: If this is a conversion-function-id, verify that the
7890 // destination type name (if present) resolves the same way after
7891 // instantiation as it did in the local scope.
7892
Abramo Bagnara25777432010-08-11 22:01:17 +00007893 DeclarationNameInfo NameInfo
7894 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7895 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007896 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007897
John McCallf7a1a742009-11-24 19:00:30 +00007898 if (!E->hasExplicitTemplateArgs()) {
7899 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007900 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007901 // Note: it is sufficient to compare the Name component of NameInfo:
7902 // if name has not changed, DNLoc has not changed either.
7903 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007904 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007905
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007906 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007907 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007908 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007909 /*TemplateArgs*/ 0,
7910 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007911 }
John McCalld5532b62009-11-23 01:53:49 +00007912
7913 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007914 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7915 E->getNumTemplateArgs(),
7916 TransArgs))
7917 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007918
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007919 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007920 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007921 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007922 &TransArgs,
7923 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007924}
7925
7926template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007927ExprResult
John McCall454feb92009-12-08 09:21:05 +00007928TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00007929 // CXXConstructExprs other than for list-initialization and
7930 // CXXTemporaryObjectExpr are always implicit, so when we have
7931 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00007932 if ((E->getNumArgs() == 1 ||
7933 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00007934 (!getDerived().DropCallArgument(E->getArg(0))) &&
7935 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00007936 return getDerived().TransformExpr(E->getArg(0));
7937
Douglas Gregorb98b1992009-08-11 05:31:07 +00007938 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7939
7940 QualType T = getDerived().TransformType(E->getType());
7941 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007942 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007943
7944 CXXConstructorDecl *Constructor
7945 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007946 getDerived().TransformDecl(E->getLocStart(),
7947 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007948 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007949 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007950
Douglas Gregorb98b1992009-08-11 05:31:07 +00007951 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007952 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007953 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007954 &ArgumentChanged))
7955 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007956
Douglas Gregorb98b1992009-08-11 05:31:07 +00007957 if (!getDerived().AlwaysRebuild() &&
7958 T == E->getType() &&
7959 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007960 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007961 // Mark the constructor as referenced.
7962 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007963 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007964 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007965 }
Mike Stump1eb44332009-09-09 15:08:12 +00007966
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007967 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7968 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007969 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007970 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00007971 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007972 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007973 E->getConstructionKind(),
7974 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007975}
Mike Stump1eb44332009-09-09 15:08:12 +00007976
Douglas Gregorb98b1992009-08-11 05:31:07 +00007977/// \brief Transform a C++ temporary-binding expression.
7978///
Douglas Gregor51326552009-12-24 18:51:59 +00007979/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7980/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007981template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007982ExprResult
John McCall454feb92009-12-08 09:21:05 +00007983TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007984 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007985}
Mike Stump1eb44332009-09-09 15:08:12 +00007986
John McCall4765fa02010-12-06 08:20:24 +00007987/// \brief Transform a C++ expression that contains cleanups that should
7988/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007989///
John McCall4765fa02010-12-06 08:20:24 +00007990/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007991/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007992template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007993ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007994TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007995 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007996}
Mike Stump1eb44332009-09-09 15:08:12 +00007997
Douglas Gregorb98b1992009-08-11 05:31:07 +00007998template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007999ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008000TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00008001 CXXTemporaryObjectExpr *E) {
8002 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8003 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008004 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008005
Douglas Gregorb98b1992009-08-11 05:31:07 +00008006 CXXConstructorDecl *Constructor
8007 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008008 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008009 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008010 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00008011 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008012
Douglas Gregorb98b1992009-08-11 05:31:07 +00008013 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008014 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00008015 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008016 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008017 &ArgumentChanged))
8018 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008019
Douglas Gregorb98b1992009-08-11 05:31:07 +00008020 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008021 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008022 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00008023 !ArgumentChanged) {
8024 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00008025 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00008026 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00008027 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008028
Richard Smithc83c2302012-12-19 01:39:02 +00008029 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00008030 return getDerived().RebuildCXXTemporaryObjectExpr(T,
8031 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008032 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008033 E->getLocEnd());
8034}
Mike Stump1eb44332009-09-09 15:08:12 +00008035
Douglas Gregorb98b1992009-08-11 05:31:07 +00008036template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008037ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00008038TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00008039 // Transform the type of the lambda parameters and start the definition of
8040 // the lambda itself.
8041 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00008042 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00008043 if (!MethodTy)
8044 return ExprError();
8045
Eli Friedman8da8a662012-09-19 01:18:11 +00008046 // Create the local class that will describe the lambda.
8047 CXXRecordDecl *Class
8048 = getSema().createLambdaClosureType(E->getIntroducerRange(),
8049 MethodTy,
8050 /*KnownDependent=*/false);
8051 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8052
Douglas Gregorc6889e72012-02-14 22:28:59 +00008053 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008054 SmallVector<QualType, 4> ParamTypes;
8055 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00008056 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
8057 E->getCallOperator()->param_begin(),
8058 E->getCallOperator()->param_size(),
8059 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00008060 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00008061
Douglas Gregordfca6f52012-02-13 22:00:16 +00008062 // Build the call operator.
8063 CXXMethodDecl *CallOperator
8064 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008065 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00008066 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008067 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008068 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00008069
Richard Smith612409e2012-07-25 03:56:55 +00008070 return getDerived().TransformLambdaScope(E, CallOperator);
8071}
8072
8073template<typename Derived>
8074ExprResult
8075TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8076 CXXMethodDecl *CallOperator) {
Richard Smith0d8e9642013-05-16 06:20:58 +00008077 bool Invalid = false;
8078
8079 // Transform any init-capture expressions before entering the scope of the
8080 // lambda.
8081 llvm::SmallVector<ExprResult, 8> InitCaptureExprs;
8082 InitCaptureExprs.resize(E->explicit_capture_end() -
8083 E->explicit_capture_begin());
8084 for (LambdaExpr::capture_iterator C = E->capture_begin(),
8085 CEnd = E->capture_end();
8086 C != CEnd; ++C) {
8087 if (!C->isInitCapture())
8088 continue;
8089 InitCaptureExprs[C - E->capture_begin()] =
8090 getDerived().TransformExpr(E->getInitCaptureInit(C));
8091 }
8092
Douglas Gregord5387e82012-02-14 00:00:48 +00008093 // Introduce the context of the call operator.
8094 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8095
Douglas Gregordfca6f52012-02-13 22:00:16 +00008096 // Enter the scope of the lambda.
8097 sema::LambdaScopeInfo *LSI
8098 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
8099 E->getCaptureDefault(),
8100 E->hasExplicitParameters(),
8101 E->hasExplicitResultType(),
8102 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008103
Douglas Gregordfca6f52012-02-13 22:00:16 +00008104 // Transform captures.
Douglas Gregordfca6f52012-02-13 22:00:16 +00008105 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008106 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008107 CEnd = E->capture_end();
8108 C != CEnd; ++C) {
8109 // When we hit the first implicit capture, tell Sema that we've finished
8110 // the list of explicit captures.
8111 if (!FinishedExplicitCaptures && C->isImplicit()) {
8112 getSema().finishLambdaExplicitCaptures(LSI);
8113 FinishedExplicitCaptures = true;
8114 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008115
Douglas Gregordfca6f52012-02-13 22:00:16 +00008116 // Capturing 'this' is trivial.
8117 if (C->capturesThis()) {
8118 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8119 continue;
8120 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008121
Richard Smith0d8e9642013-05-16 06:20:58 +00008122 // Rebuild init-captures, including the implied field declaration.
8123 if (C->isInitCapture()) {
8124 ExprResult Init = InitCaptureExprs[C - E->capture_begin()];
8125 if (Init.isInvalid()) {
8126 Invalid = true;
8127 continue;
8128 }
8129 FieldDecl *OldFD = C->getInitCaptureField();
8130 FieldDecl *NewFD = getSema().checkInitCapture(
8131 C->getLocation(), OldFD->getType()->isReferenceType(),
8132 OldFD->getIdentifier(), Init.take());
8133 if (!NewFD)
8134 Invalid = true;
8135 else
8136 getDerived().transformedLocalDecl(OldFD, NewFD);
8137 continue;
8138 }
8139
8140 assert(C->capturesVariable() && "unexpected kind of lambda capture");
8141
Douglas Gregora7365242012-02-14 19:27:52 +00008142 // Determine the capture kind for Sema.
8143 Sema::TryCaptureKind Kind
8144 = C->isImplicit()? Sema::TryCapture_Implicit
8145 : C->getCaptureKind() == LCK_ByCopy
8146 ? Sema::TryCapture_ExplicitByVal
8147 : Sema::TryCapture_ExplicitByRef;
8148 SourceLocation EllipsisLoc;
8149 if (C->isPackExpansion()) {
8150 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8151 bool ShouldExpand = false;
8152 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008153 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008154 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8155 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008156 Unexpanded,
8157 ShouldExpand, RetainExpansion,
Richard Smith0d8e9642013-05-16 06:20:58 +00008158 NumExpansions)) {
8159 Invalid = true;
8160 continue;
8161 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008162
Douglas Gregora7365242012-02-14 19:27:52 +00008163 if (ShouldExpand) {
8164 // The transform has determined that we should perform an expansion;
8165 // transform and capture each of the arguments.
8166 // expansion of the pattern. Do so.
8167 VarDecl *Pack = C->getCapturedVar();
8168 for (unsigned I = 0; I != *NumExpansions; ++I) {
8169 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8170 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008171 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008172 Pack));
8173 if (!CapturedVar) {
8174 Invalid = true;
8175 continue;
8176 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008177
Douglas Gregora7365242012-02-14 19:27:52 +00008178 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008179 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8180 }
Douglas Gregora7365242012-02-14 19:27:52 +00008181 continue;
8182 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008183
Douglas Gregora7365242012-02-14 19:27:52 +00008184 EllipsisLoc = C->getEllipsisLoc();
8185 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008186
Douglas Gregordfca6f52012-02-13 22:00:16 +00008187 // Transform the captured variable.
8188 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008189 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008190 C->getCapturedVar()));
8191 if (!CapturedVar) {
8192 Invalid = true;
8193 continue;
8194 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008195
Douglas Gregordfca6f52012-02-13 22:00:16 +00008196 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008197 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008198 }
8199 if (!FinishedExplicitCaptures)
8200 getSema().finishLambdaExplicitCaptures(LSI);
8201
Douglas Gregordfca6f52012-02-13 22:00:16 +00008202
8203 // Enter a new evaluation context to insulate the lambda from any
8204 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008205 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008206
8207 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008208 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008209 /*IsInstantiation=*/true);
8210 return ExprError();
8211 }
8212
8213 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008214 StmtResult Body = getDerived().TransformStmt(E->getBody());
8215 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008216 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008217 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008218 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008219 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008220
Chad Rosier4a9d7952012-08-08 18:46:20 +00008221 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008222 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008223}
8224
8225template<typename Derived>
8226ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008227TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008228 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008229 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8230 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008231 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008232
Douglas Gregorb98b1992009-08-11 05:31:07 +00008233 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008234 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008235 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008236 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008237 &ArgumentChanged))
8238 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008239
Douglas Gregorb98b1992009-08-11 05:31:07 +00008240 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008241 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008242 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008243 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008244
Douglas Gregorb98b1992009-08-11 05:31:07 +00008245 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008246 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008247 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008248 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008249 E->getRParenLoc());
8250}
Mike Stump1eb44332009-09-09 15:08:12 +00008251
Douglas Gregorb98b1992009-08-11 05:31:07 +00008252template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008253ExprResult
John McCall865d4472009-11-19 22:55:06 +00008254TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008255 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008256 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008257 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008258 Expr *OldBase;
8259 QualType BaseType;
8260 QualType ObjectType;
8261 if (!E->isImplicitAccess()) {
8262 OldBase = E->getBase();
8263 Base = getDerived().TransformExpr(OldBase);
8264 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008265 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008266
John McCallaa81e162009-12-01 22:10:20 +00008267 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008268 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008269 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008270 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008271 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008272 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008273 ObjectTy,
8274 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008275 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008276 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008277
John McCallb3d87482010-08-24 05:47:05 +00008278 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008279 BaseType = ((Expr*) Base.get())->getType();
8280 } else {
8281 OldBase = 0;
8282 BaseType = getDerived().TransformType(E->getBaseType());
8283 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8284 }
Mike Stump1eb44332009-09-09 15:08:12 +00008285
Douglas Gregor6cd21982009-10-20 05:58:46 +00008286 // Transform the first part of the nested-name-specifier that qualifies
8287 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008288 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008289 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008290 E->getFirstQualifierFoundInScope(),
8291 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008292
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008293 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008294 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008295 QualifierLoc
8296 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8297 ObjectType,
8298 FirstQualifierInScope);
8299 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008300 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008301 }
Mike Stump1eb44332009-09-09 15:08:12 +00008302
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008303 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8304
John McCall43fed0d2010-11-12 08:19:04 +00008305 // TODO: If this is a conversion-function-id, verify that the
8306 // destination type name (if present) resolves the same way after
8307 // instantiation as it did in the local scope.
8308
Abramo Bagnara25777432010-08-11 22:01:17 +00008309 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008310 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008311 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008312 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008313
John McCallaa81e162009-12-01 22:10:20 +00008314 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008315 // This is a reference to a member without an explicitly-specified
8316 // template argument list. Optimize for this common case.
8317 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008318 Base.get() == OldBase &&
8319 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008320 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008321 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008322 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008323 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008324
John McCall9ae2f072010-08-23 23:25:46 +00008325 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008326 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008327 E->isArrow(),
8328 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008329 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008330 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008331 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008332 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008333 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008334 }
8335
John McCalld5532b62009-11-23 01:53:49 +00008336 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008337 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8338 E->getNumTemplateArgs(),
8339 TransArgs))
8340 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008341
John McCall9ae2f072010-08-23 23:25:46 +00008342 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008343 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008344 E->isArrow(),
8345 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008346 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008347 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008348 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008349 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008350 &TransArgs);
8351}
8352
8353template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008354ExprResult
John McCall454feb92009-12-08 09:21:05 +00008355TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008356 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008357 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008358 QualType BaseType;
8359 if (!Old->isImplicitAccess()) {
8360 Base = getDerived().TransformExpr(Old->getBase());
8361 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008362 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008363 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8364 Old->isArrow());
8365 if (Base.isInvalid())
8366 return ExprError();
8367 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008368 } else {
8369 BaseType = getDerived().TransformType(Old->getBaseType());
8370 }
John McCall129e2df2009-11-30 22:42:35 +00008371
Douglas Gregor4c9be892011-02-28 20:01:57 +00008372 NestedNameSpecifierLoc QualifierLoc;
8373 if (Old->getQualifierLoc()) {
8374 QualifierLoc
8375 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8376 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008377 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008378 }
8379
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008380 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8381
Abramo Bagnara25777432010-08-11 22:01:17 +00008382 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008383 Sema::LookupOrdinaryName);
8384
8385 // Transform all the decls.
8386 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8387 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008388 NamedDecl *InstD = static_cast<NamedDecl*>(
8389 getDerived().TransformDecl(Old->getMemberLoc(),
8390 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008391 if (!InstD) {
8392 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8393 // This can happen because of dependent hiding.
8394 if (isa<UsingShadowDecl>(*I))
8395 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008396 else {
8397 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008398 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008399 }
John McCall9f54ad42009-12-10 09:41:52 +00008400 }
John McCall129e2df2009-11-30 22:42:35 +00008401
8402 // Expand using declarations.
8403 if (isa<UsingDecl>(InstD)) {
8404 UsingDecl *UD = cast<UsingDecl>(InstD);
8405 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8406 E = UD->shadow_end(); I != E; ++I)
8407 R.addDecl(*I);
8408 continue;
8409 }
8410
8411 R.addDecl(InstD);
8412 }
8413
8414 R.resolveKind();
8415
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008416 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008417 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008418 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008419 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008420 Old->getMemberLoc(),
8421 Old->getNamingClass()));
8422 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008423 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008424
Douglas Gregor66c45152010-04-27 16:10:10 +00008425 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008426 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008427
John McCall129e2df2009-11-30 22:42:35 +00008428 TemplateArgumentListInfo TransArgs;
8429 if (Old->hasExplicitTemplateArgs()) {
8430 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8431 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008432 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8433 Old->getNumTemplateArgs(),
8434 TransArgs))
8435 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008436 }
John McCallc2233c52010-01-15 08:34:02 +00008437
8438 // FIXME: to do this check properly, we will need to preserve the
8439 // first-qualifier-in-scope here, just in case we had a dependent
8440 // base (and therefore couldn't do the check) and a
8441 // nested-name-qualifier (and therefore could do the lookup).
8442 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008443
John McCall9ae2f072010-08-23 23:25:46 +00008444 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008445 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008446 Old->getOperatorLoc(),
8447 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008448 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008449 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008450 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008451 R,
8452 (Old->hasExplicitTemplateArgs()
8453 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008454}
8455
8456template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008457ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008458TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008459 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008460 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8461 if (SubExpr.isInvalid())
8462 return ExprError();
8463
8464 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008465 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008466
8467 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8468}
8469
8470template<typename Derived>
8471ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008472TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008473 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8474 if (Pattern.isInvalid())
8475 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008476
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008477 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8478 return SemaRef.Owned(E);
8479
Douglas Gregor67fd1252011-01-14 21:20:45 +00008480 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8481 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008482}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008483
8484template<typename Derived>
8485ExprResult
8486TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8487 // If E is not value-dependent, then nothing will change when we transform it.
8488 // Note: This is an instantiation-centric view.
8489 if (!E->isValueDependent())
8490 return SemaRef.Owned(E);
8491
8492 // Note: None of the implementations of TryExpandParameterPacks can ever
8493 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008494 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008495 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8496 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008497 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008498 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008499 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008500 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008501 ShouldExpand, RetainExpansion,
8502 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008503 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008504
Douglas Gregor089e8932011-10-10 18:59:29 +00008505 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008506 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008507
Douglas Gregor089e8932011-10-10 18:59:29 +00008508 NamedDecl *Pack = E->getPack();
8509 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008510 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008511 Pack));
8512 if (!Pack)
8513 return ExprError();
8514 }
8515
Chad Rosier4a9d7952012-08-08 18:46:20 +00008516
Douglas Gregoree8aff02011-01-04 17:33:58 +00008517 // We now know the length of the parameter pack, so build a new expression
8518 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008519 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8520 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008521 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008522}
8523
Douglas Gregorbe230c32011-01-03 17:17:50 +00008524template<typename Derived>
8525ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008526TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8527 SubstNonTypeTemplateParmPackExpr *E) {
8528 // Default behavior is to do nothing with this transformation.
8529 return SemaRef.Owned(E);
8530}
8531
8532template<typename Derived>
8533ExprResult
John McCall91a57552011-07-15 05:09:51 +00008534TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8535 SubstNonTypeTemplateParmExpr *E) {
8536 // Default behavior is to do nothing with this transformation.
8537 return SemaRef.Owned(E);
8538}
8539
8540template<typename Derived>
8541ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008542TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8543 // Default behavior is to do nothing with this transformation.
8544 return SemaRef.Owned(E);
8545}
8546
8547template<typename Derived>
8548ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008549TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8550 MaterializeTemporaryExpr *E) {
8551 return getDerived().TransformExpr(E->GetTemporaryExpr());
8552}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008553
Douglas Gregor03e80032011-06-21 17:03:29 +00008554template<typename Derived>
8555ExprResult
Richard Smith7c3e6152013-06-12 22:31:48 +00008556TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
8557 CXXStdInitializerListExpr *E) {
8558 return getDerived().TransformExpr(E->getSubExpr());
8559}
8560
8561template<typename Derived>
8562ExprResult
John McCall454feb92009-12-08 09:21:05 +00008563TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008564 return SemaRef.MaybeBindToTemporary(E);
8565}
8566
8567template<typename Derived>
8568ExprResult
8569TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008570 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008571}
8572
8573template<typename Derived>
8574ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008575TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8576 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8577 if (SubExpr.isInvalid())
8578 return ExprError();
8579
8580 if (!getDerived().AlwaysRebuild() &&
8581 SubExpr.get() == E->getSubExpr())
8582 return SemaRef.Owned(E);
8583
8584 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008585}
8586
8587template<typename Derived>
8588ExprResult
8589TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8590 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008591 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008592 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008593 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008594 /*IsCall=*/false, Elements, &ArgChanged))
8595 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008596
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008597 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8598 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008599
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008600 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8601 Elements.data(),
8602 Elements.size());
8603}
8604
8605template<typename Derived>
8606ExprResult
8607TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008608 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008609 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008610 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008611 bool ArgChanged = false;
8612 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8613 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008614
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008615 if (OrigElement.isPackExpansion()) {
8616 // This key/value element is a pack expansion.
8617 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8618 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8619 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8620 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8621
8622 // Determine whether the set of unexpanded parameter packs can
8623 // and should be expanded.
8624 bool Expand = true;
8625 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008626 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8627 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008628 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8629 OrigElement.Value->getLocEnd());
8630 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8631 PatternRange,
8632 Unexpanded,
8633 Expand, RetainExpansion,
8634 NumExpansions))
8635 return ExprError();
8636
8637 if (!Expand) {
8638 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008639 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008640 // expansion.
8641 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8642 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8643 if (Key.isInvalid())
8644 return ExprError();
8645
8646 if (Key.get() != OrigElement.Key)
8647 ArgChanged = true;
8648
8649 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8650 if (Value.isInvalid())
8651 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008652
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008653 if (Value.get() != OrigElement.Value)
8654 ArgChanged = true;
8655
Chad Rosier4a9d7952012-08-08 18:46:20 +00008656 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008657 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8658 };
8659 Elements.push_back(Expansion);
8660 continue;
8661 }
8662
8663 // Record right away that the argument was changed. This needs
8664 // to happen even if the array expands to nothing.
8665 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008666
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008667 // The transform has determined that we should perform an elementwise
8668 // expansion of the pattern. Do so.
8669 for (unsigned I = 0; I != *NumExpansions; ++I) {
8670 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8671 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8672 if (Key.isInvalid())
8673 return ExprError();
8674
8675 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8676 if (Value.isInvalid())
8677 return ExprError();
8678
Chad Rosier4a9d7952012-08-08 18:46:20 +00008679 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008680 Key.get(), Value.get(), SourceLocation(), NumExpansions
8681 };
8682
8683 // If any unexpanded parameter packs remain, we still have a
8684 // pack expansion.
8685 if (Key.get()->containsUnexpandedParameterPack() ||
8686 Value.get()->containsUnexpandedParameterPack())
8687 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008688
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008689 Elements.push_back(Element);
8690 }
8691
8692 // We've finished with this pack expansion.
8693 continue;
8694 }
8695
8696 // Transform and check key.
8697 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8698 if (Key.isInvalid())
8699 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008700
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008701 if (Key.get() != OrigElement.Key)
8702 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008703
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008704 // Transform and check value.
8705 ExprResult Value
8706 = getDerived().TransformExpr(OrigElement.Value);
8707 if (Value.isInvalid())
8708 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008709
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008710 if (Value.get() != OrigElement.Value)
8711 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008712
8713 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00008714 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008715 };
8716 Elements.push_back(Element);
8717 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008718
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008719 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8720 return SemaRef.MaybeBindToTemporary(E);
8721
8722 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8723 Elements.data(),
8724 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008725}
8726
Mike Stump1eb44332009-09-09 15:08:12 +00008727template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008728ExprResult
John McCall454feb92009-12-08 09:21:05 +00008729TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008730 TypeSourceInfo *EncodedTypeInfo
8731 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8732 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008733 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008734
Douglas Gregorb98b1992009-08-11 05:31:07 +00008735 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008736 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008737 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008738
8739 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008740 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008741 E->getRParenLoc());
8742}
Mike Stump1eb44332009-09-09 15:08:12 +00008743
Douglas Gregorb98b1992009-08-11 05:31:07 +00008744template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008745ExprResult TreeTransform<Derived>::
8746TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCall93b64572013-04-11 02:14:26 +00008747 // This is a kind of implicit conversion, and it needs to get dropped
8748 // and recomputed for the same general reasons that ImplicitCastExprs
8749 // do, as well a more specific one: this expression is only valid when
8750 // it appears *immediately* as an argument expression.
8751 return getDerived().TransformExpr(E->getSubExpr());
John McCallf85e1932011-06-15 23:02:42 +00008752}
8753
8754template<typename Derived>
8755ExprResult TreeTransform<Derived>::
8756TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008757 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008758 = getDerived().TransformType(E->getTypeInfoAsWritten());
8759 if (!TSInfo)
8760 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008761
John McCallf85e1932011-06-15 23:02:42 +00008762 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008763 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008764 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008765
John McCallf85e1932011-06-15 23:02:42 +00008766 if (!getDerived().AlwaysRebuild() &&
8767 TSInfo == E->getTypeInfoAsWritten() &&
8768 Result.get() == E->getSubExpr())
8769 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008770
John McCallf85e1932011-06-15 23:02:42 +00008771 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008772 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008773 Result.get());
8774}
8775
8776template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008777ExprResult
John McCall454feb92009-12-08 09:21:05 +00008778TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008779 // Transform arguments.
8780 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008781 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008782 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008783 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008784 &ArgChanged))
8785 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008786
Douglas Gregor92e986e2010-04-22 16:44:27 +00008787 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8788 // Class message: transform the receiver type.
8789 TypeSourceInfo *ReceiverTypeInfo
8790 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8791 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008792 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008793
Douglas Gregor92e986e2010-04-22 16:44:27 +00008794 // If nothing changed, just retain the existing message send.
8795 if (!getDerived().AlwaysRebuild() &&
8796 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008797 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008798
8799 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008800 SmallVector<SourceLocation, 16> SelLocs;
8801 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008802 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8803 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008804 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008805 E->getMethodDecl(),
8806 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008807 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008808 E->getRightLoc());
8809 }
8810
8811 // Instance message: transform the receiver
8812 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8813 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008814 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008815 = getDerived().TransformExpr(E->getInstanceReceiver());
8816 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008817 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008818
8819 // If nothing changed, just retain the existing message send.
8820 if (!getDerived().AlwaysRebuild() &&
8821 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008822 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008823
Douglas Gregor92e986e2010-04-22 16:44:27 +00008824 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008825 SmallVector<SourceLocation, 16> SelLocs;
8826 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008827 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008828 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008829 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008830 E->getMethodDecl(),
8831 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008832 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008833 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008834}
8835
Mike Stump1eb44332009-09-09 15:08:12 +00008836template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008837ExprResult
John McCall454feb92009-12-08 09:21:05 +00008838TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008839 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008840}
8841
Mike Stump1eb44332009-09-09 15:08:12 +00008842template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008843ExprResult
John McCall454feb92009-12-08 09:21:05 +00008844TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008845 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008846}
8847
Mike Stump1eb44332009-09-09 15:08:12 +00008848template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008849ExprResult
John McCall454feb92009-12-08 09:21:05 +00008850TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008851 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008852 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008853 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008854 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008855
8856 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008857
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008858 // If nothing changed, just retain the existing expression.
8859 if (!getDerived().AlwaysRebuild() &&
8860 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008861 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008862
John McCall9ae2f072010-08-23 23:25:46 +00008863 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008864 E->getLocation(),
8865 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008866}
8867
Mike Stump1eb44332009-09-09 15:08:12 +00008868template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008869ExprResult
John McCall454feb92009-12-08 09:21:05 +00008870TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008871 // 'super' and types never change. Property never changes. Just
8872 // retain the existing expression.
8873 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008874 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008875
Douglas Gregore3303542010-04-26 20:47:02 +00008876 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008877 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008878 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008879 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008880
Douglas Gregore3303542010-04-26 20:47:02 +00008881 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008882
Douglas Gregore3303542010-04-26 20:47:02 +00008883 // If nothing changed, just retain the existing expression.
8884 if (!getDerived().AlwaysRebuild() &&
8885 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008886 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008887
John McCall12f78a62010-12-02 01:19:52 +00008888 if (E->isExplicitProperty())
8889 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8890 E->getExplicitProperty(),
8891 E->getLocation());
8892
8893 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008894 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008895 E->getImplicitPropertyGetter(),
8896 E->getImplicitPropertySetter(),
8897 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008898}
8899
Mike Stump1eb44332009-09-09 15:08:12 +00008900template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008901ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008902TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8903 // Transform the base expression.
8904 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8905 if (Base.isInvalid())
8906 return ExprError();
8907
8908 // Transform the key expression.
8909 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8910 if (Key.isInvalid())
8911 return ExprError();
8912
8913 // If nothing changed, just retain the existing expression.
8914 if (!getDerived().AlwaysRebuild() &&
8915 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8916 return SemaRef.Owned(E);
8917
Chad Rosier4a9d7952012-08-08 18:46:20 +00008918 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008919 Base.get(), Key.get(),
8920 E->getAtIndexMethodDecl(),
8921 E->setAtIndexMethodDecl());
8922}
8923
8924template<typename Derived>
8925ExprResult
John McCall454feb92009-12-08 09:21:05 +00008926TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008927 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008928 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008929 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008930 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008931
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008932 // If nothing changed, just retain the existing expression.
8933 if (!getDerived().AlwaysRebuild() &&
8934 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008935 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008936
John McCall9ae2f072010-08-23 23:25:46 +00008937 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00008938 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008939 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008940}
8941
Mike Stump1eb44332009-09-09 15:08:12 +00008942template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008943ExprResult
John McCall454feb92009-12-08 09:21:05 +00008944TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008945 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008946 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008947 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008948 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008949 SubExprs, &ArgumentChanged))
8950 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008951
Douglas Gregorb98b1992009-08-11 05:31:07 +00008952 if (!getDerived().AlwaysRebuild() &&
8953 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008954 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008955
Douglas Gregorb98b1992009-08-11 05:31:07 +00008956 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008957 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008958 E->getRParenLoc());
8959}
8960
Mike Stump1eb44332009-09-09 15:08:12 +00008961template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008962ExprResult
John McCall454feb92009-12-08 09:21:05 +00008963TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008964 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008965
John McCallc6ac9c32011-02-04 18:33:18 +00008966 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8967 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8968
8969 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008970 blockScope->TheDecl->setBlockMissingReturnType(
8971 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008972
Chris Lattner686775d2011-07-20 06:58:45 +00008973 SmallVector<ParmVarDecl*, 4> params;
8974 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008975
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008976 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008977 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8978 oldBlock->param_begin(),
8979 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008980 0, paramTypes, &params)) {
8981 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008982 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008983 }
John McCallc6ac9c32011-02-04 18:33:18 +00008984
Jordan Rose09189892013-03-08 22:25:36 +00008985 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008986 QualType exprResultType =
8987 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008988
Jordan Rosebea522f2013-03-08 21:51:21 +00008989 QualType functionType =
8990 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00008991 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00008992 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008993
8994 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008995 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008996 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008997
8998 if (!oldBlock->blockMissingReturnType()) {
8999 blockScope->HasImplicitReturnType = false;
9000 blockScope->ReturnType = exprResultType;
9001 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00009002
John McCall711c52b2011-01-05 12:14:39 +00009003 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00009004 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009005 if (body.isInvalid()) {
9006 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00009007 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00009008 }
John McCall711c52b2011-01-05 12:14:39 +00009009
John McCallc6ac9c32011-02-04 18:33:18 +00009010#ifndef NDEBUG
9011 // In builds with assertions, make sure that we captured everything we
9012 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00009013 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
9014 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
9015 e = oldBlock->capture_end(); i != e; ++i) {
9016 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00009017
Douglas Gregorfc921372011-05-20 15:32:55 +00009018 // Ignore parameter packs.
9019 if (isa<ParmVarDecl>(oldCapture) &&
9020 cast<ParmVarDecl>(oldCapture)->isParameterPack())
9021 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00009022
Douglas Gregorfc921372011-05-20 15:32:55 +00009023 VarDecl *newCapture =
9024 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
9025 oldCapture));
9026 assert(blockScope->CaptureMap.count(newCapture));
9027 }
Douglas Gregorec79d872012-02-24 17:41:38 +00009028 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00009029 }
9030#endif
9031
9032 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
9033 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009034}
9035
Mike Stump1eb44332009-09-09 15:08:12 +00009036template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009037ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009038TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00009039 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00009040}
Eli Friedman276b0612011-10-11 02:20:01 +00009041
9042template<typename Derived>
9043ExprResult
9044TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009045 QualType RetTy = getDerived().TransformType(E->getType());
9046 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00009047 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009048 SubExprs.reserve(E->getNumSubExprs());
9049 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
9050 SubExprs, &ArgumentChanged))
9051 return ExprError();
9052
9053 if (!getDerived().AlwaysRebuild() &&
9054 !ArgumentChanged)
9055 return SemaRef.Owned(E);
9056
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009057 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00009058 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00009059}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009060
Douglas Gregorb98b1992009-08-11 05:31:07 +00009061//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00009062// Type reconstruction
9063//===----------------------------------------------------------------------===//
9064
Mike Stump1eb44332009-09-09 15:08:12 +00009065template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009066QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
9067 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009068 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009069 getDerived().getBaseEntity());
9070}
9071
Mike Stump1eb44332009-09-09 15:08:12 +00009072template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009073QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9074 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009075 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009076 getDerived().getBaseEntity());
9077}
9078
Mike Stump1eb44332009-09-09 15:08:12 +00009079template<typename Derived>
9080QualType
John McCall85737a72009-10-30 00:06:24 +00009081TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9082 bool WrittenAsLValue,
9083 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009084 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00009085 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009086}
9087
9088template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009089QualType
John McCall85737a72009-10-30 00:06:24 +00009090TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9091 QualType ClassType,
9092 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009093 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00009094 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009095}
9096
9097template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009098QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00009099TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9100 ArrayType::ArraySizeModifier SizeMod,
9101 const llvm::APInt *Size,
9102 Expr *SizeExpr,
9103 unsigned IndexTypeQuals,
9104 SourceRange BracketsRange) {
9105 if (SizeExpr || !Size)
9106 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9107 IndexTypeQuals, BracketsRange,
9108 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00009109
9110 QualType Types[] = {
9111 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9112 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9113 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00009114 };
9115 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
9116 QualType SizeType;
9117 for (unsigned I = 0; I != NumTypes; ++I)
9118 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9119 SizeType = Types[I];
9120 break;
9121 }
Mike Stump1eb44332009-09-09 15:08:12 +00009122
Eli Friedman01f276d2012-01-25 23:20:27 +00009123 // Note that we can return a VariableArrayType here in the case where
9124 // the element type was a dependent VariableArrayType.
9125 IntegerLiteral *ArraySize
9126 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9127 /*FIXME*/BracketsRange.getBegin());
9128 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009129 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00009130 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009131}
Mike Stump1eb44332009-09-09 15:08:12 +00009132
Douglas Gregor577f75a2009-08-04 16:50:30 +00009133template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009134QualType
9135TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009136 ArrayType::ArraySizeModifier SizeMod,
9137 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009138 unsigned IndexTypeQuals,
9139 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009140 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009141 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009142}
9143
9144template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009145QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009146TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009147 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009148 unsigned IndexTypeQuals,
9149 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009150 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009151 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009152}
Mike Stump1eb44332009-09-09 15:08:12 +00009153
Douglas Gregor577f75a2009-08-04 16:50:30 +00009154template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009155QualType
9156TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009157 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009158 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009159 unsigned IndexTypeQuals,
9160 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009161 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009162 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009163 IndexTypeQuals, BracketsRange);
9164}
9165
9166template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009167QualType
9168TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009169 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009170 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009171 unsigned IndexTypeQuals,
9172 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009173 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009174 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009175 IndexTypeQuals, BracketsRange);
9176}
9177
9178template<typename Derived>
9179QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009180 unsigned NumElements,
9181 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009182 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009183 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009184}
Mike Stump1eb44332009-09-09 15:08:12 +00009185
Douglas Gregor577f75a2009-08-04 16:50:30 +00009186template<typename Derived>
9187QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9188 unsigned NumElements,
9189 SourceLocation AttributeLoc) {
9190 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9191 NumElements, true);
9192 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009193 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9194 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009195 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009196}
Mike Stump1eb44332009-09-09 15:08:12 +00009197
Douglas Gregor577f75a2009-08-04 16:50:30 +00009198template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009199QualType
9200TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009201 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009202 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009203 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009204}
Mike Stump1eb44332009-09-09 15:08:12 +00009205
Douglas Gregor577f75a2009-08-04 16:50:30 +00009206template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009207QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9208 QualType T,
9209 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009210 const FunctionProtoType::ExtProtoInfo &EPI) {
9211 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009212 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009213 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009214 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009215}
Mike Stump1eb44332009-09-09 15:08:12 +00009216
Douglas Gregor577f75a2009-08-04 16:50:30 +00009217template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009218QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9219 return SemaRef.Context.getFunctionNoProtoType(T);
9220}
9221
9222template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009223QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9224 assert(D && "no decl found");
9225 if (D->isInvalidDecl()) return QualType();
9226
Douglas Gregor92e986e2010-04-22 16:44:27 +00009227 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009228 TypeDecl *Ty;
9229 if (isa<UsingDecl>(D)) {
9230 UsingDecl *Using = cast<UsingDecl>(D);
9231 assert(Using->isTypeName() &&
9232 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9233
9234 // A valid resolved using typename decl points to exactly one type decl.
9235 assert(++Using->shadow_begin() == Using->shadow_end());
9236 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009237
John McCalled976492009-12-04 22:46:56 +00009238 } else {
9239 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9240 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9241 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9242 }
9243
9244 return SemaRef.Context.getTypeDeclType(Ty);
9245}
9246
9247template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009248QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9249 SourceLocation Loc) {
9250 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009251}
9252
9253template<typename Derived>
9254QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9255 return SemaRef.Context.getTypeOfType(Underlying);
9256}
9257
9258template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009259QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9260 SourceLocation Loc) {
9261 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009262}
9263
9264template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009265QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9266 UnaryTransformType::UTTKind UKind,
9267 SourceLocation Loc) {
9268 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9269}
9270
9271template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009272QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009273 TemplateName Template,
9274 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009275 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009276 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009277}
Mike Stump1eb44332009-09-09 15:08:12 +00009278
Douglas Gregordcee1a12009-08-06 05:28:30 +00009279template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009280QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9281 SourceLocation KWLoc) {
9282 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9283}
9284
9285template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009286TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009287TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009288 bool TemplateKW,
9289 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009290 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009291 Template);
9292}
9293
9294template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009295TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009296TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9297 const IdentifierInfo &Name,
9298 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009299 QualType ObjectType,
9300 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009301 UnqualifiedId TemplateName;
9302 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009303 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009304 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009305 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009306 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009307 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009308 /*EnteringContext=*/false,
9309 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009310 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009311}
Mike Stump1eb44332009-09-09 15:08:12 +00009312
Douglas Gregorb98b1992009-08-11 05:31:07 +00009313template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009314TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009315TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009316 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009317 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009318 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009319 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009320 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009321 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009322 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009323 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009324 Sema::TemplateTy Template;
9325 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009326 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009327 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009328 /*EnteringContext=*/false,
9329 Template);
9330 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009331}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009332
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009333template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009334ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009335TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9336 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009337 Expr *OrigCallee,
9338 Expr *First,
9339 Expr *Second) {
9340 Expr *Callee = OrigCallee->IgnoreParenCasts();
9341 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009342
Douglas Gregorb98b1992009-08-11 05:31:07 +00009343 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009344 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009345 if (!First->getType()->isOverloadableType() &&
9346 !Second->getType()->isOverloadableType())
9347 return getSema().CreateBuiltinArraySubscriptExpr(First,
9348 Callee->getLocStart(),
9349 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009350 } else if (Op == OO_Arrow) {
9351 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009352 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9353 } else if (Second == 0 || isPostIncDec) {
9354 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009355 // The argument is not of overloadable type, so try to create a
9356 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009357 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009358 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009359
John McCall9ae2f072010-08-23 23:25:46 +00009360 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009361 }
9362 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009363 if (!First->getType()->isOverloadableType() &&
9364 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009365 // Neither of the arguments is an overloadable type, so try to
9366 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009367 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009368 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009369 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009370 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009371 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009372
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009373 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009374 }
9375 }
Mike Stump1eb44332009-09-09 15:08:12 +00009376
9377 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009378 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009379 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009380
John McCall9ae2f072010-08-23 23:25:46 +00009381 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009382 assert(ULE->requiresADL());
9383
9384 // FIXME: Do we have to check
9385 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009386 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009387 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009388 // If we've resolved this to a particular non-member function, just call
9389 // that function. If we resolved it to a member function,
9390 // CreateOverloaded* will find that function for us.
9391 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9392 if (!isa<CXXMethodDecl>(ND))
9393 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009394 }
Mike Stump1eb44332009-09-09 15:08:12 +00009395
Douglas Gregorb98b1992009-08-11 05:31:07 +00009396 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009397 Expr *Args[2] = { First, Second };
9398 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009399
Douglas Gregorb98b1992009-08-11 05:31:07 +00009400 // Create the overloaded operator invocation for unary operators.
9401 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009402 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009403 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009404 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009405 }
Mike Stump1eb44332009-09-09 15:08:12 +00009406
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009407 if (Op == OO_Subscript) {
9408 SourceLocation LBrace;
9409 SourceLocation RBrace;
9410
9411 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9412 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9413 LBrace = SourceLocation::getFromRawEncoding(
9414 NameLoc.CXXOperatorName.BeginOpNameLoc);
9415 RBrace = SourceLocation::getFromRawEncoding(
9416 NameLoc.CXXOperatorName.EndOpNameLoc);
9417 } else {
9418 LBrace = Callee->getLocStart();
9419 RBrace = OpLoc;
9420 }
9421
9422 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9423 First, Second);
9424 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009425
Douglas Gregorb98b1992009-08-11 05:31:07 +00009426 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009427 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009428 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009429 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9430 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009431 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009432
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009433 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009434}
Mike Stump1eb44332009-09-09 15:08:12 +00009435
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009436template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009437ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009438TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009439 SourceLocation OperatorLoc,
9440 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009441 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009442 TypeSourceInfo *ScopeType,
9443 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009444 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009445 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009446 QualType BaseType = Base->getType();
9447 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009448 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009449 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009450 !BaseType->getAs<PointerType>()->getPointeeType()
9451 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009452 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009453 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009454 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009455 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009456 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009457 /*FIXME?*/true);
9458 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009459
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009460 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009461 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9462 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9463 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9464 NameInfo.setNamedTypeInfo(DestroyedType);
9465
Richard Smith6314db92012-05-15 06:15:11 +00009466 // The scope type is now known to be a valid nested name specifier
9467 // component. Tack it on to the end of the nested name specifier.
9468 if (ScopeType)
9469 SS.Extend(SemaRef.Context, SourceLocation(),
9470 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009471
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009472 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009473 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009474 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009475 SS, TemplateKWLoc,
9476 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009477 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009478 /*TemplateArgs*/ 0);
9479}
9480
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009481template<typename Derived>
9482StmtResult
9483TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan9fd6b8f2013-05-04 03:59:06 +00009484 SourceLocation Loc = S->getLocStart();
9485 unsigned NumParams = S->getCapturedDecl()->getNumParams();
9486 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/0,
9487 S->getCapturedRegionKind(), NumParams);
9488 StmtResult Body = getDerived().TransformStmt(S->getCapturedStmt());
9489
9490 if (Body.isInvalid()) {
9491 getSema().ActOnCapturedRegionError();
9492 return StmtError();
9493 }
9494
9495 return getSema().ActOnCapturedRegionEnd(Body.take());
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009496}
9497
Douglas Gregor577f75a2009-08-04 16:50:30 +00009498} // end namespace clang
9499
9500#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H