blob: 71d95ef41ffd860c82cdf3508a6f99496b61cf77 [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
John McCall2d887082010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregore737f502010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor8491ffe2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregordcee1a12009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCall781472f2010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Richard Smith3e4c6c42011-05-05 21:57:07 +000024#include "clang/AST/DeclTemplate.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000025#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000026#include "clang/AST/ExprCXX.h"
27#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000028#include "clang/AST/Stmt.h"
29#include "clang/AST/StmtCXX.h"
30#include "clang/AST/StmtObjC.h"
John McCall19510852010-08-20 18:27:03 +000031#include "clang/Sema/Ownership.h"
32#include "clang/Sema/Designator.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000033#include "clang/Lex/Preprocessor.h"
David Blaikiea71f9d02011-09-22 02:34:54 +000034#include "llvm/ADT/ArrayRef.h"
John McCalla2becad2009-10-21 00:40:46 +000035#include "llvm/Support/ErrorHandling.h"
Douglas Gregor7e44e3f2010-12-02 00:05:49 +000036#include "TypeLocBuilder.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,
David Blaikiea71f9d02011-09-22 02:34:54 +0000250 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000251 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000252 bool &RetainExpansion,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000253 llvm::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
Douglas Gregoraa165f82011-01-03 19:04:46 +0000326 /// \brief Transform the given list of expressions.
327 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000328 /// This routine transforms a list of expressions by invoking
329 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregoraa165f82011-01-03 19:04:46 +0000330 /// support for variadic templates by expanding any pack expansions (if the
331 /// derived class permits such expansion) along the way. When pack expansions
332 /// are present, the number of outputs may not equal the number of inputs.
333 ///
334 /// \param Inputs The set of expressions to be transformed.
335 ///
336 /// \param NumInputs The number of expressions in \c Inputs.
337 ///
338 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier4a9d7952012-08-08 18:46:20 +0000339 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregoraa165f82011-01-03 19:04:46 +0000340 /// be.
341 ///
342 /// \param Outputs The transformed input expressions will be added to this
343 /// vector.
344 ///
345 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
346 /// due to transformation.
347 ///
348 /// \returns true if an error occurred, false otherwise.
349 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +0000350 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000351 bool *ArgChanged = 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000352
Douglas Gregor577f75a2009-08-04 16:50:30 +0000353 /// \brief Transform the given declaration, which is referenced from a type
354 /// or expression.
355 ///
Douglas Gregordfca6f52012-02-13 22:00:16 +0000356 /// By default, acts as the identity function on declarations, unless the
357 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregordcee1a12009-08-06 05:28:30 +0000358 /// may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000359 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregordfca6f52012-02-13 22:00:16 +0000360 llvm::DenseMap<Decl *, Decl *>::iterator Known
361 = TransformedLocalDecls.find(D);
362 if (Known != TransformedLocalDecls.end())
363 return Known->second;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000364
365 return D;
Douglas Gregordfca6f52012-02-13 22:00:16 +0000366 }
Douglas Gregor43959a92009-08-20 07:17:43 +0000367
Chad Rosier4a9d7952012-08-08 18:46:20 +0000368 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregordfca6f52012-02-13 22:00:16 +0000369 /// place them on the new declaration.
370 ///
371 /// By default, this operation does nothing. Subclasses may override this
372 /// behavior to transform attributes.
373 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000374
Douglas Gregordfca6f52012-02-13 22:00:16 +0000375 /// \brief Note that a local declaration has been transformed by this
376 /// transformer.
377 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000378 /// Local declarations are typically transformed via a call to
Douglas Gregordfca6f52012-02-13 22:00:16 +0000379 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
380 /// the transformer itself has to transform the declarations. This routine
381 /// can be overridden by a subclass that keeps track of such mappings.
382 void transformedLocalDecl(Decl *Old, Decl *New) {
383 TransformedLocalDecls[Old] = New;
384 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000385
Douglas Gregor43959a92009-08-20 07:17:43 +0000386 /// \brief Transform the definition of the given declaration.
387 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000388 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000389 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000390 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
391 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000392 }
Mike Stump1eb44332009-09-09 15:08:12 +0000393
Douglas Gregor6cd21982009-10-20 05:58:46 +0000394 /// \brief Transform the given declaration, which was the first part of a
395 /// nested-name-specifier in a member access expression.
396 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000397 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000398 /// identifier in a nested-name-specifier of a member access expression, e.g.,
399 /// the \c T in \c x->T::member
400 ///
401 /// By default, invokes TransformDecl() to transform the declaration.
402 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000403 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
404 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000405 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000406
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000407 /// \brief Transform the given nested-name-specifier with source-location
408 /// information.
409 ///
410 /// By default, transforms all of the types and declarations within the
411 /// nested-name-specifier. Subclasses may override this function to provide
412 /// alternate behavior.
413 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
414 NestedNameSpecifierLoc NNS,
415 QualType ObjectType = QualType(),
416 NamedDecl *FirstQualifierInScope = 0);
417
Douglas Gregor81499bb2009-09-03 22:13:48 +0000418 /// \brief Transform the given declaration name.
419 ///
420 /// By default, transforms the types of conversion function, constructor,
421 /// and destructor names and then (if needed) rebuilds the declaration name.
422 /// Identifiers and selectors are returned unmodified. Sublcasses may
423 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000424 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000425 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000426
Douglas Gregor577f75a2009-08-04 16:50:30 +0000427 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000428 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000429 /// \param SS The nested-name-specifier that qualifies the template
430 /// name. This nested-name-specifier must already have been transformed.
431 ///
432 /// \param Name The template name to transform.
433 ///
434 /// \param NameLoc The source location of the template name.
435 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000436 /// \param ObjectType If we're translating a template name within a member
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000437 /// access expression, this is the type of the object whose member template
438 /// is being referenced.
439 ///
440 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
441 /// also refers to a name within the current (lexical) scope, this is the
442 /// declaration it refers to.
443 ///
444 /// By default, transforms the template name by transforming the declarations
445 /// and nested-name-specifiers that occur within the template name.
446 /// Subclasses may override this function to provide alternate behavior.
447 TemplateName TransformTemplateName(CXXScopeSpec &SS,
448 TemplateName Name,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000449 SourceLocation NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000450 QualType ObjectType = QualType(),
451 NamedDecl *FirstQualifierInScope = 0);
452
Douglas Gregor577f75a2009-08-04 16:50:30 +0000453 /// \brief Transform the given template argument.
454 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000455 /// By default, this operation transforms the type, expression, or
456 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000457 /// new template argument from the transformed result. Subclasses may
458 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000459 ///
460 /// Returns true if there was an error.
461 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
462 TemplateArgumentLoc &Output);
463
Douglas Gregorfcc12532010-12-20 17:31:10 +0000464 /// \brief Transform the given set of template arguments.
465 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000466 /// By default, this operation transforms all of the template arguments
Douglas Gregorfcc12532010-12-20 17:31:10 +0000467 /// in the input set using \c TransformTemplateArgument(), and appends
468 /// the transformed arguments to the output list.
469 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000470 /// Note that this overload of \c TransformTemplateArguments() is merely
471 /// a convenience function. Subclasses that wish to override this behavior
472 /// should override the iterator-based member template version.
473 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000474 /// \param Inputs The set of template arguments to be transformed.
475 ///
476 /// \param NumInputs The number of template arguments in \p Inputs.
477 ///
478 /// \param Outputs The set of transformed template arguments output by this
479 /// routine.
480 ///
481 /// Returns true if an error occurred.
482 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
483 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000484 TemplateArgumentListInfo &Outputs) {
485 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
486 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000487
488 /// \brief Transform the given set of template arguments.
489 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000490 /// By default, this operation transforms all of the template arguments
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000491 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier4a9d7952012-08-08 18:46:20 +0000492 /// the transformed arguments to the output list.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000493 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000494 /// \param First An iterator to the first template argument.
495 ///
496 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000497 ///
498 /// \param Outputs The set of transformed template arguments output by this
499 /// routine.
500 ///
501 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000502 template<typename InputIterator>
503 bool TransformTemplateArguments(InputIterator First,
504 InputIterator Last,
505 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000506
John McCall833ca992009-10-29 08:12:44 +0000507 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
508 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
509 TemplateArgumentLoc &ArgLoc);
510
John McCalla93c9342009-12-07 02:54:59 +0000511 /// \brief Fakes up a TypeSourceInfo for a type.
512 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
513 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000514 getDerived().getBaseLocation());
515 }
Mike Stump1eb44332009-09-09 15:08:12 +0000516
John McCalla2becad2009-10-21 00:40:46 +0000517#define ABSTRACT_TYPELOC(CLASS, PARENT)
518#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000519 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000520#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000521
Douglas Gregorcefc3af2012-04-16 07:05:22 +0000522 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
523 FunctionProtoTypeLoc TL,
524 CXXRecordDecl *ThisContext,
525 unsigned ThisTypeQuals);
526
John Wiegley28bbe4b2011-04-28 01:08:34 +0000527 StmtResult
528 TransformSEHHandler(Stmt *Handler);
529
Chad Rosier4a9d7952012-08-08 18:46:20 +0000530 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000531 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
532 TemplateSpecializationTypeLoc TL,
533 TemplateName Template);
534
Chad Rosier4a9d7952012-08-08 18:46:20 +0000535 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000536 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
537 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000538 TemplateName Template,
539 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000540
Chad Rosier4a9d7952012-08-08 18:46:20 +0000541 QualType
Douglas Gregora88f09f2011-02-28 17:23:35 +0000542 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000543 DependentTemplateSpecializationTypeLoc TL,
544 NestedNameSpecifierLoc QualifierLoc);
545
John McCall21ef0fa2010-03-11 09:03:00 +0000546 /// \brief Transforms the parameters of a function type into the
547 /// given vectors.
548 ///
549 /// The result vectors should be kept in sync; null entries in the
550 /// variables vector are acceptable.
551 ///
552 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000553 bool TransformFunctionTypeParams(SourceLocation Loc,
554 ParmVarDecl **Params, unsigned NumParams,
555 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000556 SmallVectorImpl<QualType> &PTypes,
557 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000558
559 /// \brief Transforms a single function-type parameter. Return null
560 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000561 ///
562 /// \param indexAdjustment - A number to add to the parameter's
563 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000564 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000565 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000566 llvm::Optional<unsigned> NumExpansions,
567 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000568
John McCall43fed0d2010-11-12 08:19:04 +0000569 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000570
John McCall60d7b3a2010-08-24 06:29:42 +0000571 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
572 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000573
Richard Smith612409e2012-07-25 03:56:55 +0000574 /// \brief Transform the captures and body of a lambda expression.
575 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator);
576
Douglas Gregor43959a92009-08-20 07:17:43 +0000577#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000578 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000579#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000580 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000581#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000582#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000583
Douglas Gregor577f75a2009-08-04 16:50:30 +0000584 /// \brief Build a new pointer type given its pointee type.
585 ///
586 /// By default, performs semantic analysis when building the pointer type.
587 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000588 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000589
590 /// \brief Build a new block pointer type given its pointee type.
591 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000592 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000593 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000594 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000595
John McCall85737a72009-10-30 00:06:24 +0000596 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000597 ///
John McCall85737a72009-10-30 00:06:24 +0000598 /// By default, performs semantic analysis when building the
599 /// reference type. Subclasses may override this routine to provide
600 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000601 ///
John McCall85737a72009-10-30 00:06:24 +0000602 /// \param LValue whether the type was written with an lvalue sigil
603 /// or an rvalue sigil.
604 QualType RebuildReferenceType(QualType ReferentType,
605 bool LValue,
606 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000607
Douglas Gregor577f75a2009-08-04 16:50:30 +0000608 /// \brief Build a new member pointer type given the pointee type and the
609 /// class type it refers into.
610 ///
611 /// By default, performs semantic analysis when building the member pointer
612 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000613 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
614 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000615
Douglas Gregor577f75a2009-08-04 16:50:30 +0000616 /// \brief Build a new array type given the element type, size
617 /// modifier, size of the array (if known), size expression, and index type
618 /// qualifiers.
619 ///
620 /// By default, performs semantic analysis when building the array type.
621 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000622 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000623 QualType RebuildArrayType(QualType ElementType,
624 ArrayType::ArraySizeModifier SizeMod,
625 const llvm::APInt *Size,
626 Expr *SizeExpr,
627 unsigned IndexTypeQuals,
628 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000629
Douglas Gregor577f75a2009-08-04 16:50:30 +0000630 /// \brief Build a new constant array type given the element type, size
631 /// modifier, (known) size of the array, and index type 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 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000636 ArrayType::ArraySizeModifier SizeMod,
637 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000638 unsigned IndexTypeQuals,
639 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000640
Douglas Gregor577f75a2009-08-04 16:50:30 +0000641 /// \brief Build a new incomplete array type given the element type, size
642 /// modifier, and index type qualifiers.
643 ///
644 /// By default, performs semantic analysis when building the array type.
645 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000646 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000647 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000648 unsigned IndexTypeQuals,
649 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000650
Mike Stump1eb44332009-09-09 15:08:12 +0000651 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000652 /// size modifier, size expression, and index type qualifiers.
653 ///
654 /// By default, performs semantic analysis when building the array type.
655 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000656 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000657 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000658 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000659 unsigned IndexTypeQuals,
660 SourceRange BracketsRange);
661
Mike Stump1eb44332009-09-09 15:08:12 +0000662 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000663 /// size modifier, size expression, and index type qualifiers.
664 ///
665 /// By default, performs semantic analysis when building the array type.
666 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000667 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000668 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000669 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000670 unsigned IndexTypeQuals,
671 SourceRange BracketsRange);
672
673 /// \brief Build a new vector type given the element type and
674 /// number of elements.
675 ///
676 /// By default, performs semantic analysis when building the vector type.
677 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000678 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000679 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000680
Douglas Gregor577f75a2009-08-04 16:50:30 +0000681 /// \brief Build a new extended vector type given the element type and
682 /// number of elements.
683 ///
684 /// By default, performs semantic analysis when building the vector type.
685 /// Subclasses may override this routine to provide different behavior.
686 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
687 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000688
689 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000690 /// given the element type and number of elements.
691 ///
692 /// By default, performs semantic analysis when building the vector type.
693 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000694 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000695 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000696 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000697
Douglas Gregor577f75a2009-08-04 16:50:30 +0000698 /// \brief Build a new function type.
699 ///
700 /// By default, performs semantic analysis when building the function type.
701 /// Subclasses may override this routine to provide different behavior.
702 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000703 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000704 unsigned NumParamTypes,
Richard Smitheefb3d52012-02-10 09:58:53 +0000705 bool Variadic, bool HasTrailingReturn,
706 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000707 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000708 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000709
John McCalla2becad2009-10-21 00:40:46 +0000710 /// \brief Build a new unprototyped function type.
711 QualType RebuildFunctionNoProtoType(QualType ResultType);
712
John McCalled976492009-12-04 22:46:56 +0000713 /// \brief Rebuild an unresolved typename type, given the decl that
714 /// the UnresolvedUsingTypenameDecl was transformed to.
715 QualType RebuildUnresolvedUsingType(Decl *D);
716
Douglas Gregor577f75a2009-08-04 16:50:30 +0000717 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000718 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000719 return SemaRef.Context.getTypeDeclType(Typedef);
720 }
721
722 /// \brief Build a new class/struct/union type.
723 QualType RebuildRecordType(RecordDecl *Record) {
724 return SemaRef.Context.getTypeDeclType(Record);
725 }
726
727 /// \brief Build a new Enum type.
728 QualType RebuildEnumType(EnumDecl *Enum) {
729 return SemaRef.Context.getTypeDeclType(Enum);
730 }
John McCall7da24312009-09-05 00:15:47 +0000731
Mike Stump1eb44332009-09-09 15:08:12 +0000732 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000733 ///
734 /// By default, performs semantic analysis when building the typeof type.
735 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000736 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000737
Mike Stump1eb44332009-09-09 15:08:12 +0000738 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000739 ///
740 /// By default, builds a new TypeOfType with the given underlying type.
741 QualType RebuildTypeOfType(QualType Underlying);
742
Sean Huntca63c202011-05-24 22:41:36 +0000743 /// \brief Build a new unary transform type.
744 QualType RebuildUnaryTransformType(QualType BaseType,
745 UnaryTransformType::UTTKind UKind,
746 SourceLocation Loc);
747
Mike Stump1eb44332009-09-09 15:08:12 +0000748 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000749 ///
750 /// By default, performs semantic analysis when building the decltype type.
751 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000752 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000753
Richard Smith34b41d92011-02-20 03:19:35 +0000754 /// \brief Build a new C++0x auto type.
755 ///
756 /// By default, builds a new AutoType with the given deduced type.
757 QualType RebuildAutoType(QualType Deduced) {
758 return SemaRef.Context.getAutoType(Deduced);
759 }
760
Douglas Gregor577f75a2009-08-04 16:50:30 +0000761 /// \brief Build a new template specialization type.
762 ///
763 /// By default, performs semantic analysis when building the template
764 /// specialization type. Subclasses may override this routine to provide
765 /// different behavior.
766 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000767 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000768 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000769
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000770 /// \brief Build a new parenthesized type.
771 ///
772 /// By default, builds a new ParenType type from the inner type.
773 /// Subclasses may override this routine to provide different behavior.
774 QualType RebuildParenType(QualType InnerType) {
775 return SemaRef.Context.getParenType(InnerType);
776 }
777
Douglas Gregor577f75a2009-08-04 16:50:30 +0000778 /// \brief Build a new qualified name type.
779 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000780 /// By default, builds a new ElaboratedType type from the keyword,
781 /// the nested-name-specifier and the named type.
782 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000783 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
784 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000785 NestedNameSpecifierLoc QualifierLoc,
786 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000787 return SemaRef.Context.getElaboratedType(Keyword,
788 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000789 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000790 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000791
792 /// \brief Build a new typename type that refers to a template-id.
793 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000794 /// By default, builds a new DependentNameType type from the
795 /// nested-name-specifier and the given type. Subclasses may override
796 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000797 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000798 ElaboratedTypeKeyword Keyword,
799 NestedNameSpecifierLoc QualifierLoc,
800 const IdentifierInfo *Name,
801 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000802 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000803 // Rebuild the template name.
804 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000805 CXXScopeSpec SS;
806 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000807 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000808 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000809
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000810 if (InstName.isNull())
811 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000812
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000813 // If it's still dependent, make a dependent specialization.
814 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000815 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
816 QualifierLoc.getNestedNameSpecifier(),
817 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000818 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000819
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000820 // Otherwise, make an elaborated type wrapping a non-dependent
821 // specialization.
822 QualType T =
823 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
824 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000825
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000826 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
827 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000828
829 return SemaRef.Context.getElaboratedType(Keyword,
830 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000831 T);
832 }
833
Douglas Gregor577f75a2009-08-04 16:50:30 +0000834 /// \brief Build a new typename type that refers to an identifier.
835 ///
836 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000837 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000838 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000839 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000840 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000841 NestedNameSpecifierLoc QualifierLoc,
842 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000843 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000844 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000845 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000846
Douglas Gregor2494dd02011-03-01 01:34:45 +0000847 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000848 // If the name is still dependent, just build a new dependent name type.
849 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000850 return SemaRef.Context.getDependentNameType(Keyword,
851 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000852 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000853 }
854
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000855 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000856 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000857 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000858
859 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
860
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000861 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000862 // into a non-dependent elaborated-type-specifier. Find the tag we're
863 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000864 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000865 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
866 if (!DC)
867 return QualType();
868
John McCall56138762010-05-27 06:40:31 +0000869 if (SemaRef.RequireCompleteDeclContext(SS, DC))
870 return QualType();
871
Douglas Gregor40336422010-03-31 22:19:08 +0000872 TagDecl *Tag = 0;
873 SemaRef.LookupQualifiedName(Result, DC);
874 switch (Result.getResultKind()) {
875 case LookupResult::NotFound:
876 case LookupResult::NotFoundInCurrentInstantiation:
877 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000878
Douglas Gregor40336422010-03-31 22:19:08 +0000879 case LookupResult::Found:
880 Tag = Result.getAsSingle<TagDecl>();
881 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000882
Douglas Gregor40336422010-03-31 22:19:08 +0000883 case LookupResult::FoundOverloaded:
884 case LookupResult::FoundUnresolvedValue:
885 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000886
Douglas Gregor40336422010-03-31 22:19:08 +0000887 case LookupResult::Ambiguous:
888 // Let the LookupResult structure handle ambiguities.
889 return QualType();
890 }
891
892 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000893 // Check where the name exists but isn't a tag type and use that to emit
894 // better diagnostics.
895 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
896 SemaRef.LookupQualifiedName(Result, DC);
897 switch (Result.getResultKind()) {
898 case LookupResult::Found:
899 case LookupResult::FoundOverloaded:
900 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000901 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000902 unsigned Kind = 0;
903 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000904 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
905 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000906 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
907 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
908 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000909 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000910 default:
911 // FIXME: Would be nice to highlight just the source range.
912 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
913 << Kind << Id << DC;
914 break;
915 }
Douglas Gregor40336422010-03-31 22:19:08 +0000916 return QualType();
917 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000918
Richard Trieubbf34c02011-06-10 03:11:26 +0000919 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
920 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000921 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000922 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
923 return QualType();
924 }
925
926 // Build the elaborated-type-specifier type.
927 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000928 return SemaRef.Context.getElaboratedType(Keyword,
929 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000930 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000931 }
Mike Stump1eb44332009-09-09 15:08:12 +0000932
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000933 /// \brief Build a new pack expansion type.
934 ///
935 /// By default, builds a new PackExpansionType type from the given pattern.
936 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000937 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000938 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000939 SourceLocation EllipsisLoc,
940 llvm::Optional<unsigned> NumExpansions) {
941 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
942 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000943 }
944
Eli Friedmanb001de72011-10-06 23:00:33 +0000945 /// \brief Build a new atomic type given its value type.
946 ///
947 /// By default, performs semantic analysis when building the atomic type.
948 /// Subclasses may override this routine to provide different behavior.
949 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
950
Douglas Gregord1067e52009-08-06 06:41:21 +0000951 /// \brief Build a new template name given a nested name specifier, a flag
952 /// indicating whether the "template" keyword was provided, and the template
953 /// that the template name refers to.
954 ///
955 /// By default, builds the new template name directly. Subclasses may override
956 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000957 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000958 bool TemplateKW,
959 TemplateDecl *Template);
960
Douglas Gregord1067e52009-08-06 06:41:21 +0000961 /// \brief Build a new template name given a nested name specifier and the
962 /// name that is referred to as a template.
963 ///
964 /// By default, performs semantic analysis to determine whether the name can
965 /// be resolved to a specific template, then builds the appropriate kind of
966 /// template name. Subclasses may override this routine to provide different
967 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000968 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
969 const IdentifierInfo &Name,
970 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000971 QualType ObjectType,
972 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000973
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000974 /// \brief Build a new template name given a nested name specifier and the
975 /// overloaded operator name that is referred to as a template.
976 ///
977 /// By default, performs semantic analysis to determine whether the name can
978 /// be resolved to a specific template, then builds the appropriate kind of
979 /// template name. Subclasses may override this routine to provide different
980 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000981 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000982 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000983 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000984 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000985
986 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +0000987 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000988 ///
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.
993 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
994 const TemplateArgument &ArgPack) {
995 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
996 }
997
Douglas Gregor43959a92009-08-20 07:17:43 +0000998 /// \brief Build a new compound statement.
999 ///
1000 /// By default, performs semantic analysis to build the new statement.
1001 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001002 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001003 MultiStmtArg Statements,
1004 SourceLocation RBraceLoc,
1005 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001006 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001007 IsStmtExpr);
1008 }
1009
1010 /// \brief Build a new case 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 RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001015 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001016 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001017 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001018 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001019 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001020 ColonLoc);
1021 }
Mike Stump1eb44332009-09-09 15:08:12 +00001022
Douglas Gregor43959a92009-08-20 07:17:43 +00001023 /// \brief Attach the body to a new case statement.
1024 ///
1025 /// By default, performs semantic analysis to build the new statement.
1026 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001027 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001028 getSema().ActOnCaseStmtBody(S, Body);
1029 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001030 }
Mike Stump1eb44332009-09-09 15:08:12 +00001031
Douglas Gregor43959a92009-08-20 07:17:43 +00001032 /// \brief Build a new default statement.
1033 ///
1034 /// By default, performs semantic analysis to build the new statement.
1035 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001036 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001037 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001038 Stmt *SubStmt) {
1039 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001040 /*CurScope=*/0);
1041 }
Mike Stump1eb44332009-09-09 15:08:12 +00001042
Douglas Gregor43959a92009-08-20 07:17:43 +00001043 /// \brief Build a new label statement.
1044 ///
1045 /// By default, performs semantic analysis to build the new statement.
1046 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001047 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1048 SourceLocation ColonLoc, Stmt *SubStmt) {
1049 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001050 }
Mike Stump1eb44332009-09-09 15:08:12 +00001051
Richard Smith534986f2012-04-14 00:33:13 +00001052 /// \brief Build a new label statement.
1053 ///
1054 /// By default, performs semantic analysis to build the new statement.
1055 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001056 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1057 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001058 Stmt *SubStmt) {
1059 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1060 }
1061
Douglas Gregor43959a92009-08-20 07:17:43 +00001062 /// \brief Build a new "if" statement.
1063 ///
1064 /// By default, performs semantic analysis to build the new statement.
1065 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001066 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001067 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001068 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001069 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001070 }
Mike Stump1eb44332009-09-09 15:08:12 +00001071
Douglas Gregor43959a92009-08-20 07:17:43 +00001072 /// \brief Start building a new switch statement.
1073 ///
1074 /// By default, performs semantic analysis to build the new statement.
1075 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001076 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001077 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001078 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001079 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001080 }
Mike Stump1eb44332009-09-09 15:08:12 +00001081
Douglas Gregor43959a92009-08-20 07:17:43 +00001082 /// \brief Attach the body to the switch statement.
1083 ///
1084 /// By default, performs semantic analysis to build the new statement.
1085 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001086 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001087 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001088 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001089 }
1090
1091 /// \brief Build a new while statement.
1092 ///
1093 /// By default, performs semantic analysis to build the new statement.
1094 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001095 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1096 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001097 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001098 }
Mike Stump1eb44332009-09-09 15:08:12 +00001099
Douglas Gregor43959a92009-08-20 07:17:43 +00001100 /// \brief Build a new do-while statement.
1101 ///
1102 /// By default, performs semantic analysis to build the new statement.
1103 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001104 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001105 SourceLocation WhileLoc, SourceLocation LParenLoc,
1106 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001107 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1108 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001109 }
1110
1111 /// \brief Build a new for statement.
1112 ///
1113 /// By default, performs semantic analysis to build the new statement.
1114 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001115 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001116 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001117 VarDecl *CondVar, Sema::FullExprArg Inc,
1118 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001119 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001120 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001121 }
Mike Stump1eb44332009-09-09 15:08:12 +00001122
Douglas Gregor43959a92009-08-20 07:17:43 +00001123 /// \brief Build a new goto 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 RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1128 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001129 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001130 }
1131
1132 /// \brief Build a new indirect goto statement.
1133 ///
1134 /// By default, performs semantic analysis to build the new statement.
1135 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001136 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001137 SourceLocation StarLoc,
1138 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001139 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001140 }
Mike Stump1eb44332009-09-09 15:08:12 +00001141
Douglas Gregor43959a92009-08-20 07:17:43 +00001142 /// \brief Build a new return statement.
1143 ///
1144 /// By default, performs semantic analysis to build the new statement.
1145 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001146 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001147 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001148 }
Mike Stump1eb44332009-09-09 15:08:12 +00001149
Douglas Gregor43959a92009-08-20 07:17:43 +00001150 /// \brief Build a new declaration statement.
1151 ///
1152 /// By default, performs semantic analysis to build the new statement.
1153 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001154 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001155 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001156 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001157 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1158 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001159 }
Mike Stump1eb44332009-09-09 15:08:12 +00001160
Anders Carlsson703e3942010-01-24 05:50:09 +00001161 /// \brief Build a new inline asm statement.
1162 ///
1163 /// By default, performs semantic analysis to build the new statement.
1164 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001165 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1166 bool IsVolatile, unsigned NumOutputs,
1167 unsigned NumInputs, IdentifierInfo **Names,
1168 MultiExprArg Constraints, MultiExprArg Exprs,
1169 Expr *AsmString, MultiExprArg Clobbers,
1170 SourceLocation RParenLoc) {
1171 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1172 NumInputs, Names, Constraints, Exprs,
1173 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001174 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001175
Chad Rosier8cd64b42012-06-11 20:47:18 +00001176 /// \brief Build a new MS style inline asm statement.
1177 ///
1178 /// By default, performs semantic analysis to build the new statement.
1179 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001180 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
1181 ArrayRef<Token> AsmToks, SourceLocation EndLoc) {
Chad Rosier7bd092b2012-08-15 16:53:30 +00001182 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001183 }
1184
James Dennett699c9042012-06-15 07:13:21 +00001185 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001186 ///
1187 /// By default, performs semantic analysis to build the new statement.
1188 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001189 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001190 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001191 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001192 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001193 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001194 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001195 }
1196
Douglas Gregorbe270a02010-04-26 17:57:08 +00001197 /// \brief Rebuild an Objective-C exception declaration.
1198 ///
1199 /// By default, performs semantic analysis to build the new declaration.
1200 /// Subclasses may override this routine to provide different behavior.
1201 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1202 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001203 return getSema().BuildObjCExceptionDecl(TInfo, T,
1204 ExceptionDecl->getInnerLocStart(),
1205 ExceptionDecl->getLocation(),
1206 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001207 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001208
James Dennett699c9042012-06-15 07:13:21 +00001209 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001210 ///
1211 /// By default, performs semantic analysis to build the new statement.
1212 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001213 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001214 SourceLocation RParenLoc,
1215 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001216 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001217 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001218 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001219 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001220
James Dennett699c9042012-06-15 07:13:21 +00001221 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001222 ///
1223 /// By default, performs semantic analysis to build the new statement.
1224 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001225 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001226 Stmt *Body) {
1227 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001228 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001229
James Dennett699c9042012-06-15 07:13:21 +00001230 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001231 ///
1232 /// By default, performs semantic analysis to build the new statement.
1233 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001234 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001235 Expr *Operand) {
1236 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001237 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001238
James Dennett699c9042012-06-15 07:13:21 +00001239 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001240 ///
1241 /// By default, performs semantic analysis to build the new statement.
1242 /// Subclasses may override this routine to provide different behavior.
1243 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1244 Expr *object) {
1245 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1246 }
1247
James Dennett699c9042012-06-15 07:13:21 +00001248 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001249 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001250 /// By default, performs semantic analysis to build the new statement.
1251 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001252 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001253 Expr *Object, Stmt *Body) {
1254 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001255 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001256
James Dennett699c9042012-06-15 07:13:21 +00001257 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001258 ///
1259 /// By default, performs semantic analysis to build the new statement.
1260 /// Subclasses may override this routine to provide different behavior.
1261 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1262 Stmt *Body) {
1263 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1264 }
John McCall990567c2011-07-27 01:07:15 +00001265
Douglas Gregorc3203e72010-04-22 23:10:45 +00001266 /// \brief Build a new Objective-C fast enumeration statement.
1267 ///
1268 /// By default, performs semantic analysis to build the new statement.
1269 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001270 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001271 Stmt *Element,
1272 Expr *Collection,
1273 SourceLocation RParenLoc,
1274 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001275 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001276 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001277 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001278 RParenLoc);
1279 if (ForEachStmt.isInvalid())
1280 return StmtError();
1281
1282 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001283 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001284
Douglas Gregor43959a92009-08-20 07:17:43 +00001285 /// \brief Build a new C++ exception declaration.
1286 ///
1287 /// By default, performs semantic analysis to build the new decaration.
1288 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001289 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001290 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001291 SourceLocation StartLoc,
1292 SourceLocation IdLoc,
1293 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001294 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1295 StartLoc, IdLoc, Id);
1296 if (Var)
1297 getSema().CurContext->addDecl(Var);
1298 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001299 }
1300
1301 /// \brief Build a new C++ catch statement.
1302 ///
1303 /// By default, performs semantic analysis to build the new statement.
1304 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001305 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001306 VarDecl *ExceptionDecl,
1307 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001308 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1309 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001310 }
Mike Stump1eb44332009-09-09 15:08:12 +00001311
Douglas Gregor43959a92009-08-20 07:17:43 +00001312 /// \brief Build a new C++ try statement.
1313 ///
1314 /// By default, performs semantic analysis to build the new statement.
1315 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001316 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001317 Stmt *TryBlock,
1318 MultiStmtArg Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001319 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001320 }
Mike Stump1eb44332009-09-09 15:08:12 +00001321
Richard Smithad762fc2011-04-14 22:09:26 +00001322 /// \brief Build a new C++0x range-based for statement.
1323 ///
1324 /// By default, performs semantic analysis to build the new statement.
1325 /// Subclasses may override this routine to provide different behavior.
1326 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1327 SourceLocation ColonLoc,
1328 Stmt *Range, Stmt *BeginEnd,
1329 Expr *Cond, Expr *Inc,
1330 Stmt *LoopVar,
1331 SourceLocation RParenLoc) {
1332 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Sam Panzere1715b62012-08-21 00:52:01 +00001333 Cond, Inc, LoopVar, RParenLoc, false);
Richard Smithad762fc2011-04-14 22:09:26 +00001334 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001335
1336 /// \brief Build a new C++0x range-based for statement.
1337 ///
1338 /// By default, performs semantic analysis to build the new statement.
1339 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001340 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001341 bool IsIfExists,
1342 NestedNameSpecifierLoc QualifierLoc,
1343 DeclarationNameInfo NameInfo,
1344 Stmt *Nested) {
1345 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1346 QualifierLoc, NameInfo, Nested);
1347 }
1348
Richard Smithad762fc2011-04-14 22:09:26 +00001349 /// \brief Attach body to a C++0x range-based for statement.
1350 ///
1351 /// By default, performs semantic analysis to finish the new statement.
1352 /// Subclasses may override this routine to provide different behavior.
1353 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1354 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1355 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001356
John Wiegley28bbe4b2011-04-28 01:08:34 +00001357 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1358 SourceLocation TryLoc,
1359 Stmt *TryBlock,
1360 Stmt *Handler) {
1361 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1362 }
1363
1364 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1365 Expr *FilterExpr,
1366 Stmt *Block) {
1367 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1368 }
1369
1370 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1371 Stmt *Block) {
1372 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1373 }
1374
Douglas Gregorb98b1992009-08-11 05:31:07 +00001375 /// \brief Build a new expression that references a declaration.
1376 ///
1377 /// By default, performs semantic analysis to build the new expression.
1378 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001379 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001380 LookupResult &R,
1381 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001382 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1383 }
1384
1385
1386 /// \brief Build a new expression that references a declaration.
1387 ///
1388 /// By default, performs semantic analysis to build the new expression.
1389 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001390 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001391 ValueDecl *VD,
1392 const DeclarationNameInfo &NameInfo,
1393 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001394 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001395 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001396
1397 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001398
1399 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001400 }
Mike Stump1eb44332009-09-09 15:08:12 +00001401
Douglas Gregorb98b1992009-08-11 05:31:07 +00001402 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001403 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001404 /// By default, performs semantic analysis to build the new expression.
1405 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001406 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001407 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001408 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001409 }
1410
Douglas Gregora71d8192009-09-04 17:36:40 +00001411 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001412 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001413 /// By default, performs semantic analysis to build the new expression.
1414 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001415 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001416 SourceLocation OperatorLoc,
1417 bool isArrow,
1418 CXXScopeSpec &SS,
1419 TypeSourceInfo *ScopeType,
1420 SourceLocation CCLoc,
1421 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001422 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001423
Douglas Gregorb98b1992009-08-11 05:31:07 +00001424 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001425 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001426 /// By default, performs semantic analysis to build the new expression.
1427 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001428 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001429 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001430 Expr *SubExpr) {
1431 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001432 }
Mike Stump1eb44332009-09-09 15:08:12 +00001433
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001434 /// \brief Build a new builtin offsetof expression.
1435 ///
1436 /// By default, performs semantic analysis to build the new expression.
1437 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001438 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001439 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001440 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001441 unsigned NumComponents,
1442 SourceLocation RParenLoc) {
1443 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1444 NumComponents, RParenLoc);
1445 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001446
1447 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001448 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001449 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001450 /// By default, performs semantic analysis to build the new expression.
1451 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001452 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1453 SourceLocation OpLoc,
1454 UnaryExprOrTypeTrait ExprKind,
1455 SourceRange R) {
1456 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001457 }
1458
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001459 /// \brief Build a new sizeof, alignof or vec step expression with an
1460 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001461 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001462 /// By default, performs semantic analysis to build the new expression.
1463 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001464 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1465 UnaryExprOrTypeTrait ExprKind,
1466 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001467 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001468 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001469 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001470 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001471
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001472 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001473 }
Mike Stump1eb44332009-09-09 15:08:12 +00001474
Douglas Gregorb98b1992009-08-11 05:31:07 +00001475 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001476 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001477 /// By default, performs semantic analysis to build the new expression.
1478 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001479 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001480 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001481 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001482 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001483 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1484 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001485 RBracketLoc);
1486 }
1487
1488 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001489 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001490 /// By default, performs semantic analysis to build the new expression.
1491 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001492 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001494 SourceLocation RParenLoc,
1495 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001496 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001497 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001498 }
1499
1500 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001501 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001502 /// By default, performs semantic analysis to build the new expression.
1503 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001504 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001505 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001506 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001507 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001508 const DeclarationNameInfo &MemberNameInfo,
1509 ValueDecl *Member,
1510 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001511 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001512 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001513 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1514 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001515 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001516 // We have a reference to an unnamed field. This is always the
1517 // base of an anonymous struct/union member access, i.e. the
1518 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001519 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001520 assert(Member->getType()->isRecordType() &&
1521 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001522
Richard Smith9138b4e2011-10-26 19:06:56 +00001523 BaseResult =
1524 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001525 QualifierLoc.getNestedNameSpecifier(),
1526 FoundDecl, Member);
1527 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001528 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001529 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001530 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001531 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001532 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001533 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001534 cast<FieldDecl>(Member)->getType(),
1535 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001536 return getSema().Owned(ME);
1537 }
Mike Stump1eb44332009-09-09 15:08:12 +00001538
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001539 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001540 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001541
John Wiegley429bb272011-04-08 18:41:53 +00001542 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001543 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001544
John McCall6bb80172010-03-30 21:47:33 +00001545 // FIXME: this involves duplicating earlier analysis in a lot of
1546 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001547 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001548 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001549 R.resolveKind();
1550
John McCall9ae2f072010-08-23 23:25:46 +00001551 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001552 SS, TemplateKWLoc,
1553 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001554 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001555 }
Mike Stump1eb44332009-09-09 15:08:12 +00001556
Douglas Gregorb98b1992009-08-11 05:31:07 +00001557 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001558 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001559 /// By default, performs semantic analysis to build the new expression.
1560 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001561 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001562 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001563 Expr *LHS, Expr *RHS) {
1564 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001565 }
1566
1567 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001568 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001569 /// By default, performs semantic analysis to build the new expression.
1570 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001571 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001572 SourceLocation QuestionLoc,
1573 Expr *LHS,
1574 SourceLocation ColonLoc,
1575 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001576 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1577 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001578 }
1579
Douglas Gregorb98b1992009-08-11 05:31:07 +00001580 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001581 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001582 /// By default, performs semantic analysis to build the new expression.
1583 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001584 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001585 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001586 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001587 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001588 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001589 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001590 }
Mike Stump1eb44332009-09-09 15:08:12 +00001591
Douglas Gregorb98b1992009-08-11 05:31:07 +00001592 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001593 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001594 /// By default, performs semantic analysis to build the new expression.
1595 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001596 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001597 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001598 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001599 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001600 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001601 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 }
Mike Stump1eb44332009-09-09 15:08:12 +00001603
Douglas Gregorb98b1992009-08-11 05:31:07 +00001604 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001605 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001606 /// By default, performs semantic analysis to build the new expression.
1607 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001608 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001609 SourceLocation OpLoc,
1610 SourceLocation AccessorLoc,
1611 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001612
John McCall129e2df2009-11-30 22:42:35 +00001613 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001614 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001615 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001616 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001617 SS, SourceLocation(),
1618 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001619 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001620 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001621 }
Mike Stump1eb44332009-09-09 15:08:12 +00001622
Douglas Gregorb98b1992009-08-11 05:31:07 +00001623 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001624 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001625 /// By default, performs semantic analysis to build the new expression.
1626 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001627 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001628 MultiExprArg Inits,
1629 SourceLocation RBraceLoc,
1630 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001631 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001632 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001633 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001634 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001635
Douglas Gregore48319a2009-11-09 17:16:50 +00001636 // Patch in the result type we were given, which may have been computed
1637 // when the initial InitListExpr was built.
1638 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1639 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001640 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001641 }
Mike Stump1eb44332009-09-09 15:08:12 +00001642
Douglas Gregorb98b1992009-08-11 05:31:07 +00001643 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001644 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001645 /// By default, performs semantic analysis to build the new expression.
1646 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001647 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001648 MultiExprArg ArrayExprs,
1649 SourceLocation EqualOrColonLoc,
1650 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001651 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001652 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001654 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001655 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001656 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001657
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001658 return Result;
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 value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001662 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001663 /// By default, builds the implicit value initialization without performing
1664 /// any semantic analysis. Subclasses may override this routine to provide
1665 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001666 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001667 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1668 }
Mike Stump1eb44332009-09-09 15:08:12 +00001669
Douglas Gregorb98b1992009-08-11 05:31:07 +00001670 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001671 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001672 /// By default, performs semantic analysis to build the new expression.
1673 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001674 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001675 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001676 SourceLocation RParenLoc) {
1677 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001678 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001679 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001680 }
1681
1682 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001683 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001684 /// By default, performs semantic analysis to build the new expression.
1685 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001686 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001687 MultiExprArg SubExprs,
1688 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001689 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001690 }
Mike Stump1eb44332009-09-09 15:08:12 +00001691
Douglas Gregorb98b1992009-08-11 05:31:07 +00001692 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001693 ///
1694 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001695 /// rather than attempting to map the label statement itself.
1696 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001697 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001698 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001699 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001700 }
Mike Stump1eb44332009-09-09 15:08:12 +00001701
Douglas Gregorb98b1992009-08-11 05:31:07 +00001702 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001703 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001704 /// By default, performs semantic analysis to build the new expression.
1705 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001706 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001707 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001708 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001709 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 }
Mike Stump1eb44332009-09-09 15:08:12 +00001711
Douglas Gregorb98b1992009-08-11 05:31:07 +00001712 /// \brief Build a new __builtin_choose_expr expression.
1713 ///
1714 /// By default, performs semantic analysis to build the new expression.
1715 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001716 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001717 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 SourceLocation RParenLoc) {
1719 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001720 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001721 RParenLoc);
1722 }
Mike Stump1eb44332009-09-09 15:08:12 +00001723
Peter Collingbournef111d932011-04-15 00:35:48 +00001724 /// \brief Build a new generic selection expression.
1725 ///
1726 /// By default, performs semantic analysis to build the new expression.
1727 /// Subclasses may override this routine to provide different behavior.
1728 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1729 SourceLocation DefaultLoc,
1730 SourceLocation RParenLoc,
1731 Expr *ControllingExpr,
1732 TypeSourceInfo **Types,
1733 Expr **Exprs,
1734 unsigned NumAssocs) {
1735 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1736 ControllingExpr, Types, Exprs,
1737 NumAssocs);
1738 }
1739
Douglas Gregorb98b1992009-08-11 05:31:07 +00001740 /// \brief Build a new overloaded operator call expression.
1741 ///
1742 /// By default, performs semantic analysis to build the new expression.
1743 /// The semantic analysis provides the behavior of template instantiation,
1744 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001745 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001746 /// argument-dependent lookup, etc. Subclasses may override this routine to
1747 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001748 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001749 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001750 Expr *Callee,
1751 Expr *First,
1752 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001753
1754 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001755 /// reinterpret_cast.
1756 ///
1757 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001758 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001759 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001760 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001761 Stmt::StmtClass Class,
1762 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001763 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001764 SourceLocation RAngleLoc,
1765 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001766 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001767 SourceLocation RParenLoc) {
1768 switch (Class) {
1769 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001770 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001771 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001772 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001773
1774 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001775 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001776 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001777 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001778
Douglas Gregorb98b1992009-08-11 05:31:07 +00001779 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001780 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001781 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001782 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001783 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001784
Douglas Gregorb98b1992009-08-11 05:31:07 +00001785 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001786 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001787 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001788 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001789
Douglas Gregorb98b1992009-08-11 05:31:07 +00001790 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001791 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001792 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001793 }
Mike Stump1eb44332009-09-09 15:08:12 +00001794
Douglas Gregorb98b1992009-08-11 05:31:07 +00001795 /// \brief Build a new C++ static_cast expression.
1796 ///
1797 /// By default, performs semantic analysis to build the new expression.
1798 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001799 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001800 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001801 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001802 SourceLocation RAngleLoc,
1803 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001804 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001805 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001806 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001807 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001808 SourceRange(LAngleLoc, RAngleLoc),
1809 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001810 }
1811
1812 /// \brief Build a new C++ dynamic_cast expression.
1813 ///
1814 /// By default, performs semantic analysis to build the new expression.
1815 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001816 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001817 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001818 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001819 SourceLocation RAngleLoc,
1820 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001821 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001822 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001823 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001824 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001825 SourceRange(LAngleLoc, RAngleLoc),
1826 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001827 }
1828
1829 /// \brief Build a new C++ reinterpret_cast expression.
1830 ///
1831 /// By default, performs semantic analysis to build the new expression.
1832 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001833 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001834 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001835 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001836 SourceLocation RAngleLoc,
1837 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001838 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001839 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001840 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001841 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001842 SourceRange(LAngleLoc, RAngleLoc),
1843 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001844 }
1845
1846 /// \brief Build a new C++ const_cast expression.
1847 ///
1848 /// By default, performs semantic analysis to build the new expression.
1849 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001850 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001851 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001852 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001853 SourceLocation RAngleLoc,
1854 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001855 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001856 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001857 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001858 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001859 SourceRange(LAngleLoc, RAngleLoc),
1860 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001861 }
Mike Stump1eb44332009-09-09 15:08:12 +00001862
Douglas Gregorb98b1992009-08-11 05:31:07 +00001863 /// \brief Build a new C++ functional-style cast expression.
1864 ///
1865 /// By default, performs semantic analysis to build the new expression.
1866 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001867 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1868 SourceLocation LParenLoc,
1869 Expr *Sub,
1870 SourceLocation RParenLoc) {
1871 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001872 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001873 RParenLoc);
1874 }
Mike Stump1eb44332009-09-09 15:08:12 +00001875
Douglas Gregorb98b1992009-08-11 05:31:07 +00001876 /// \brief Build a new C++ typeid(type) expression.
1877 ///
1878 /// By default, performs semantic analysis to build the new expression.
1879 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001880 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001881 SourceLocation TypeidLoc,
1882 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001883 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001884 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001885 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001886 }
Mike Stump1eb44332009-09-09 15:08:12 +00001887
Francois Pichet01b7c302010-09-08 12:20:18 +00001888
Douglas Gregorb98b1992009-08-11 05:31:07 +00001889 /// \brief Build a new C++ typeid(expr) expression.
1890 ///
1891 /// By default, performs semantic analysis to build the new expression.
1892 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001893 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001894 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001895 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001896 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001897 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001898 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001899 }
1900
Francois Pichet01b7c302010-09-08 12:20:18 +00001901 /// \brief Build a new C++ __uuidof(type) expression.
1902 ///
1903 /// By default, performs semantic analysis to build the new expression.
1904 /// Subclasses may override this routine to provide different behavior.
1905 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1906 SourceLocation TypeidLoc,
1907 TypeSourceInfo *Operand,
1908 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001909 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00001910 RParenLoc);
1911 }
1912
1913 /// \brief Build a new C++ __uuidof(expr) expression.
1914 ///
1915 /// By default, performs semantic analysis to build the new expression.
1916 /// Subclasses may override this routine to provide different behavior.
1917 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1918 SourceLocation TypeidLoc,
1919 Expr *Operand,
1920 SourceLocation RParenLoc) {
1921 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1922 RParenLoc);
1923 }
1924
Douglas Gregorb98b1992009-08-11 05:31:07 +00001925 /// \brief Build a new C++ "this" expression.
1926 ///
1927 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001928 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001929 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001930 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001931 QualType ThisType,
1932 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001933 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001934 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001935 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1936 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001937 }
1938
1939 /// \brief Build a new C++ throw expression.
1940 ///
1941 /// By default, performs semantic analysis to build the new expression.
1942 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001943 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1944 bool IsThrownVariableInScope) {
1945 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001946 }
1947
1948 /// \brief Build a new C++ default-argument expression.
1949 ///
1950 /// By default, builds a new default-argument expression, which does not
1951 /// require any semantic analysis. Subclasses may override this routine to
1952 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001953 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001954 ParmVarDecl *Param) {
1955 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1956 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001957 }
1958
1959 /// \brief Build a new C++ zero-initialization expression.
1960 ///
1961 /// By default, performs semantic analysis to build the new expression.
1962 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001963 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1964 SourceLocation LParenLoc,
1965 SourceLocation RParenLoc) {
1966 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Benjamin Kramer5354e772012-08-23 23:38:35 +00001967 MultiExprArg(), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001968 }
Mike Stump1eb44332009-09-09 15:08:12 +00001969
Douglas Gregorb98b1992009-08-11 05:31:07 +00001970 /// \brief Build a new C++ "new" expression.
1971 ///
1972 /// By default, performs semantic analysis to build the new expression.
1973 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001974 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001975 bool UseGlobal,
1976 SourceLocation PlacementLParen,
1977 MultiExprArg PlacementArgs,
1978 SourceLocation PlacementRParen,
1979 SourceRange TypeIdParens,
1980 QualType AllocatedType,
1981 TypeSourceInfo *AllocatedTypeInfo,
1982 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001983 SourceRange DirectInitRange,
1984 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00001985 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001986 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001987 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001988 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001989 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001990 AllocatedType,
1991 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001992 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001993 DirectInitRange,
1994 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001995 }
Mike Stump1eb44332009-09-09 15:08:12 +00001996
Douglas Gregorb98b1992009-08-11 05:31:07 +00001997 /// \brief Build a new C++ "delete" expression.
1998 ///
1999 /// By default, performs semantic analysis to build the new expression.
2000 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002001 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002002 bool IsGlobalDelete,
2003 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002004 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002005 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002006 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002007 }
Mike Stump1eb44332009-09-09 15:08:12 +00002008
Douglas Gregorb98b1992009-08-11 05:31:07 +00002009 /// \brief Build a new unary type trait expression.
2010 ///
2011 /// By default, performs semantic analysis to build the new expression.
2012 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002013 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002014 SourceLocation StartLoc,
2015 TypeSourceInfo *T,
2016 SourceLocation RParenLoc) {
2017 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002018 }
2019
Francois Pichet6ad6f282010-12-07 00:08:36 +00002020 /// \brief Build a new binary type trait expression.
2021 ///
2022 /// By default, performs semantic analysis to build the new expression.
2023 /// Subclasses may override this routine to provide different behavior.
2024 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2025 SourceLocation StartLoc,
2026 TypeSourceInfo *LhsT,
2027 TypeSourceInfo *RhsT,
2028 SourceLocation RParenLoc) {
2029 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2030 }
2031
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002032 /// \brief Build a new type trait expression.
2033 ///
2034 /// By default, performs semantic analysis to build the new expression.
2035 /// Subclasses may override this routine to provide different behavior.
2036 ExprResult RebuildTypeTrait(TypeTrait Trait,
2037 SourceLocation StartLoc,
2038 ArrayRef<TypeSourceInfo *> Args,
2039 SourceLocation RParenLoc) {
2040 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2041 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002042
John Wiegley21ff2e52011-04-28 00:16:57 +00002043 /// \brief Build a new array type trait expression.
2044 ///
2045 /// By default, performs semantic analysis to build the new expression.
2046 /// Subclasses may override this routine to provide different behavior.
2047 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2048 SourceLocation StartLoc,
2049 TypeSourceInfo *TSInfo,
2050 Expr *DimExpr,
2051 SourceLocation RParenLoc) {
2052 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2053 }
2054
John Wiegley55262202011-04-25 06:54:41 +00002055 /// \brief Build a new expression trait expression.
2056 ///
2057 /// By default, performs semantic analysis to build the new expression.
2058 /// Subclasses may override this routine to provide different behavior.
2059 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2060 SourceLocation StartLoc,
2061 Expr *Queried,
2062 SourceLocation RParenLoc) {
2063 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2064 }
2065
Mike Stump1eb44332009-09-09 15:08:12 +00002066 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002067 /// expression.
2068 ///
2069 /// By default, performs semantic analysis to build the new expression.
2070 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002071 ExprResult RebuildDependentScopeDeclRefExpr(
2072 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002073 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002074 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002075 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002076 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002077 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002078
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002079 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002080 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002081 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002082
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002083 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002084 }
2085
2086 /// \brief Build a new template-id expression.
2087 ///
2088 /// By default, performs semantic analysis to build the new expression.
2089 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002090 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002091 SourceLocation TemplateKWLoc,
2092 LookupResult &R,
2093 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002094 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002095 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2096 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002097 }
2098
2099 /// \brief Build a new object-construction expression.
2100 ///
2101 /// By default, performs semantic analysis to build the new expression.
2102 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002103 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002104 SourceLocation Loc,
2105 CXXConstructorDecl *Constructor,
2106 bool IsElidable,
2107 MultiExprArg Args,
2108 bool HadMultipleCandidates,
2109 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002110 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002111 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002112 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002113 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002114 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002115 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002116
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002117 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002118 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002119 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002120 RequiresZeroInit, ConstructKind,
2121 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002122 }
2123
2124 /// \brief Build a new object-construction expression.
2125 ///
2126 /// By default, performs semantic analysis to build the new expression.
2127 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002128 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2129 SourceLocation LParenLoc,
2130 MultiExprArg Args,
2131 SourceLocation RParenLoc) {
2132 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002133 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002134 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002135 RParenLoc);
2136 }
2137
2138 /// \brief Build a new object-construction expression.
2139 ///
2140 /// By default, performs semantic analysis to build the new expression.
2141 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002142 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2143 SourceLocation LParenLoc,
2144 MultiExprArg Args,
2145 SourceLocation RParenLoc) {
2146 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002147 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002148 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002149 RParenLoc);
2150 }
Mike Stump1eb44332009-09-09 15:08:12 +00002151
Douglas Gregorb98b1992009-08-11 05:31:07 +00002152 /// \brief Build a new member reference expression.
2153 ///
2154 /// By default, performs semantic analysis to build the new expression.
2155 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002156 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002157 QualType BaseType,
2158 bool IsArrow,
2159 SourceLocation OperatorLoc,
2160 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002161 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002162 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002163 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002164 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002165 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002166 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002167
John McCall9ae2f072010-08-23 23:25:46 +00002168 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002169 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002170 SS, TemplateKWLoc,
2171 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002172 MemberNameInfo,
2173 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002174 }
2175
John McCall129e2df2009-11-30 22:42:35 +00002176 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002177 ///
2178 /// By default, performs semantic analysis to build the new expression.
2179 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002180 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2181 SourceLocation OperatorLoc,
2182 bool IsArrow,
2183 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002184 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002185 NamedDecl *FirstQualifierInScope,
2186 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002187 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002188 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002189 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002190
John McCall9ae2f072010-08-23 23:25:46 +00002191 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002192 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002193 SS, TemplateKWLoc,
2194 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002195 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002196 }
Mike Stump1eb44332009-09-09 15:08:12 +00002197
Sebastian Redl2e156222010-09-10 20:55:43 +00002198 /// \brief Build a new noexcept expression.
2199 ///
2200 /// By default, performs semantic analysis to build the new expression.
2201 /// Subclasses may override this routine to provide different behavior.
2202 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2203 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2204 }
2205
Douglas Gregoree8aff02011-01-04 17:33:58 +00002206 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002207 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2208 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002209 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002210 llvm::Optional<unsigned> Length) {
2211 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002212 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2213 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002214 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002215
2216 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2217 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002218 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002219 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002220
Patrick Beardeb382ec2012-04-19 00:25:12 +00002221 /// \brief Build a new Objective-C boxed expression.
2222 ///
2223 /// By default, performs semantic analysis to build the new expression.
2224 /// Subclasses may override this routine to provide different behavior.
2225 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2226 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2227 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002228
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002229 /// \brief Build a new Objective-C array literal.
2230 ///
2231 /// By default, performs semantic analysis to build the new expression.
2232 /// Subclasses may override this routine to provide different behavior.
2233 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2234 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002235 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002236 MultiExprArg(Elements, NumElements));
2237 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002238
2239 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002240 Expr *Base, Expr *Key,
2241 ObjCMethodDecl *getterMethod,
2242 ObjCMethodDecl *setterMethod) {
2243 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2244 getterMethod, setterMethod);
2245 }
2246
2247 /// \brief Build a new Objective-C dictionary literal.
2248 ///
2249 /// By default, performs semantic analysis to build the new expression.
2250 /// Subclasses may override this routine to provide different behavior.
2251 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2252 ObjCDictionaryElement *Elements,
2253 unsigned NumElements) {
2254 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2255 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002256
James Dennett699c9042012-06-15 07:13:21 +00002257 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002258 ///
2259 /// By default, performs semantic analysis to build the new expression.
2260 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002261 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002262 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002263 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002264 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002265 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002266 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002267
Douglas Gregor92e986e2010-04-22 16:44:27 +00002268 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002269 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002270 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002271 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002272 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002273 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002274 MultiExprArg Args,
2275 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002276 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2277 ReceiverTypeInfo->getType(),
2278 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002279 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002280 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002281 }
2282
2283 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002284 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002285 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002286 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002287 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002288 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002289 MultiExprArg Args,
2290 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002291 return SemaRef.BuildInstanceMessage(Receiver,
2292 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002293 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002294 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002295 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002296 }
2297
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002298 /// \brief Build a new Objective-C ivar reference expression.
2299 ///
2300 /// By default, performs semantic analysis to build the new expression.
2301 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002302 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002303 SourceLocation IvarLoc,
2304 bool IsArrow, bool IsFreeIvar) {
2305 // FIXME: We lose track of the IsFreeIvar bit.
2306 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002307 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002308 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2309 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002310 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002311 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002312 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002313 false);
John Wiegley429bb272011-04-08 18:41:53 +00002314 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002315 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002316
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002317 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002318 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002319
John Wiegley429bb272011-04-08 18:41:53 +00002320 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002321 /*FIXME:*/IvarLoc, IsArrow,
2322 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002323 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002324 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002325 /*TemplateArgs=*/0);
2326 }
Douglas Gregore3303542010-04-26 20:47:02 +00002327
2328 /// \brief Build a new Objective-C property reference expression.
2329 ///
2330 /// By default, performs semantic analysis to build the new expression.
2331 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002332 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002333 ObjCPropertyDecl *Property,
2334 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002335 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002336 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002337 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2338 Sema::LookupMemberName);
2339 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002340 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002341 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002342 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002343 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002344 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002345
Douglas Gregore3303542010-04-26 20:47:02 +00002346 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002347 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002348
John Wiegley429bb272011-04-08 18:41:53 +00002349 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002350 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002351 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002352 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002353 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002354 /*TemplateArgs=*/0);
2355 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002356
John McCall12f78a62010-12-02 01:19:52 +00002357 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002358 ///
2359 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002360 /// Subclasses may override this routine to provide different behavior.
2361 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2362 ObjCMethodDecl *Getter,
2363 ObjCMethodDecl *Setter,
2364 SourceLocation PropertyLoc) {
2365 // Since these expressions can only be value-dependent, we do not
2366 // need to perform semantic analysis again.
2367 return Owned(
2368 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2369 VK_LValue, OK_ObjCProperty,
2370 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002371 }
2372
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002373 /// \brief Build a new Objective-C "isa" expression.
2374 ///
2375 /// By default, performs semantic analysis to build the new expression.
2376 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002377 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002378 bool IsArrow) {
2379 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002380 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002381 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2382 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002383 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002384 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002385 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002386 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002387 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002388
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002389 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002390 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002391
John Wiegley429bb272011-04-08 18:41:53 +00002392 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002393 /*FIXME:*/IsaLoc, IsArrow,
2394 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002395 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002396 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002397 /*TemplateArgs=*/0);
2398 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002399
Douglas Gregorb98b1992009-08-11 05:31:07 +00002400 /// \brief Build a new shuffle vector expression.
2401 ///
2402 /// By default, performs semantic analysis to build the new expression.
2403 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002404 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002405 MultiExprArg SubExprs,
2406 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002407 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002408 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002409 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2410 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2411 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2412 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002413
Douglas Gregorb98b1992009-08-11 05:31:07 +00002414 // Build a reference to the __builtin_shufflevector builtin
2415 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002416 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2417 SemaRef.Context.BuiltinFnTy,
2418 VK_RValue, BuiltinLoc);
2419 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2420 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2421 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002422
2423 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002424 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002425 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002426 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002427 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002428 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002429
Douglas Gregorb98b1992009-08-11 05:31:07 +00002430 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002431 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002432 }
John McCall43fed0d2010-11-12 08:19:04 +00002433
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002434 /// \brief Build a new template argument pack expansion.
2435 ///
2436 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002437 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002438 /// different behavior.
2439 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002440 SourceLocation EllipsisLoc,
2441 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002442 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002443 case TemplateArgument::Expression: {
2444 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002445 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2446 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002447 if (Result.isInvalid())
2448 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002449
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002450 return TemplateArgumentLoc(Result.get(), Result.get());
2451 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002452
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002453 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002454 return TemplateArgumentLoc(TemplateArgument(
2455 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002456 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002457 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002458 Pattern.getTemplateNameLoc(),
2459 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002460
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002461 case TemplateArgument::Null:
2462 case TemplateArgument::Integral:
2463 case TemplateArgument::Declaration:
2464 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002465 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002466 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002467
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002468 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002469 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002470 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002471 EllipsisLoc,
2472 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002473 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2474 Expansion);
2475 break;
2476 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002477
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002478 return TemplateArgumentLoc();
2479 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002480
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002481 /// \brief Build a new expression pack expansion.
2482 ///
2483 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002484 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002485 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002486 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2487 llvm::Optional<unsigned> NumExpansions) {
2488 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002489 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002490
2491 /// \brief Build a new atomic operation expression.
2492 ///
2493 /// By default, performs semantic analysis to build the new expression.
2494 /// Subclasses may override this routine to provide different behavior.
2495 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2496 MultiExprArg SubExprs,
2497 QualType RetTy,
2498 AtomicExpr::AtomicOp Op,
2499 SourceLocation RParenLoc) {
2500 // Just create the expression; there is not any interesting semantic
2501 // analysis here because we can't actually build an AtomicExpr until
2502 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002503 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002504 RParenLoc);
2505 }
2506
John McCall43fed0d2010-11-12 08:19:04 +00002507private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002508 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2509 QualType ObjectType,
2510 NamedDecl *FirstQualifierInScope,
2511 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002512
2513 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2514 QualType ObjectType,
2515 NamedDecl *FirstQualifierInScope,
2516 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002517};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002518
Douglas Gregor43959a92009-08-20 07:17:43 +00002519template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002520StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002521 if (!S)
2522 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002523
Douglas Gregor43959a92009-08-20 07:17:43 +00002524 switch (S->getStmtClass()) {
2525 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002526
Douglas Gregor43959a92009-08-20 07:17:43 +00002527 // Transform individual statement nodes
2528#define STMT(Node, Parent) \
2529 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002530#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002531#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002532#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002533
Douglas Gregor43959a92009-08-20 07:17:43 +00002534 // Transform expressions by calling TransformExpr.
2535#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002536#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002537#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002538#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002539 {
John McCall60d7b3a2010-08-24 06:29:42 +00002540 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002541 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002542 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002543
John McCall9ae2f072010-08-23 23:25:46 +00002544 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002545 }
Mike Stump1eb44332009-09-09 15:08:12 +00002546 }
2547
John McCall3fa5cae2010-10-26 07:05:15 +00002548 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002549}
Mike Stump1eb44332009-09-09 15:08:12 +00002550
2551
Douglas Gregor670444e2009-08-04 22:27:00 +00002552template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002553ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002554 if (!E)
2555 return SemaRef.Owned(E);
2556
2557 switch (E->getStmtClass()) {
2558 case Stmt::NoStmtClass: break;
2559#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002560#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002561#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002562 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002563#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002564 }
2565
John McCall3fa5cae2010-10-26 07:05:15 +00002566 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002567}
2568
2569template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002570bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2571 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002572 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002573 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002574 bool *ArgChanged) {
2575 for (unsigned I = 0; I != NumInputs; ++I) {
2576 // If requested, drop call arguments that need to be dropped.
2577 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2578 if (ArgChanged)
2579 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002580
Douglas Gregoraa165f82011-01-03 19:04:46 +00002581 break;
2582 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002583
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002584 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2585 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002586
Chris Lattner686775d2011-07-20 06:58:45 +00002587 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002588 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2589 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002590
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002591 // Determine whether the set of unexpanded parameter packs can and should
2592 // be expanded.
2593 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002594 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002595 llvm::Optional<unsigned> OrigNumExpansions
2596 = Expansion->getNumExpansions();
2597 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002598 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2599 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002600 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002601 Expand, RetainExpansion,
2602 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002603 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002604
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002605 if (!Expand) {
2606 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002607 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002608 // expansion.
2609 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2610 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2611 if (OutPattern.isInvalid())
2612 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002613
2614 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002615 Expansion->getEllipsisLoc(),
2616 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002617 if (Out.isInvalid())
2618 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002619
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002620 if (ArgChanged)
2621 *ArgChanged = true;
2622 Outputs.push_back(Out.get());
2623 continue;
2624 }
John McCallc8fc90a2011-07-06 07:30:07 +00002625
2626 // Record right away that the argument was changed. This needs
2627 // to happen even if the array expands to nothing.
2628 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002629
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002630 // The transform has determined that we should perform an elementwise
2631 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002632 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002633 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2634 ExprResult Out = getDerived().TransformExpr(Pattern);
2635 if (Out.isInvalid())
2636 return true;
2637
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002638 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002639 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2640 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002641 if (Out.isInvalid())
2642 return true;
2643 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002644
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002645 Outputs.push_back(Out.get());
2646 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002647
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002648 continue;
2649 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002650
Douglas Gregoraa165f82011-01-03 19:04:46 +00002651 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2652 if (Result.isInvalid())
2653 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002654
Douglas Gregoraa165f82011-01-03 19:04:46 +00002655 if (Result.get() != Inputs[I] && ArgChanged)
2656 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002657
2658 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002659 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002660
Douglas Gregoraa165f82011-01-03 19:04:46 +00002661 return false;
2662}
2663
2664template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002665NestedNameSpecifierLoc
2666TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2667 NestedNameSpecifierLoc NNS,
2668 QualType ObjectType,
2669 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002670 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002671 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002672 Qualifier = Qualifier.getPrefix())
2673 Qualifiers.push_back(Qualifier);
2674
2675 CXXScopeSpec SS;
2676 while (!Qualifiers.empty()) {
2677 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2678 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002679
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002680 switch (QNNS->getKind()) {
2681 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002682 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002683 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002684 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002685 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002686 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002687 FirstQualifierInScope, false))
2688 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002689
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002690 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002691
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002692 case NestedNameSpecifier::Namespace: {
2693 NamespaceDecl *NS
2694 = cast_or_null<NamespaceDecl>(
2695 getDerived().TransformDecl(
2696 Q.getLocalBeginLoc(),
2697 QNNS->getAsNamespace()));
2698 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2699 break;
2700 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002701
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002702 case NestedNameSpecifier::NamespaceAlias: {
2703 NamespaceAliasDecl *Alias
2704 = cast_or_null<NamespaceAliasDecl>(
2705 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2706 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002707 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002708 Q.getLocalEndLoc());
2709 break;
2710 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002711
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002712 case NestedNameSpecifier::Global:
2713 // There is no meaningful transformation that one could perform on the
2714 // global scope.
2715 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2716 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002717
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002718 case NestedNameSpecifier::TypeSpecWithTemplate:
2719 case NestedNameSpecifier::TypeSpec: {
2720 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2721 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002722
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002723 if (!TL)
2724 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002725
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002726 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00002727 (SemaRef.getLangOpts().CPlusPlus0x &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002728 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002729 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002730 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002731 if (TL.getType()->isEnumeralType())
2732 SemaRef.Diag(TL.getBeginLoc(),
2733 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002734 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2735 Q.getLocalEndLoc());
2736 break;
2737 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002738 // If the nested-name-specifier is an invalid type def, don't emit an
2739 // error because a previous error should have already been emitted.
2740 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2741 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002742 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002743 << TL.getType() << SS.getRange();
2744 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002745 return NestedNameSpecifierLoc();
2746 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002747 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002748
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002749 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002750 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002751 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002752 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002753
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002754 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002755 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002756 !getDerived().AlwaysRebuild())
2757 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002758
2759 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002760 // nested-name-specifier, do so.
2761 if (SS.location_size() == NNS.getDataLength() &&
2762 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2763 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2764
2765 // Allocate new nested-name-specifier location information.
2766 return SS.getWithLocInContext(SemaRef.Context);
2767}
2768
2769template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002770DeclarationNameInfo
2771TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002772::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002773 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002774 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002775 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002776
2777 switch (Name.getNameKind()) {
2778 case DeclarationName::Identifier:
2779 case DeclarationName::ObjCZeroArgSelector:
2780 case DeclarationName::ObjCOneArgSelector:
2781 case DeclarationName::ObjCMultiArgSelector:
2782 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002783 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002784 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002785 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002786
Douglas Gregor81499bb2009-09-03 22:13:48 +00002787 case DeclarationName::CXXConstructorName:
2788 case DeclarationName::CXXDestructorName:
2789 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002790 TypeSourceInfo *NewTInfo;
2791 CanQualType NewCanTy;
2792 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002793 NewTInfo = getDerived().TransformType(OldTInfo);
2794 if (!NewTInfo)
2795 return DeclarationNameInfo();
2796 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002797 }
2798 else {
2799 NewTInfo = 0;
2800 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002801 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002802 if (NewT.isNull())
2803 return DeclarationNameInfo();
2804 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2805 }
Mike Stump1eb44332009-09-09 15:08:12 +00002806
Abramo Bagnara25777432010-08-11 22:01:17 +00002807 DeclarationName NewName
2808 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2809 NewCanTy);
2810 DeclarationNameInfo NewNameInfo(NameInfo);
2811 NewNameInfo.setName(NewName);
2812 NewNameInfo.setNamedTypeInfo(NewTInfo);
2813 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002814 }
Mike Stump1eb44332009-09-09 15:08:12 +00002815 }
2816
David Blaikieb219cfc2011-09-23 05:06:16 +00002817 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002818}
2819
2820template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002821TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002822TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2823 TemplateName Name,
2824 SourceLocation NameLoc,
2825 QualType ObjectType,
2826 NamedDecl *FirstQualifierInScope) {
2827 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2828 TemplateDecl *Template = QTN->getTemplateDecl();
2829 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002830
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002831 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002832 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002833 Template));
2834 if (!TransTemplate)
2835 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002836
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002837 if (!getDerived().AlwaysRebuild() &&
2838 SS.getScopeRep() == QTN->getQualifier() &&
2839 TransTemplate == Template)
2840 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002841
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002842 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2843 TransTemplate);
2844 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002845
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002846 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2847 if (SS.getScopeRep()) {
2848 // These apply to the scope specifier, not the template.
2849 ObjectType = QualType();
2850 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002851 }
2852
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002853 if (!getDerived().AlwaysRebuild() &&
2854 SS.getScopeRep() == DTN->getQualifier() &&
2855 ObjectType.isNull())
2856 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002857
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002858 if (DTN->isIdentifier()) {
2859 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002860 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002861 NameLoc,
2862 ObjectType,
2863 FirstQualifierInScope);
2864 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002865
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002866 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2867 ObjectType);
2868 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002869
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002870 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2871 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002872 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002873 Template));
2874 if (!TransTemplate)
2875 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002876
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002877 if (!getDerived().AlwaysRebuild() &&
2878 TransTemplate == Template)
2879 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002880
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002881 return TemplateName(TransTemplate);
2882 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002883
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002884 if (SubstTemplateTemplateParmPackStorage *SubstPack
2885 = Name.getAsSubstTemplateTemplateParmPack()) {
2886 TemplateTemplateParmDecl *TransParam
2887 = cast_or_null<TemplateTemplateParmDecl>(
2888 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2889 if (!TransParam)
2890 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002891
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002892 if (!getDerived().AlwaysRebuild() &&
2893 TransParam == SubstPack->getParameterPack())
2894 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002895
2896 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002897 SubstPack->getArgumentPack());
2898 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002899
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002900 // These should be getting filtered out before they reach the AST.
2901 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002902}
2903
2904template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002905void TreeTransform<Derived>::InventTemplateArgumentLoc(
2906 const TemplateArgument &Arg,
2907 TemplateArgumentLoc &Output) {
2908 SourceLocation Loc = getDerived().getBaseLocation();
2909 switch (Arg.getKind()) {
2910 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002911 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002912 break;
2913
2914 case TemplateArgument::Type:
2915 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002916 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002917
John McCall833ca992009-10-29 08:12:44 +00002918 break;
2919
Douglas Gregor788cd062009-11-11 01:00:40 +00002920 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002921 case TemplateArgument::TemplateExpansion: {
2922 NestedNameSpecifierLocBuilder Builder;
2923 TemplateName Template = Arg.getAsTemplate();
2924 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2925 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2926 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2927 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002928
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002929 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002930 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002931 Builder.getWithLocInContext(SemaRef.Context),
2932 Loc);
2933 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00002934 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002935 Builder.getWithLocInContext(SemaRef.Context),
2936 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002937
Douglas Gregor788cd062009-11-11 01:00:40 +00002938 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002939 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002940
John McCall833ca992009-10-29 08:12:44 +00002941 case TemplateArgument::Expression:
2942 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2943 break;
2944
2945 case TemplateArgument::Declaration:
2946 case TemplateArgument::Integral:
2947 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002948 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002949 break;
2950 }
2951}
2952
2953template<typename Derived>
2954bool TreeTransform<Derived>::TransformTemplateArgument(
2955 const TemplateArgumentLoc &Input,
2956 TemplateArgumentLoc &Output) {
2957 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002958 switch (Arg.getKind()) {
2959 case TemplateArgument::Null:
2960 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002961 Output = Input;
2962 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002963
Douglas Gregor670444e2009-08-04 22:27:00 +00002964 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002965 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002966 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002967 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002968
2969 DI = getDerived().TransformType(DI);
2970 if (!DI) return true;
2971
2972 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2973 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002974 }
Mike Stump1eb44332009-09-09 15:08:12 +00002975
Douglas Gregor670444e2009-08-04 22:27:00 +00002976 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002977 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002978 DeclarationName Name;
2979 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2980 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002981 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002982 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002983 if (!D) return true;
2984
John McCall828bff22009-10-29 18:45:58 +00002985 Expr *SourceExpr = Input.getSourceDeclExpression();
2986 if (SourceExpr) {
2987 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00002988 Sema::ConstantEvaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002989 ExprResult E = getDerived().TransformExpr(SourceExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00002990 E = SemaRef.ActOnConstantExpression(E);
John McCall9ae2f072010-08-23 23:25:46 +00002991 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002992 }
2993
2994 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002995 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002996 }
Mike Stump1eb44332009-09-09 15:08:12 +00002997
Douglas Gregor788cd062009-11-11 01:00:40 +00002998 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002999 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3000 if (QualifierLoc) {
3001 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3002 if (!QualifierLoc)
3003 return true;
3004 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003005
Douglas Gregor1d752d72011-03-02 18:46:51 +00003006 CXXScopeSpec SS;
3007 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003008 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003009 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3010 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003011 if (Template.isNull())
3012 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003013
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003014 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003015 Input.getTemplateNameLoc());
3016 return false;
3017 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003018
3019 case TemplateArgument::TemplateExpansion:
3020 llvm_unreachable("Caller should expand pack expansions");
3021
Douglas Gregor670444e2009-08-04 22:27:00 +00003022 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003023 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003024 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003025 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003026
John McCall833ca992009-10-29 08:12:44 +00003027 Expr *InputExpr = Input.getSourceExpression();
3028 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3029
Chris Lattner223de242011-04-25 20:37:58 +00003030 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003031 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003032 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003033 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003034 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003035 }
Mike Stump1eb44332009-09-09 15:08:12 +00003036
Douglas Gregor670444e2009-08-04 22:27:00 +00003037 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00003038 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00003039 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00003040 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00003041 AEnd = Arg.pack_end();
3042 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00003043
John McCall833ca992009-10-29 08:12:44 +00003044 // FIXME: preserve source information here when we start
3045 // caring about parameter packs.
3046
John McCall828bff22009-10-29 18:45:58 +00003047 TemplateArgumentLoc InputArg;
3048 TemplateArgumentLoc OutputArg;
3049 getDerived().InventTemplateArgumentLoc(*A, InputArg);
3050 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00003051 return true;
3052
John McCall828bff22009-10-29 18:45:58 +00003053 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00003054 }
Douglas Gregor910f8002010-11-07 23:05:16 +00003055
3056 TemplateArgument *TransformedArgsPtr
3057 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
3058 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
3059 TransformedArgsPtr);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003060 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
3061 TransformedArgs.size()),
Douglas Gregor910f8002010-11-07 23:05:16 +00003062 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003063 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003064 }
3065 }
Mike Stump1eb44332009-09-09 15:08:12 +00003066
Douglas Gregor670444e2009-08-04 22:27:00 +00003067 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003068 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003069}
3070
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003071/// \brief Iterator adaptor that invents template argument location information
3072/// for each of the template arguments in its underlying iterator.
3073template<typename Derived, typename InputIterator>
3074class TemplateArgumentLocInventIterator {
3075 TreeTransform<Derived> &Self;
3076 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003077
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003078public:
3079 typedef TemplateArgumentLoc value_type;
3080 typedef TemplateArgumentLoc reference;
3081 typedef typename std::iterator_traits<InputIterator>::difference_type
3082 difference_type;
3083 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003084
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003085 class pointer {
3086 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003087
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003088 public:
3089 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003090
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003091 const TemplateArgumentLoc *operator->() const { return &Arg; }
3092 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003093
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003094 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003095
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003096 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3097 InputIterator Iter)
3098 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003099
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003100 TemplateArgumentLocInventIterator &operator++() {
3101 ++Iter;
3102 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003103 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003104
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003105 TemplateArgumentLocInventIterator operator++(int) {
3106 TemplateArgumentLocInventIterator Old(*this);
3107 ++(*this);
3108 return Old;
3109 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003110
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003111 reference operator*() const {
3112 TemplateArgumentLoc Result;
3113 Self.InventTemplateArgumentLoc(*Iter, Result);
3114 return Result;
3115 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003116
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003117 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003118
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003119 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3120 const TemplateArgumentLocInventIterator &Y) {
3121 return X.Iter == Y.Iter;
3122 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003123
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003124 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3125 const TemplateArgumentLocInventIterator &Y) {
3126 return X.Iter != Y.Iter;
3127 }
3128};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003129
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003130template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003131template<typename InputIterator>
3132bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3133 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003134 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003135 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003136 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003137 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003138
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003139 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3140 // Unpack argument packs, which we translate them into separate
3141 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003142 // FIXME: We could do much better if we could guarantee that the
3143 // TemplateArgumentLocInfo for the pack expansion would be usable for
3144 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003145 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003146 TemplateArgument::pack_iterator>
3147 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003148 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003149 In.getArgument().pack_begin()),
3150 PackLocIterator(*this,
3151 In.getArgument().pack_end()),
3152 Outputs))
3153 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003154
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003155 continue;
3156 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003157
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003158 if (In.getArgument().isPackExpansion()) {
3159 // We have a pack expansion, for which we will be substituting into
3160 // the pattern.
3161 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003162 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003163 TemplateArgumentLoc Pattern
Chad Rosier4a9d7952012-08-08 18:46:20 +00003164 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
Douglas Gregorcded4f62011-01-14 17:04:44 +00003165 getSema().Context);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003166
Chris Lattner686775d2011-07-20 06:58:45 +00003167 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003168 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3169 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003170
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003171 // Determine whether the set of unexpanded parameter packs can and should
3172 // be expanded.
3173 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003174 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003175 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003176 if (getDerived().TryExpandParameterPacks(Ellipsis,
3177 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003178 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003179 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003180 RetainExpansion,
3181 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003182 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003183
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003184 if (!Expand) {
3185 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003186 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003187 // expansion.
3188 TemplateArgumentLoc OutPattern;
3189 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3190 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3191 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003192
Douglas Gregorcded4f62011-01-14 17:04:44 +00003193 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3194 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003195 if (Out.getArgument().isNull())
3196 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003197
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003198 Outputs.addArgument(Out);
3199 continue;
3200 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003201
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003202 // The transform has determined that we should perform an elementwise
3203 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003204 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003205 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3206
3207 if (getDerived().TransformTemplateArgument(Pattern, Out))
3208 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003209
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003210 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003211 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3212 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003213 if (Out.getArgument().isNull())
3214 return true;
3215 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003216
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003217 Outputs.addArgument(Out);
3218 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003219
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003220 // If we're supposed to retain a pack expansion, do so by temporarily
3221 // forgetting the partially-substituted parameter pack.
3222 if (RetainExpansion) {
3223 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003224
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003225 if (getDerived().TransformTemplateArgument(Pattern, Out))
3226 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003227
Douglas Gregorcded4f62011-01-14 17:04:44 +00003228 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3229 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003230 if (Out.getArgument().isNull())
3231 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003232
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003233 Outputs.addArgument(Out);
3234 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003235
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003236 continue;
3237 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003238
3239 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003240 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003241 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003242
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003243 Outputs.addArgument(Out);
3244 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003245
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003246 return false;
3247
3248}
3249
Douglas Gregor577f75a2009-08-04 16:50:30 +00003250//===----------------------------------------------------------------------===//
3251// Type transformation
3252//===----------------------------------------------------------------------===//
3253
3254template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003255QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003256 if (getDerived().AlreadyTransformed(T))
3257 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003258
John McCalla2becad2009-10-21 00:40:46 +00003259 // Temporary workaround. All of these transformations should
3260 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003261 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3262 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003263
John McCall43fed0d2010-11-12 08:19:04 +00003264 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003265
John McCalla2becad2009-10-21 00:40:46 +00003266 if (!NewDI)
3267 return QualType();
3268
3269 return NewDI->getType();
3270}
3271
3272template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003273TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003274 // Refine the base location to the type's location.
3275 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3276 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003277 if (getDerived().AlreadyTransformed(DI->getType()))
3278 return DI;
3279
3280 TypeLocBuilder TLB;
3281
3282 TypeLoc TL = DI->getTypeLoc();
3283 TLB.reserve(TL.getFullDataSize());
3284
John McCall43fed0d2010-11-12 08:19:04 +00003285 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003286 if (Result.isNull())
3287 return 0;
3288
John McCalla93c9342009-12-07 02:54:59 +00003289 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003290}
3291
3292template<typename Derived>
3293QualType
John McCall43fed0d2010-11-12 08:19:04 +00003294TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003295 switch (T.getTypeLocClass()) {
3296#define ABSTRACT_TYPELOC(CLASS, PARENT)
3297#define TYPELOC(CLASS, PARENT) \
3298 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003299 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003300#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003301 }
Mike Stump1eb44332009-09-09 15:08:12 +00003302
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003303 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003304}
3305
3306/// FIXME: By default, this routine adds type qualifiers only to types
3307/// that can have qualifiers, and silently suppresses those qualifiers
3308/// that are not permitted (e.g., qualifiers on reference or function
3309/// types). This is the right thing for template instantiation, but
3310/// probably not for other clients.
3311template<typename Derived>
3312QualType
3313TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003314 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003315 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003316
John McCall43fed0d2010-11-12 08:19:04 +00003317 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003318 if (Result.isNull())
3319 return QualType();
3320
3321 // Silently suppress qualifiers if the result type can't be qualified.
3322 // FIXME: this is the right thing for template instantiation, but
3323 // probably not for other clients.
3324 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003325 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003326
John McCallf85e1932011-06-15 23:02:42 +00003327 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003328 // resulting type.
3329 if (Quals.hasObjCLifetime()) {
3330 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3331 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003332 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003333 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003334 // A lifetime qualifier applied to a substituted template parameter
3335 // overrides the lifetime qualifier from the template argument.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003336 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003337 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3338 QualType Replacement = SubstTypeParam->getReplacementType();
3339 Qualifiers Qs = Replacement.getQualifiers();
3340 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003341 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003342 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3343 Qs);
3344 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003345 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003346 Replacement);
3347 TLB.TypeWasModifiedSafely(Result);
3348 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003349 // Otherwise, complain about the addition of a qualifier to an
3350 // already-qualified type.
3351 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003352 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003353 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003354
Douglas Gregore559ca12011-06-17 22:11:49 +00003355 Quals.removeObjCLifetime();
3356 }
3357 }
3358 }
John McCall28654742010-06-05 06:41:15 +00003359 if (!Quals.empty()) {
3360 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3361 TLB.push<QualifiedTypeLoc>(Result);
3362 // No location information to preserve.
3363 }
John McCalla2becad2009-10-21 00:40:46 +00003364
3365 return Result;
3366}
3367
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003368template<typename Derived>
3369TypeLoc
3370TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3371 QualType ObjectType,
3372 NamedDecl *UnqualLookup,
3373 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003374 QualType T = TL.getType();
3375 if (getDerived().AlreadyTransformed(T))
3376 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003377
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003378 TypeLocBuilder TLB;
3379 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003380
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003381 if (isa<TemplateSpecializationType>(T)) {
3382 TemplateSpecializationTypeLoc SpecTL
3383 = cast<TemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003384
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003385 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003386 getDerived().TransformTemplateName(SS,
3387 SpecTL.getTypePtr()->getTemplateName(),
3388 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003389 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003390 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003391 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003392
3393 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003394 Template);
3395 } else if (isa<DependentTemplateSpecializationType>(T)) {
3396 DependentTemplateSpecializationTypeLoc SpecTL
3397 = cast<DependentTemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003398
Douglas Gregora88f09f2011-02-28 17:23:35 +00003399 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003400 = getDerived().RebuildTemplateName(SS,
3401 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003402 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003403 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003404 if (Template.isNull())
3405 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003406
3407 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003408 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003409 Template,
3410 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003411 } else {
3412 // Nothing special needs to be done for these.
3413 Result = getDerived().TransformType(TLB, TL);
3414 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003415
3416 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003417 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003418
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003419 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3420}
3421
Douglas Gregorb71d8212011-03-02 18:32:08 +00003422template<typename Derived>
3423TypeSourceInfo *
3424TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3425 QualType ObjectType,
3426 NamedDecl *UnqualLookup,
3427 CXXScopeSpec &SS) {
3428 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003429
Douglas Gregorb71d8212011-03-02 18:32:08 +00003430 QualType T = TSInfo->getType();
3431 if (getDerived().AlreadyTransformed(T))
3432 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003433
Douglas Gregorb71d8212011-03-02 18:32:08 +00003434 TypeLocBuilder TLB;
3435 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003436
Douglas Gregorb71d8212011-03-02 18:32:08 +00003437 TypeLoc TL = TSInfo->getTypeLoc();
3438 if (isa<TemplateSpecializationType>(T)) {
3439 TemplateSpecializationTypeLoc SpecTL
3440 = cast<TemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003441
Douglas Gregorb71d8212011-03-02 18:32:08 +00003442 TemplateName Template
3443 = getDerived().TransformTemplateName(SS,
3444 SpecTL.getTypePtr()->getTemplateName(),
3445 SpecTL.getTemplateNameLoc(),
3446 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003447 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003448 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003449
3450 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003451 Template);
3452 } else if (isa<DependentTemplateSpecializationType>(T)) {
3453 DependentTemplateSpecializationTypeLoc SpecTL
3454 = cast<DependentTemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003455
Douglas Gregorb71d8212011-03-02 18:32:08 +00003456 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003457 = getDerived().RebuildTemplateName(SS,
3458 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003459 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003460 ObjectType, UnqualLookup);
3461 if (Template.isNull())
3462 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003463
3464 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003465 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003466 Template,
3467 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003468 } else {
3469 // Nothing special needs to be done for these.
3470 Result = getDerived().TransformType(TLB, TL);
3471 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003472
3473 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003474 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003475
Douglas Gregorb71d8212011-03-02 18:32:08 +00003476 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3477}
3478
John McCalla2becad2009-10-21 00:40:46 +00003479template <class TyLoc> static inline
3480QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3481 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3482 NewT.setNameLoc(T.getNameLoc());
3483 return T.getType();
3484}
3485
John McCalla2becad2009-10-21 00:40:46 +00003486template<typename Derived>
3487QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003488 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003489 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3490 NewT.setBuiltinLoc(T.getBuiltinLoc());
3491 if (T.needsExtraLocalData())
3492 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3493 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003494}
Mike Stump1eb44332009-09-09 15:08:12 +00003495
Douglas Gregor577f75a2009-08-04 16:50:30 +00003496template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003497QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003498 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003499 // FIXME: recurse?
3500 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003501}
Mike Stump1eb44332009-09-09 15:08:12 +00003502
Douglas Gregor577f75a2009-08-04 16:50:30 +00003503template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003504QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003505 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003506 QualType PointeeType
3507 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003508 if (PointeeType.isNull())
3509 return QualType();
3510
3511 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003512 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003513 // A dependent pointer type 'T *' has is being transformed such
3514 // that an Objective-C class type is being replaced for 'T'. The
3515 // resulting pointer type is an ObjCObjectPointerType, not a
3516 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003517 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003518
John McCallc12c5bb2010-05-15 11:32:37 +00003519 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3520 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003521 return Result;
3522 }
John McCall43fed0d2010-11-12 08:19:04 +00003523
Douglas Gregor92e986e2010-04-22 16:44:27 +00003524 if (getDerived().AlwaysRebuild() ||
3525 PointeeType != TL.getPointeeLoc().getType()) {
3526 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3527 if (Result.isNull())
3528 return QualType();
3529 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003530
John McCallf85e1932011-06-15 23:02:42 +00003531 // Objective-C ARC can add lifetime qualifiers to the type that we're
3532 // pointing to.
3533 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003534
Douglas Gregor92e986e2010-04-22 16:44:27 +00003535 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3536 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003537 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003538}
Mike Stump1eb44332009-09-09 15:08:12 +00003539
3540template<typename Derived>
3541QualType
John McCalla2becad2009-10-21 00:40:46 +00003542TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003543 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003544 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003545 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3546 if (PointeeType.isNull())
3547 return QualType();
3548
3549 QualType Result = TL.getType();
3550 if (getDerived().AlwaysRebuild() ||
3551 PointeeType != TL.getPointeeLoc().getType()) {
3552 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003553 TL.getSigilLoc());
3554 if (Result.isNull())
3555 return QualType();
3556 }
3557
Douglas Gregor39968ad2010-04-22 16:50:51 +00003558 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003559 NewT.setSigilLoc(TL.getSigilLoc());
3560 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003561}
3562
John McCall85737a72009-10-30 00:06:24 +00003563/// Transforms a reference type. Note that somewhat paradoxically we
3564/// don't care whether the type itself is an l-value type or an r-value
3565/// type; we only care if the type was *written* as an l-value type
3566/// or an r-value type.
3567template<typename Derived>
3568QualType
3569TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003570 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003571 const ReferenceType *T = TL.getTypePtr();
3572
3573 // Note that this works with the pointee-as-written.
3574 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3575 if (PointeeType.isNull())
3576 return QualType();
3577
3578 QualType Result = TL.getType();
3579 if (getDerived().AlwaysRebuild() ||
3580 PointeeType != T->getPointeeTypeAsWritten()) {
3581 Result = getDerived().RebuildReferenceType(PointeeType,
3582 T->isSpelledAsLValue(),
3583 TL.getSigilLoc());
3584 if (Result.isNull())
3585 return QualType();
3586 }
3587
John McCallf85e1932011-06-15 23:02:42 +00003588 // Objective-C ARC can add lifetime qualifiers to the type that we're
3589 // referring to.
3590 TLB.TypeWasModifiedSafely(
3591 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3592
John McCall85737a72009-10-30 00:06:24 +00003593 // r-value references can be rebuilt as l-value references.
3594 ReferenceTypeLoc NewTL;
3595 if (isa<LValueReferenceType>(Result))
3596 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3597 else
3598 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3599 NewTL.setSigilLoc(TL.getSigilLoc());
3600
3601 return Result;
3602}
3603
Mike Stump1eb44332009-09-09 15:08:12 +00003604template<typename Derived>
3605QualType
John McCalla2becad2009-10-21 00:40:46 +00003606TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003607 LValueReferenceTypeLoc TL) {
3608 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003609}
3610
Mike Stump1eb44332009-09-09 15:08:12 +00003611template<typename Derived>
3612QualType
John McCalla2becad2009-10-21 00:40:46 +00003613TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003614 RValueReferenceTypeLoc TL) {
3615 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003616}
Mike Stump1eb44332009-09-09 15:08:12 +00003617
Douglas Gregor577f75a2009-08-04 16:50:30 +00003618template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003619QualType
John McCalla2becad2009-10-21 00:40:46 +00003620TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003621 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003622 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003623 if (PointeeType.isNull())
3624 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003625
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003626 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3627 TypeSourceInfo* NewClsTInfo = 0;
3628 if (OldClsTInfo) {
3629 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3630 if (!NewClsTInfo)
3631 return QualType();
3632 }
3633
3634 const MemberPointerType *T = TL.getTypePtr();
3635 QualType OldClsType = QualType(T->getClass(), 0);
3636 QualType NewClsType;
3637 if (NewClsTInfo)
3638 NewClsType = NewClsTInfo->getType();
3639 else {
3640 NewClsType = getDerived().TransformType(OldClsType);
3641 if (NewClsType.isNull())
3642 return QualType();
3643 }
Mike Stump1eb44332009-09-09 15:08:12 +00003644
John McCalla2becad2009-10-21 00:40:46 +00003645 QualType Result = TL.getType();
3646 if (getDerived().AlwaysRebuild() ||
3647 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003648 NewClsType != OldClsType) {
3649 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003650 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003651 if (Result.isNull())
3652 return QualType();
3653 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003654
John McCalla2becad2009-10-21 00:40:46 +00003655 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3656 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003657 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003658
3659 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003660}
3661
Mike Stump1eb44332009-09-09 15:08:12 +00003662template<typename Derived>
3663QualType
John McCalla2becad2009-10-21 00:40:46 +00003664TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003665 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003666 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003667 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003668 if (ElementType.isNull())
3669 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003670
John McCalla2becad2009-10-21 00:40:46 +00003671 QualType Result = TL.getType();
3672 if (getDerived().AlwaysRebuild() ||
3673 ElementType != T->getElementType()) {
3674 Result = getDerived().RebuildConstantArrayType(ElementType,
3675 T->getSizeModifier(),
3676 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003677 T->getIndexTypeCVRQualifiers(),
3678 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003679 if (Result.isNull())
3680 return QualType();
3681 }
Eli Friedman457a3772012-01-25 22:19:07 +00003682
3683 // We might have either a ConstantArrayType or a VariableArrayType now:
3684 // a ConstantArrayType is allowed to have an element type which is a
3685 // VariableArrayType if the type is dependent. Fortunately, all array
3686 // types have the same location layout.
3687 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003688 NewTL.setLBracketLoc(TL.getLBracketLoc());
3689 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003690
John McCalla2becad2009-10-21 00:40:46 +00003691 Expr *Size = TL.getSizeExpr();
3692 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003693 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3694 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003695 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003696 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003697 }
3698 NewTL.setSizeExpr(Size);
3699
3700 return Result;
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>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003704QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003705 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003706 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003707 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003708 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003709 if (ElementType.isNull())
3710 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003711
John McCalla2becad2009-10-21 00:40:46 +00003712 QualType Result = TL.getType();
3713 if (getDerived().AlwaysRebuild() ||
3714 ElementType != T->getElementType()) {
3715 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003716 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003717 T->getIndexTypeCVRQualifiers(),
3718 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003719 if (Result.isNull())
3720 return QualType();
3721 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003722
John McCalla2becad2009-10-21 00:40:46 +00003723 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3724 NewTL.setLBracketLoc(TL.getLBracketLoc());
3725 NewTL.setRBracketLoc(TL.getRBracketLoc());
3726 NewTL.setSizeExpr(0);
3727
3728 return Result;
3729}
3730
3731template<typename Derived>
3732QualType
3733TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003734 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003735 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003736 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3737 if (ElementType.isNull())
3738 return QualType();
3739
John McCall60d7b3a2010-08-24 06:29:42 +00003740 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003741 = getDerived().TransformExpr(T->getSizeExpr());
3742 if (SizeResult.isInvalid())
3743 return QualType();
3744
John McCall9ae2f072010-08-23 23:25:46 +00003745 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003746
3747 QualType Result = TL.getType();
3748 if (getDerived().AlwaysRebuild() ||
3749 ElementType != T->getElementType() ||
3750 Size != T->getSizeExpr()) {
3751 Result = getDerived().RebuildVariableArrayType(ElementType,
3752 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003753 Size,
John McCalla2becad2009-10-21 00:40:46 +00003754 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003755 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003756 if (Result.isNull())
3757 return QualType();
3758 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003759
John McCalla2becad2009-10-21 00:40:46 +00003760 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3761 NewTL.setLBracketLoc(TL.getLBracketLoc());
3762 NewTL.setRBracketLoc(TL.getRBracketLoc());
3763 NewTL.setSizeExpr(Size);
3764
3765 return Result;
3766}
3767
3768template<typename Derived>
3769QualType
3770TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003771 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003772 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003773 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3774 if (ElementType.isNull())
3775 return QualType();
3776
Richard Smithf6702a32011-12-20 02:08:33 +00003777 // Array bounds are constant expressions.
3778 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3779 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003780
John McCall3b657512011-01-19 10:06:00 +00003781 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3782 Expr *origSize = TL.getSizeExpr();
3783 if (!origSize) origSize = T->getSizeExpr();
3784
3785 ExprResult sizeResult
3786 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003787 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003788 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003789 return QualType();
3790
John McCall3b657512011-01-19 10:06:00 +00003791 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003792
3793 QualType Result = TL.getType();
3794 if (getDerived().AlwaysRebuild() ||
3795 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003796 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003797 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3798 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003799 size,
John McCalla2becad2009-10-21 00:40:46 +00003800 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003801 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003802 if (Result.isNull())
3803 return QualType();
3804 }
John McCalla2becad2009-10-21 00:40:46 +00003805
3806 // We might have any sort of array type now, but fortunately they
3807 // all have the same location layout.
3808 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3809 NewTL.setLBracketLoc(TL.getLBracketLoc());
3810 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003811 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003812
3813 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003814}
Mike Stump1eb44332009-09-09 15:08:12 +00003815
3816template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003817QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003818 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003819 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003820 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003821
3822 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003823 QualType ElementType = getDerived().TransformType(T->getElementType());
3824 if (ElementType.isNull())
3825 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003826
Richard Smithf6702a32011-12-20 02:08:33 +00003827 // Vector sizes are constant expressions.
3828 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3829 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003830
John McCall60d7b3a2010-08-24 06:29:42 +00003831 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003832 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003833 if (Size.isInvalid())
3834 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003835
John McCalla2becad2009-10-21 00:40:46 +00003836 QualType Result = TL.getType();
3837 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003838 ElementType != T->getElementType() ||
3839 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003840 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003841 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003842 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003843 if (Result.isNull())
3844 return QualType();
3845 }
John McCalla2becad2009-10-21 00:40:46 +00003846
3847 // Result might be dependent or not.
3848 if (isa<DependentSizedExtVectorType>(Result)) {
3849 DependentSizedExtVectorTypeLoc NewTL
3850 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3851 NewTL.setNameLoc(TL.getNameLoc());
3852 } else {
3853 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3854 NewTL.setNameLoc(TL.getNameLoc());
3855 }
3856
3857 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003858}
Mike Stump1eb44332009-09-09 15:08:12 +00003859
3860template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003861QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003862 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003863 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003864 QualType ElementType = getDerived().TransformType(T->getElementType());
3865 if (ElementType.isNull())
3866 return QualType();
3867
John McCalla2becad2009-10-21 00:40:46 +00003868 QualType Result = TL.getType();
3869 if (getDerived().AlwaysRebuild() ||
3870 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003871 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003872 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003873 if (Result.isNull())
3874 return QualType();
3875 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003876
John McCalla2becad2009-10-21 00:40:46 +00003877 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3878 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003879
John McCalla2becad2009-10-21 00:40:46 +00003880 return Result;
3881}
3882
3883template<typename Derived>
3884QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003885 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003886 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003887 QualType ElementType = getDerived().TransformType(T->getElementType());
3888 if (ElementType.isNull())
3889 return QualType();
3890
3891 QualType Result = TL.getType();
3892 if (getDerived().AlwaysRebuild() ||
3893 ElementType != T->getElementType()) {
3894 Result = getDerived().RebuildExtVectorType(ElementType,
3895 T->getNumElements(),
3896 /*FIXME*/ SourceLocation());
3897 if (Result.isNull())
3898 return QualType();
3899 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003900
John McCalla2becad2009-10-21 00:40:46 +00003901 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3902 NewTL.setNameLoc(TL.getNameLoc());
3903
3904 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003905}
Mike Stump1eb44332009-09-09 15:08:12 +00003906
3907template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003908ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003909TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003910 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003911 llvm::Optional<unsigned> NumExpansions,
3912 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003913 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003914 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003915
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003916 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003917 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003918 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003919 TypeLoc OldTL = OldDI->getTypeLoc();
3920 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003921
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003922 TypeLocBuilder TLB;
3923 TypeLoc NewTL = OldDI->getTypeLoc();
3924 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003925
3926 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003927 OldExpansionTL.getPatternLoc());
3928 if (Result.isNull())
3929 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003930
3931 Result = RebuildPackExpansionType(Result,
3932 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003933 OldExpansionTL.getEllipsisLoc(),
3934 NumExpansions);
3935 if (Result.isNull())
3936 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003937
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003938 PackExpansionTypeLoc NewExpansionTL
3939 = TLB.push<PackExpansionTypeLoc>(Result);
3940 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3941 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3942 } else
3943 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003944 if (!NewDI)
3945 return 0;
3946
John McCallfb44de92011-05-01 22:35:37 +00003947 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003948 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003949
3950 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3951 OldParm->getDeclContext(),
3952 OldParm->getInnerLocStart(),
3953 OldParm->getLocation(),
3954 OldParm->getIdentifier(),
3955 NewDI->getType(),
3956 NewDI,
3957 OldParm->getStorageClass(),
3958 OldParm->getStorageClassAsWritten(),
3959 /* DefArg */ NULL);
3960 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3961 OldParm->getFunctionScopeIndex() + indexAdjustment);
3962 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003963}
3964
3965template<typename Derived>
3966bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003967 TransformFunctionTypeParams(SourceLocation Loc,
3968 ParmVarDecl **Params, unsigned NumParams,
3969 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003970 SmallVectorImpl<QualType> &OutParamTypes,
3971 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003972 int indexAdjustment = 0;
3973
Douglas Gregora009b592011-01-07 00:20:55 +00003974 for (unsigned i = 0; i != NumParams; ++i) {
3975 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003976 assert(OldParm->getFunctionScopeIndex() == i);
3977
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003978 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003979 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003980 if (OldParm->isParameterPack()) {
3981 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003982 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003983
Douglas Gregor603cfb42011-01-05 23:12:31 +00003984 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003985 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3986 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3987 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3988 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003989 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3990
Douglas Gregor603cfb42011-01-05 23:12:31 +00003991 // Determine whether we should expand the parameter packs.
3992 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003993 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003994 llvm::Optional<unsigned> OrigNumExpansions
3995 = ExpansionTL.getTypePtr()->getNumExpansions();
3996 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003997 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3998 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00003999 Unexpanded,
4000 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004001 RetainExpansion,
4002 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004003 return true;
4004 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004005
Douglas Gregor603cfb42011-01-05 23:12:31 +00004006 if (ShouldExpand) {
4007 // Expand the function parameter pack into multiple, separate
4008 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004009 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004010 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004011 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004012 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004013 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004014 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004015 OrigNumExpansions,
4016 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004017 if (!NewParm)
4018 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004019
Douglas Gregora009b592011-01-07 00:20:55 +00004020 OutParamTypes.push_back(NewParm->getType());
4021 if (PVars)
4022 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004023 }
Douglas Gregord3731192011-01-10 07:32:04 +00004024
4025 // If we're supposed to retain a pack expansion, do so by temporarily
4026 // forgetting the partially-substituted parameter pack.
4027 if (RetainExpansion) {
4028 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004029 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004030 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004031 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004032 OrigNumExpansions,
4033 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004034 if (!NewParm)
4035 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004036
Douglas Gregord3731192011-01-10 07:32:04 +00004037 OutParamTypes.push_back(NewParm->getType());
4038 if (PVars)
4039 PVars->push_back(NewParm);
4040 }
4041
John McCallfb44de92011-05-01 22:35:37 +00004042 // The next parameter should have the same adjustment as the
4043 // last thing we pushed, but we post-incremented indexAdjustment
4044 // on every push. Also, if we push nothing, the adjustment should
4045 // go down by one.
4046 indexAdjustment--;
4047
Douglas Gregor603cfb42011-01-05 23:12:31 +00004048 // We're done with the pack expansion.
4049 continue;
4050 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004051
4052 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004053 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004054 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4055 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004056 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004057 NumExpansions,
4058 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004059 } else {
4060 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004061 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004062 llvm::Optional<unsigned>(),
4063 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004064 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004065
John McCall21ef0fa2010-03-11 09:03:00 +00004066 if (!NewParm)
4067 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004068
Douglas Gregora009b592011-01-07 00:20:55 +00004069 OutParamTypes.push_back(NewParm->getType());
4070 if (PVars)
4071 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004072 continue;
4073 }
John McCall21ef0fa2010-03-11 09:03:00 +00004074
4075 // Deal with the possibility that we don't have a parameter
4076 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004077 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004078 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004079 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004080 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004081 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004082 = dyn_cast<PackExpansionType>(OldType)) {
4083 // We have a function parameter pack that may need to be expanded.
4084 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004085 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004086 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004087
Douglas Gregor603cfb42011-01-05 23:12:31 +00004088 // Determine whether we should expand the parameter packs.
4089 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004090 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004091 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004092 Unexpanded,
4093 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004094 RetainExpansion,
4095 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004096 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004097 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004098
Douglas Gregor603cfb42011-01-05 23:12:31 +00004099 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004100 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004101 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004102 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004103 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4104 QualType NewType = getDerived().TransformType(Pattern);
4105 if (NewType.isNull())
4106 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004107
Douglas Gregora009b592011-01-07 00:20:55 +00004108 OutParamTypes.push_back(NewType);
4109 if (PVars)
4110 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004111 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004112
Douglas Gregor603cfb42011-01-05 23:12:31 +00004113 // We're done with the pack expansion.
4114 continue;
4115 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004116
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004117 // If we're supposed to retain a pack expansion, do so by temporarily
4118 // forgetting the partially-substituted parameter pack.
4119 if (RetainExpansion) {
4120 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4121 QualType NewType = getDerived().TransformType(Pattern);
4122 if (NewType.isNull())
4123 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004124
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004125 OutParamTypes.push_back(NewType);
4126 if (PVars)
4127 PVars->push_back(0);
4128 }
Douglas Gregord3731192011-01-10 07:32:04 +00004129
Chad Rosier4a9d7952012-08-08 18:46:20 +00004130 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004131 // expansion.
4132 OldType = Expansion->getPattern();
4133 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004134 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4135 NewType = getDerived().TransformType(OldType);
4136 } else {
4137 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004138 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004139
Douglas Gregor603cfb42011-01-05 23:12:31 +00004140 if (NewType.isNull())
4141 return true;
4142
4143 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004144 NewType = getSema().Context.getPackExpansionType(NewType,
4145 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004146
Douglas Gregora009b592011-01-07 00:20:55 +00004147 OutParamTypes.push_back(NewType);
4148 if (PVars)
4149 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004150 }
4151
John McCallfb44de92011-05-01 22:35:37 +00004152#ifndef NDEBUG
4153 if (PVars) {
4154 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4155 if (ParmVarDecl *parm = (*PVars)[i])
4156 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004157 }
John McCallfb44de92011-05-01 22:35:37 +00004158#endif
4159
4160 return false;
4161}
John McCall21ef0fa2010-03-11 09:03:00 +00004162
4163template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004164QualType
John McCalla2becad2009-10-21 00:40:46 +00004165TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004166 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004167 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4168}
4169
4170template<typename Derived>
4171QualType
4172TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4173 FunctionProtoTypeLoc TL,
4174 CXXRecordDecl *ThisContext,
4175 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004176 // Transform the parameters and return type.
4177 //
Richard Smithe6975e92012-04-17 00:58:00 +00004178 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004179 // When the function has a trailing return type, we instantiate the
4180 // parameters before the return type, since the return type can then refer
4181 // to the parameters themselves (via decltype, sizeof, etc.).
4182 //
Chris Lattner686775d2011-07-20 06:58:45 +00004183 SmallVector<QualType, 4> ParamTypes;
4184 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004185 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004186
Douglas Gregordab60ad2010-10-01 18:44:50 +00004187 QualType ResultType;
4188
Richard Smith9fbf3272012-08-14 22:51:13 +00004189 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004190 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004191 TL.getParmArray(),
4192 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004193 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004194 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004195 return QualType();
4196
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004197 {
4198 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004199 // If a declaration declares a member function or member function
4200 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004201 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004202 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004203 // declarator.
4204 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004205
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004206 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4207 if (ResultType.isNull())
4208 return QualType();
4209 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004210 }
4211 else {
4212 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4213 if (ResultType.isNull())
4214 return QualType();
4215
Chad Rosier4a9d7952012-08-08 18:46:20 +00004216 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004217 TL.getParmArray(),
4218 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004219 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004220 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004221 return QualType();
4222 }
4223
Richard Smithe6975e92012-04-17 00:58:00 +00004224 // FIXME: Need to transform the exception-specification too.
4225
John McCalla2becad2009-10-21 00:40:46 +00004226 QualType Result = TL.getType();
4227 if (getDerived().AlwaysRebuild() ||
4228 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004229 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004230 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4231 Result = getDerived().RebuildFunctionProtoType(ResultType,
4232 ParamTypes.data(),
4233 ParamTypes.size(),
4234 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004235 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004236 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004237 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004238 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004239 if (Result.isNull())
4240 return QualType();
4241 }
Mike Stump1eb44332009-09-09 15:08:12 +00004242
John McCalla2becad2009-10-21 00:40:46 +00004243 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004244 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4245 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004246 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4247 NewTL.setArg(i, ParamDecls[i]);
4248
4249 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004250}
Mike Stump1eb44332009-09-09 15:08:12 +00004251
Douglas Gregor577f75a2009-08-04 16:50:30 +00004252template<typename Derived>
4253QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004254 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004255 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004256 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004257 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4258 if (ResultType.isNull())
4259 return QualType();
4260
4261 QualType Result = TL.getType();
4262 if (getDerived().AlwaysRebuild() ||
4263 ResultType != T->getResultType())
4264 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4265
4266 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004267 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4268 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004269
4270 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004271}
Mike Stump1eb44332009-09-09 15:08:12 +00004272
John McCalled976492009-12-04 22:46:56 +00004273template<typename Derived> QualType
4274TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004275 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004276 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004277 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004278 if (!D)
4279 return QualType();
4280
4281 QualType Result = TL.getType();
4282 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4283 Result = getDerived().RebuildUnresolvedUsingType(D);
4284 if (Result.isNull())
4285 return QualType();
4286 }
4287
4288 // We might get an arbitrary type spec type back. We should at
4289 // least always get a type spec type, though.
4290 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4291 NewTL.setNameLoc(TL.getNameLoc());
4292
4293 return Result;
4294}
4295
Douglas Gregor577f75a2009-08-04 16:50:30 +00004296template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004297QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004298 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004299 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004300 TypedefNameDecl *Typedef
4301 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4302 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004303 if (!Typedef)
4304 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004305
John McCalla2becad2009-10-21 00:40:46 +00004306 QualType Result = TL.getType();
4307 if (getDerived().AlwaysRebuild() ||
4308 Typedef != T->getDecl()) {
4309 Result = getDerived().RebuildTypedefType(Typedef);
4310 if (Result.isNull())
4311 return QualType();
4312 }
Mike Stump1eb44332009-09-09 15:08:12 +00004313
John McCalla2becad2009-10-21 00:40:46 +00004314 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4315 NewTL.setNameLoc(TL.getNameLoc());
4316
4317 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004318}
Mike Stump1eb44332009-09-09 15:08:12 +00004319
Douglas Gregor577f75a2009-08-04 16:50:30 +00004320template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004321QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004322 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004323 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004324 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004325
John McCall60d7b3a2010-08-24 06:29:42 +00004326 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004327 if (E.isInvalid())
4328 return QualType();
4329
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004330 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4331 if (E.isInvalid())
4332 return QualType();
4333
John McCalla2becad2009-10-21 00:40:46 +00004334 QualType Result = TL.getType();
4335 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004336 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004337 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004338 if (Result.isNull())
4339 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004340 }
John McCalla2becad2009-10-21 00:40:46 +00004341 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004342
John McCalla2becad2009-10-21 00:40:46 +00004343 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004344 NewTL.setTypeofLoc(TL.getTypeofLoc());
4345 NewTL.setLParenLoc(TL.getLParenLoc());
4346 NewTL.setRParenLoc(TL.getRParenLoc());
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
4351template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004352QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004353 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004354 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4355 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4356 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004357 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004358
John McCalla2becad2009-10-21 00:40:46 +00004359 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004360 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4361 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004362 if (Result.isNull())
4363 return QualType();
4364 }
Mike Stump1eb44332009-09-09 15:08:12 +00004365
John McCalla2becad2009-10-21 00:40:46 +00004366 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004367 NewTL.setTypeofLoc(TL.getTypeofLoc());
4368 NewTL.setLParenLoc(TL.getLParenLoc());
4369 NewTL.setRParenLoc(TL.getRParenLoc());
4370 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004371
4372 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004373}
Mike Stump1eb44332009-09-09 15:08:12 +00004374
4375template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004376QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004377 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004378 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004379
Douglas Gregor670444e2009-08-04 22:27:00 +00004380 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004381 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4382 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004383
John McCall60d7b3a2010-08-24 06:29:42 +00004384 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004385 if (E.isInvalid())
4386 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004387
Richard Smith76f3f692012-02-22 02:04:18 +00004388 E = getSema().ActOnDecltypeExpression(E.take());
4389 if (E.isInvalid())
4390 return QualType();
4391
John McCalla2becad2009-10-21 00:40:46 +00004392 QualType Result = TL.getType();
4393 if (getDerived().AlwaysRebuild() ||
4394 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004395 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004396 if (Result.isNull())
4397 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004398 }
John McCalla2becad2009-10-21 00:40:46 +00004399 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004400
John McCalla2becad2009-10-21 00:40:46 +00004401 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4402 NewTL.setNameLoc(TL.getNameLoc());
4403
4404 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004405}
4406
4407template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004408QualType TreeTransform<Derived>::TransformUnaryTransformType(
4409 TypeLocBuilder &TLB,
4410 UnaryTransformTypeLoc TL) {
4411 QualType Result = TL.getType();
4412 if (Result->isDependentType()) {
4413 const UnaryTransformType *T = TL.getTypePtr();
4414 QualType NewBase =
4415 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4416 Result = getDerived().RebuildUnaryTransformType(NewBase,
4417 T->getUTTKind(),
4418 TL.getKWLoc());
4419 if (Result.isNull())
4420 return QualType();
4421 }
4422
4423 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4424 NewTL.setKWLoc(TL.getKWLoc());
4425 NewTL.setParensRange(TL.getParensRange());
4426 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4427 return Result;
4428}
4429
4430template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004431QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4432 AutoTypeLoc TL) {
4433 const AutoType *T = TL.getTypePtr();
4434 QualType OldDeduced = T->getDeducedType();
4435 QualType NewDeduced;
4436 if (!OldDeduced.isNull()) {
4437 NewDeduced = getDerived().TransformType(OldDeduced);
4438 if (NewDeduced.isNull())
4439 return QualType();
4440 }
4441
4442 QualType Result = TL.getType();
4443 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4444 Result = getDerived().RebuildAutoType(NewDeduced);
4445 if (Result.isNull())
4446 return QualType();
4447 }
4448
4449 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4450 NewTL.setNameLoc(TL.getNameLoc());
4451
4452 return Result;
4453}
4454
4455template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004456QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004457 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004458 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004459 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004460 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4461 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004462 if (!Record)
4463 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004464
John McCalla2becad2009-10-21 00:40:46 +00004465 QualType Result = TL.getType();
4466 if (getDerived().AlwaysRebuild() ||
4467 Record != T->getDecl()) {
4468 Result = getDerived().RebuildRecordType(Record);
4469 if (Result.isNull())
4470 return QualType();
4471 }
Mike Stump1eb44332009-09-09 15:08:12 +00004472
John McCalla2becad2009-10-21 00:40:46 +00004473 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4474 NewTL.setNameLoc(TL.getNameLoc());
4475
4476 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004477}
Mike Stump1eb44332009-09-09 15:08:12 +00004478
4479template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004480QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004481 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004482 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004483 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004484 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4485 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004486 if (!Enum)
4487 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004488
John McCalla2becad2009-10-21 00:40:46 +00004489 QualType Result = TL.getType();
4490 if (getDerived().AlwaysRebuild() ||
4491 Enum != T->getDecl()) {
4492 Result = getDerived().RebuildEnumType(Enum);
4493 if (Result.isNull())
4494 return QualType();
4495 }
Mike Stump1eb44332009-09-09 15:08:12 +00004496
John McCalla2becad2009-10-21 00:40:46 +00004497 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4498 NewTL.setNameLoc(TL.getNameLoc());
4499
4500 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004501}
John McCall7da24312009-09-05 00:15:47 +00004502
John McCall3cb0ebd2010-03-10 03:28:59 +00004503template<typename Derived>
4504QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4505 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004506 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004507 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4508 TL.getTypePtr()->getDecl());
4509 if (!D) return QualType();
4510
4511 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4512 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4513 return T;
4514}
4515
Douglas Gregor577f75a2009-08-04 16:50:30 +00004516template<typename Derived>
4517QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004518 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004519 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004520 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004521}
4522
Mike Stump1eb44332009-09-09 15:08:12 +00004523template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004524QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004525 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004526 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004527 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004528
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004529 // Substitute into the replacement type, which itself might involve something
4530 // that needs to be transformed. This only tends to occur with default
4531 // template arguments of template template parameters.
4532 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4533 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4534 if (Replacement.isNull())
4535 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004536
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004537 // Always canonicalize the replacement type.
4538 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4539 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004540 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004541 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004542
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004543 // Propagate type-source information.
4544 SubstTemplateTypeParmTypeLoc NewTL
4545 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4546 NewTL.setNameLoc(TL.getNameLoc());
4547 return Result;
4548
John McCall49a832b2009-10-18 09:09:24 +00004549}
4550
4551template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004552QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4553 TypeLocBuilder &TLB,
4554 SubstTemplateTypeParmPackTypeLoc TL) {
4555 return TransformTypeSpecType(TLB, TL);
4556}
4557
4558template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004559QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004560 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004561 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004562 const TemplateSpecializationType *T = TL.getTypePtr();
4563
Douglas Gregor1d752d72011-03-02 18:46:51 +00004564 // The nested-name-specifier never matters in a TemplateSpecializationType,
4565 // because we can't have a dependent nested-name-specifier anyway.
4566 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004567 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004568 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4569 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004570 if (Template.isNull())
4571 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004572
John McCall43fed0d2010-11-12 08:19:04 +00004573 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4574}
4575
Eli Friedmanb001de72011-10-06 23:00:33 +00004576template<typename Derived>
4577QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4578 AtomicTypeLoc TL) {
4579 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4580 if (ValueType.isNull())
4581 return QualType();
4582
4583 QualType Result = TL.getType();
4584 if (getDerived().AlwaysRebuild() ||
4585 ValueType != TL.getValueLoc().getType()) {
4586 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4587 if (Result.isNull())
4588 return QualType();
4589 }
4590
4591 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4592 NewTL.setKWLoc(TL.getKWLoc());
4593 NewTL.setLParenLoc(TL.getLParenLoc());
4594 NewTL.setRParenLoc(TL.getRParenLoc());
4595
4596 return Result;
4597}
4598
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004599namespace {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004600 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004601 /// container that provides a \c getArgLoc() member function.
4602 ///
4603 /// This iterator is intended to be used with the iterator form of
4604 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4605 template<typename ArgLocContainer>
4606 class TemplateArgumentLocContainerIterator {
4607 ArgLocContainer *Container;
4608 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004609
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004610 public:
4611 typedef TemplateArgumentLoc value_type;
4612 typedef TemplateArgumentLoc reference;
4613 typedef int difference_type;
4614 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004615
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004616 class pointer {
4617 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004618
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004619 public:
4620 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004621
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004622 const TemplateArgumentLoc *operator->() const {
4623 return &Arg;
4624 }
4625 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004626
4627
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004628 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004629
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004630 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4631 unsigned Index)
4632 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004633
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004634 TemplateArgumentLocContainerIterator &operator++() {
4635 ++Index;
4636 return *this;
4637 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004638
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004639 TemplateArgumentLocContainerIterator operator++(int) {
4640 TemplateArgumentLocContainerIterator Old(*this);
4641 ++(*this);
4642 return Old;
4643 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004644
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004645 TemplateArgumentLoc operator*() const {
4646 return Container->getArgLoc(Index);
4647 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004648
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004649 pointer operator->() const {
4650 return pointer(Container->getArgLoc(Index));
4651 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004652
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004653 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004654 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004655 return X.Container == Y.Container && X.Index == Y.Index;
4656 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004657
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004658 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004659 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004660 return !(X == Y);
4661 }
4662 };
4663}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004664
4665
John McCall43fed0d2010-11-12 08:19:04 +00004666template <typename Derived>
4667QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4668 TypeLocBuilder &TLB,
4669 TemplateSpecializationTypeLoc TL,
4670 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004671 TemplateArgumentListInfo NewTemplateArgs;
4672 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4673 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004674 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4675 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004676 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004677 ArgIterator(TL, TL.getNumArgs()),
4678 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004679 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004680
John McCall833ca992009-10-29 08:12:44 +00004681 // FIXME: maybe don't rebuild if all the template arguments are the same.
4682
4683 QualType Result =
4684 getDerived().RebuildTemplateSpecializationType(Template,
4685 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004686 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004687
4688 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004689 // Specializations of template template parameters are represented as
4690 // TemplateSpecializationTypes, and substitution of type alias templates
4691 // within a dependent context can transform them into
4692 // DependentTemplateSpecializationTypes.
4693 if (isa<DependentTemplateSpecializationType>(Result)) {
4694 DependentTemplateSpecializationTypeLoc NewTL
4695 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004696 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004697 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004698 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004699 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004700 NewTL.setLAngleLoc(TL.getLAngleLoc());
4701 NewTL.setRAngleLoc(TL.getRAngleLoc());
4702 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4703 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4704 return Result;
4705 }
4706
John McCall833ca992009-10-29 08:12:44 +00004707 TemplateSpecializationTypeLoc NewTL
4708 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004709 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004710 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4711 NewTL.setLAngleLoc(TL.getLAngleLoc());
4712 NewTL.setRAngleLoc(TL.getRAngleLoc());
4713 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4714 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004715 }
Mike Stump1eb44332009-09-09 15:08:12 +00004716
John McCall833ca992009-10-29 08:12:44 +00004717 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004718}
Mike Stump1eb44332009-09-09 15:08:12 +00004719
Douglas Gregora88f09f2011-02-28 17:23:35 +00004720template <typename Derived>
4721QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4722 TypeLocBuilder &TLB,
4723 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004724 TemplateName Template,
4725 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004726 TemplateArgumentListInfo NewTemplateArgs;
4727 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4728 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4729 typedef TemplateArgumentLocContainerIterator<
4730 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004731 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004732 ArgIterator(TL, TL.getNumArgs()),
4733 NewTemplateArgs))
4734 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004735
Douglas Gregora88f09f2011-02-28 17:23:35 +00004736 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004737
Douglas Gregora88f09f2011-02-28 17:23:35 +00004738 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4739 QualType Result
4740 = getSema().Context.getDependentTemplateSpecializationType(
4741 TL.getTypePtr()->getKeyword(),
4742 DTN->getQualifier(),
4743 DTN->getIdentifier(),
4744 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004745
Douglas Gregora88f09f2011-02-28 17:23:35 +00004746 DependentTemplateSpecializationTypeLoc NewTL
4747 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004748 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004749 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004750 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004751 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004752 NewTL.setLAngleLoc(TL.getLAngleLoc());
4753 NewTL.setRAngleLoc(TL.getRAngleLoc());
4754 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4755 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4756 return Result;
4757 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004758
4759 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004760 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004761 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004762 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004763
Douglas Gregora88f09f2011-02-28 17:23:35 +00004764 if (!Result.isNull()) {
4765 /// FIXME: Wrap this in an elaborated-type-specifier?
4766 TemplateSpecializationTypeLoc NewTL
4767 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004768 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004769 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004770 NewTL.setLAngleLoc(TL.getLAngleLoc());
4771 NewTL.setRAngleLoc(TL.getRAngleLoc());
4772 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4773 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4774 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004775
Douglas Gregora88f09f2011-02-28 17:23:35 +00004776 return Result;
4777}
4778
Mike Stump1eb44332009-09-09 15:08:12 +00004779template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004780QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004781TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004782 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004783 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004784
Douglas Gregor9e876872011-03-01 18:12:44 +00004785 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004786 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004787 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004788 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004789 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4790 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004791 return QualType();
4792 }
Mike Stump1eb44332009-09-09 15:08:12 +00004793
John McCall43fed0d2010-11-12 08:19:04 +00004794 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4795 if (NamedT.isNull())
4796 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004797
Richard Smith3e4c6c42011-05-05 21:57:07 +00004798 // C++0x [dcl.type.elab]p2:
4799 // If the identifier resolves to a typedef-name or the simple-template-id
4800 // resolves to an alias template specialization, the
4801 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004802 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4803 if (const TemplateSpecializationType *TST =
4804 NamedT->getAs<TemplateSpecializationType>()) {
4805 TemplateName Template = TST->getTemplateName();
4806 if (TypeAliasTemplateDecl *TAT =
4807 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4808 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4809 diag::err_tag_reference_non_tag) << 4;
4810 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4811 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004812 }
4813 }
4814
John McCalla2becad2009-10-21 00:40:46 +00004815 QualType Result = TL.getType();
4816 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004817 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004818 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004819 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004820 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004821 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004822 if (Result.isNull())
4823 return QualType();
4824 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004825
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004826 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004827 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004828 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004829 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004830}
Mike Stump1eb44332009-09-09 15:08:12 +00004831
4832template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004833QualType TreeTransform<Derived>::TransformAttributedType(
4834 TypeLocBuilder &TLB,
4835 AttributedTypeLoc TL) {
4836 const AttributedType *oldType = TL.getTypePtr();
4837 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4838 if (modifiedType.isNull())
4839 return QualType();
4840
4841 QualType result = TL.getType();
4842
4843 // FIXME: dependent operand expressions?
4844 if (getDerived().AlwaysRebuild() ||
4845 modifiedType != oldType->getModifiedType()) {
4846 // TODO: this is really lame; we should really be rebuilding the
4847 // equivalent type from first principles.
4848 QualType equivalentType
4849 = getDerived().TransformType(oldType->getEquivalentType());
4850 if (equivalentType.isNull())
4851 return QualType();
4852 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4853 modifiedType,
4854 equivalentType);
4855 }
4856
4857 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4858 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4859 if (TL.hasAttrOperand())
4860 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4861 if (TL.hasAttrExprOperand())
4862 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4863 else if (TL.hasAttrEnumOperand())
4864 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4865
4866 return result;
4867}
4868
4869template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004870QualType
4871TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4872 ParenTypeLoc TL) {
4873 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4874 if (Inner.isNull())
4875 return QualType();
4876
4877 QualType Result = TL.getType();
4878 if (getDerived().AlwaysRebuild() ||
4879 Inner != TL.getInnerLoc().getType()) {
4880 Result = getDerived().RebuildParenType(Inner);
4881 if (Result.isNull())
4882 return QualType();
4883 }
4884
4885 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4886 NewTL.setLParenLoc(TL.getLParenLoc());
4887 NewTL.setRParenLoc(TL.getRParenLoc());
4888 return Result;
4889}
4890
4891template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004892QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004893 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004894 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004895
Douglas Gregor2494dd02011-03-01 01:34:45 +00004896 NestedNameSpecifierLoc QualifierLoc
4897 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4898 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004899 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004900
John McCall33500952010-06-11 00:33:02 +00004901 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004902 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004903 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004904 QualifierLoc,
4905 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004906 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004907 if (Result.isNull())
4908 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004909
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004910 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4911 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004912 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4913
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004914 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004915 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004916 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004917 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004918 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004919 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004920 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004921 NewTL.setNameLoc(TL.getNameLoc());
4922 }
John McCalla2becad2009-10-21 00:40:46 +00004923 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004924}
Mike Stump1eb44332009-09-09 15:08:12 +00004925
Douglas Gregor577f75a2009-08-04 16:50:30 +00004926template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004927QualType TreeTransform<Derived>::
4928 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004929 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004930 NestedNameSpecifierLoc QualifierLoc;
4931 if (TL.getQualifierLoc()) {
4932 QualifierLoc
4933 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4934 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004935 return QualType();
4936 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004937
John McCall43fed0d2010-11-12 08:19:04 +00004938 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004939 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004940}
4941
4942template<typename Derived>
4943QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004944TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4945 DependentTemplateSpecializationTypeLoc TL,
4946 NestedNameSpecifierLoc QualifierLoc) {
4947 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004948
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004949 TemplateArgumentListInfo NewTemplateArgs;
4950 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4951 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004952
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004953 typedef TemplateArgumentLocContainerIterator<
4954 DependentTemplateSpecializationTypeLoc> ArgIterator;
4955 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4956 ArgIterator(TL, TL.getNumArgs()),
4957 NewTemplateArgs))
4958 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004959
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004960 QualType Result
4961 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4962 QualifierLoc,
4963 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004964 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004965 NewTemplateArgs);
4966 if (Result.isNull())
4967 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004968
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004969 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4970 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004971
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004972 // Copy information relevant to the template specialization.
4973 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004974 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004975 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004976 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004977 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4978 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004979 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004980 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004981
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004982 // Copy information relevant to the elaborated type.
4983 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004984 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004985 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004986 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4987 DependentTemplateSpecializationTypeLoc SpecTL
4988 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004989 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004990 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004991 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004992 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004993 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4994 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004995 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004996 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004997 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004998 TemplateSpecializationTypeLoc SpecTL
4999 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005000 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005001 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005002 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5003 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005004 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005005 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005006 }
5007 return Result;
5008}
5009
5010template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005011QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5012 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005013 QualType Pattern
5014 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005015 if (Pattern.isNull())
5016 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005017
5018 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005019 if (getDerived().AlwaysRebuild() ||
5020 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005021 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005022 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005023 TL.getEllipsisLoc(),
5024 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005025 if (Result.isNull())
5026 return QualType();
5027 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005028
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005029 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5030 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5031 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005032}
5033
5034template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005035QualType
5036TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005037 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005038 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005039 TLB.pushFullCopy(TL);
5040 return TL.getType();
5041}
5042
5043template<typename Derived>
5044QualType
5045TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005046 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005047 // ObjCObjectType is never dependent.
5048 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005049 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005050}
Mike Stump1eb44332009-09-09 15:08:12 +00005051
5052template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005053QualType
5054TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005055 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005056 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005057 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005058 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005059}
5060
Douglas Gregor577f75a2009-08-04 16:50:30 +00005061//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005062// Statement transformation
5063//===----------------------------------------------------------------------===//
5064template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005065StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005066TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005067 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005068}
5069
5070template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005071StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005072TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5073 return getDerived().TransformCompoundStmt(S, false);
5074}
5075
5076template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005077StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005078TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005079 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005080 Sema::CompoundScopeRAII CompoundScope(getSema());
5081
John McCall7114cba2010-08-27 19:56:05 +00005082 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005083 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005084 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005085 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5086 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005087 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005088 if (Result.isInvalid()) {
5089 // Immediately fail if this was a DeclStmt, since it's very
5090 // likely that this will cause problems for future statements.
5091 if (isa<DeclStmt>(*B))
5092 return StmtError();
5093
5094 // Otherwise, just keep processing substatements and fail later.
5095 SubStmtInvalid = true;
5096 continue;
5097 }
Mike Stump1eb44332009-09-09 15:08:12 +00005098
Douglas Gregor43959a92009-08-20 07:17:43 +00005099 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5100 Statements.push_back(Result.takeAs<Stmt>());
5101 }
Mike Stump1eb44332009-09-09 15:08:12 +00005102
John McCall7114cba2010-08-27 19:56:05 +00005103 if (SubStmtInvalid)
5104 return StmtError();
5105
Douglas Gregor43959a92009-08-20 07:17:43 +00005106 if (!getDerived().AlwaysRebuild() &&
5107 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005108 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005109
5110 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005111 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005112 S->getRBracLoc(),
5113 IsStmtExpr);
5114}
Mike Stump1eb44332009-09-09 15:08:12 +00005115
Douglas Gregor43959a92009-08-20 07:17:43 +00005116template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005117StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005118TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005119 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005120 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005121 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5122 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005123
Eli Friedman264c1f82009-11-19 03:14:00 +00005124 // Transform the left-hand case value.
5125 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005126 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005127 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005128 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005129
Eli Friedman264c1f82009-11-19 03:14:00 +00005130 // Transform the right-hand case value (for the GNU case-range extension).
5131 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005132 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005133 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005134 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005135 }
Mike Stump1eb44332009-09-09 15:08:12 +00005136
Douglas Gregor43959a92009-08-20 07:17:43 +00005137 // Build the case statement.
5138 // Case statements are always rebuilt so that they will attached to their
5139 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005140 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005141 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005142 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005143 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005144 S->getColonLoc());
5145 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005146 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005147
Douglas Gregor43959a92009-08-20 07:17:43 +00005148 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005149 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005150 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005151 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005152
Douglas Gregor43959a92009-08-20 07:17:43 +00005153 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005154 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005155}
5156
5157template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005158StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005159TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005160 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005161 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005162 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005163 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005164
Douglas Gregor43959a92009-08-20 07:17:43 +00005165 // Default statements are always rebuilt
5166 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005167 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005168}
Mike Stump1eb44332009-09-09 15:08:12 +00005169
Douglas Gregor43959a92009-08-20 07:17:43 +00005170template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005171StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005172TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005173 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005174 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005175 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005176
Chris Lattner57ad3782011-02-17 20:34:02 +00005177 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5178 S->getDecl());
5179 if (!LD)
5180 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005181
5182
Douglas Gregor43959a92009-08-20 07:17:43 +00005183 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005184 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005185 cast<LabelDecl>(LD), SourceLocation(),
5186 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005187}
Mike Stump1eb44332009-09-09 15:08:12 +00005188
Douglas Gregor43959a92009-08-20 07:17:43 +00005189template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005190StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005191TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5192 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5193 if (SubStmt.isInvalid())
5194 return StmtError();
5195
5196 // TODO: transform attributes
5197 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5198 return S;
5199
5200 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5201 S->getAttrs(),
5202 SubStmt.get());
5203}
5204
5205template<typename Derived>
5206StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005207TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005208 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005209 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005210 VarDecl *ConditionVar = 0;
5211 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005212 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005213 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005214 getDerived().TransformDefinition(
5215 S->getConditionVariable()->getLocation(),
5216 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005217 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005218 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005219 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005220 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005221
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005222 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005223 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005224
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005225 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005226 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005227 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005228 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005229 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005230 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005231
John McCall9ae2f072010-08-23 23:25:46 +00005232 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005233 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005234 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005235
John McCall9ae2f072010-08-23 23:25:46 +00005236 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5237 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005238 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005239
Douglas Gregor43959a92009-08-20 07:17:43 +00005240 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005241 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005242 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005243 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005244
Douglas Gregor43959a92009-08-20 07:17:43 +00005245 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005246 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005247 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005248 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005249
Douglas Gregor43959a92009-08-20 07:17:43 +00005250 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005251 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005252 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005253 Then.get() == S->getThen() &&
5254 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005255 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005256
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005257 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005258 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005259 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005260}
5261
5262template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005263StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005264TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005265 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005266 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005267 VarDecl *ConditionVar = 0;
5268 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005269 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005270 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005271 getDerived().TransformDefinition(
5272 S->getConditionVariable()->getLocation(),
5273 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005274 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005275 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005276 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005277 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005278
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005279 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005280 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005281 }
Mike Stump1eb44332009-09-09 15:08:12 +00005282
Douglas Gregor43959a92009-08-20 07:17:43 +00005283 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005284 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005285 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005286 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005287 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005288 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005289
Douglas Gregor43959a92009-08-20 07:17:43 +00005290 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005291 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005292 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005293 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005294
Douglas Gregor43959a92009-08-20 07:17:43 +00005295 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005296 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5297 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005298}
Mike Stump1eb44332009-09-09 15:08:12 +00005299
Douglas Gregor43959a92009-08-20 07:17:43 +00005300template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005301StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005302TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005303 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005304 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005305 VarDecl *ConditionVar = 0;
5306 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005307 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005308 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005309 getDerived().TransformDefinition(
5310 S->getConditionVariable()->getLocation(),
5311 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005312 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005313 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005314 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005315 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005316
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005317 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005318 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005319
5320 if (S->getCond()) {
5321 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005322 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005323 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005324 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005325 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005326 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005327 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005328 }
Mike Stump1eb44332009-09-09 15:08:12 +00005329
John McCall9ae2f072010-08-23 23:25:46 +00005330 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5331 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005332 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005333
Douglas Gregor43959a92009-08-20 07:17:43 +00005334 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005335 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005336 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005337 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005338
Douglas Gregor43959a92009-08-20 07:17:43 +00005339 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005340 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005341 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005342 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005343 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005344
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005345 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005346 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005347}
Mike Stump1eb44332009-09-09 15:08:12 +00005348
Douglas Gregor43959a92009-08-20 07:17:43 +00005349template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005350StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005351TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005352 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005353 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005354 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005355 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005356
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005357 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005358 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005359 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005360 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005361
Douglas Gregor43959a92009-08-20 07:17:43 +00005362 if (!getDerived().AlwaysRebuild() &&
5363 Cond.get() == S->getCond() &&
5364 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005365 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005366
John McCall9ae2f072010-08-23 23:25:46 +00005367 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5368 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005369 S->getRParenLoc());
5370}
Mike Stump1eb44332009-09-09 15:08:12 +00005371
Douglas Gregor43959a92009-08-20 07:17:43 +00005372template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005373StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005374TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005375 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005376 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005377 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005378 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005379
Douglas Gregor43959a92009-08-20 07:17:43 +00005380 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005381 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005382 VarDecl *ConditionVar = 0;
5383 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005384 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005385 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005386 getDerived().TransformDefinition(
5387 S->getConditionVariable()->getLocation(),
5388 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005389 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005390 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005391 } else {
5392 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005393
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005394 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005395 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005396
5397 if (S->getCond()) {
5398 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005399 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005400 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005401 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005402 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005403
John McCall9ae2f072010-08-23 23:25:46 +00005404 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005405 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005406 }
Mike Stump1eb44332009-09-09 15:08:12 +00005407
Chad Rosier4a9d7952012-08-08 18:46:20 +00005408 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005409 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 increment
John McCall60d7b3a2010-08-24 06:29:42 +00005413 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005414 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005415 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005416
John McCall9ae2f072010-08-23 23:25:46 +00005417 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5418 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005419 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005420
Douglas Gregor43959a92009-08-20 07:17:43 +00005421 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005422 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005423 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005424 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005425
Douglas Gregor43959a92009-08-20 07:17:43 +00005426 if (!getDerived().AlwaysRebuild() &&
5427 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005428 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005429 Inc.get() == S->getInc() &&
5430 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005431 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005432
Douglas Gregor43959a92009-08-20 07:17:43 +00005433 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005434 Init.get(), FullCond, ConditionVar,
5435 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005436}
5437
5438template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005439StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005440TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005441 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5442 S->getLabel());
5443 if (!LD)
5444 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005445
Douglas Gregor43959a92009-08-20 07:17:43 +00005446 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005447 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005448 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005449}
5450
5451template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005452StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005453TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005454 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005455 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005456 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005457 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005458
Douglas Gregor43959a92009-08-20 07:17:43 +00005459 if (!getDerived().AlwaysRebuild() &&
5460 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005461 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005462
5463 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005464 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005465}
5466
5467template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005468StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005469TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005470 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005471}
Mike Stump1eb44332009-09-09 15:08:12 +00005472
Douglas Gregor43959a92009-08-20 07:17:43 +00005473template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005474StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005475TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005476 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005477}
Mike Stump1eb44332009-09-09 15:08:12 +00005478
Douglas Gregor43959a92009-08-20 07:17:43 +00005479template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005480StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005481TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005482 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005483 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005484 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005485
Mike Stump1eb44332009-09-09 15:08:12 +00005486 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005487 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005488 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005489}
Mike Stump1eb44332009-09-09 15:08:12 +00005490
Douglas Gregor43959a92009-08-20 07:17:43 +00005491template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005492StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005493TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005494 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005495 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005496 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5497 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005498 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5499 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005500 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005501 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005502
Douglas Gregor43959a92009-08-20 07:17:43 +00005503 if (Transformed != *D)
5504 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005505
Douglas Gregor43959a92009-08-20 07:17:43 +00005506 Decls.push_back(Transformed);
5507 }
Mike Stump1eb44332009-09-09 15:08:12 +00005508
Douglas Gregor43959a92009-08-20 07:17:43 +00005509 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005510 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005511
5512 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005513 S->getStartLoc(), S->getEndLoc());
5514}
Mike Stump1eb44332009-09-09 15:08:12 +00005515
Douglas Gregor43959a92009-08-20 07:17:43 +00005516template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005517StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005518TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005519
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005520 SmallVector<Expr*, 8> Constraints;
5521 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005522 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005523
John McCall60d7b3a2010-08-24 06:29:42 +00005524 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005525 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005526
5527 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005528
Anders Carlsson703e3942010-01-24 05:50:09 +00005529 // Go through the outputs.
5530 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005531 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005532
Anders Carlsson703e3942010-01-24 05:50:09 +00005533 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005534 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005535
Anders Carlsson703e3942010-01-24 05:50:09 +00005536 // Transform the output expr.
5537 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005538 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005539 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005540 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005541
Anders Carlsson703e3942010-01-24 05:50:09 +00005542 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005543
John McCall9ae2f072010-08-23 23:25:46 +00005544 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005545 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005546
Anders Carlsson703e3942010-01-24 05:50:09 +00005547 // Go through the inputs.
5548 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005549 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005550
Anders Carlsson703e3942010-01-24 05:50:09 +00005551 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005552 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005553
Anders Carlsson703e3942010-01-24 05:50:09 +00005554 // Transform the input expr.
5555 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005556 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005557 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005558 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005559
Anders Carlsson703e3942010-01-24 05:50:09 +00005560 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005561
John McCall9ae2f072010-08-23 23:25:46 +00005562 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005563 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005564
Anders Carlsson703e3942010-01-24 05:50:09 +00005565 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005566 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005567
5568 // Go through the clobbers.
5569 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005570 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005571
5572 // No need to transform the asm string literal.
5573 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005574 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5575 S->isVolatile(), S->getNumOutputs(),
5576 S->getNumInputs(), Names.data(),
5577 Constraints, Exprs, AsmString.get(),
5578 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005579}
5580
Chad Rosier8cd64b42012-06-11 20:47:18 +00005581template<typename Derived>
5582StmtResult
5583TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005584 ArrayRef<Token> AsmToks =
5585 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005586
Chad Rosier7bd092b2012-08-15 16:53:30 +00005587 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
5588 AsmToks, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005589}
Douglas Gregor43959a92009-08-20 07:17:43 +00005590
5591template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005592StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005593TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005594 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005595 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005596 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005597 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005598
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005599 // Transform the @catch statements (if present).
5600 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005601 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005602 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005603 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005604 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005605 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005606 if (Catch.get() != S->getCatchStmt(I))
5607 AnyCatchChanged = true;
5608 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005609 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005610
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005611 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005612 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005613 if (S->getFinallyStmt()) {
5614 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5615 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005616 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005617 }
5618
5619 // If nothing changed, just retain this statement.
5620 if (!getDerived().AlwaysRebuild() &&
5621 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005622 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005623 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005624 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005625
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005626 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005627 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005628 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005629}
Mike Stump1eb44332009-09-09 15:08:12 +00005630
Douglas Gregor43959a92009-08-20 07:17:43 +00005631template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005632StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005633TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005634 // Transform the @catch parameter, if there is one.
5635 VarDecl *Var = 0;
5636 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5637 TypeSourceInfo *TSInfo = 0;
5638 if (FromVar->getTypeSourceInfo()) {
5639 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5640 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005641 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005642 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005643
Douglas Gregorbe270a02010-04-26 17:57:08 +00005644 QualType T;
5645 if (TSInfo)
5646 T = TSInfo->getType();
5647 else {
5648 T = getDerived().TransformType(FromVar->getType());
5649 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005650 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005651 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005652
Douglas Gregorbe270a02010-04-26 17:57:08 +00005653 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5654 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005655 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005656 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005657
John McCall60d7b3a2010-08-24 06:29:42 +00005658 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005659 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005660 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005661
5662 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005663 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005664 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005665}
Mike Stump1eb44332009-09-09 15:08:12 +00005666
Douglas Gregor43959a92009-08-20 07:17:43 +00005667template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005668StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005669TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005670 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005671 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005672 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005673 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005674
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005675 // If nothing changed, just retain this statement.
5676 if (!getDerived().AlwaysRebuild() &&
5677 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005678 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005679
5680 // Build a new statement.
5681 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005682 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005683}
Mike Stump1eb44332009-09-09 15:08:12 +00005684
Douglas Gregor43959a92009-08-20 07:17:43 +00005685template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005686StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005687TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005688 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005689 if (S->getThrowExpr()) {
5690 Operand = getDerived().TransformExpr(S->getThrowExpr());
5691 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005692 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005693 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005694
Douglas Gregord1377b22010-04-22 21:44:01 +00005695 if (!getDerived().AlwaysRebuild() &&
5696 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005697 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005698
John McCall9ae2f072010-08-23 23:25:46 +00005699 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005700}
Mike Stump1eb44332009-09-09 15:08:12 +00005701
Douglas Gregor43959a92009-08-20 07:17:43 +00005702template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005703StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005704TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005705 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005706 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005707 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005708 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005709 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005710 Object =
5711 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5712 Object.get());
5713 if (Object.isInvalid())
5714 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005715
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005716 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005717 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005718 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005719 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005720
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005721 // If nothing change, just retain the current statement.
5722 if (!getDerived().AlwaysRebuild() &&
5723 Object.get() == S->getSynchExpr() &&
5724 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005725 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005726
5727 // Build a new statement.
5728 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005729 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005730}
5731
5732template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005733StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005734TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5735 ObjCAutoreleasePoolStmt *S) {
5736 // Transform the body.
5737 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5738 if (Body.isInvalid())
5739 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005740
John McCallf85e1932011-06-15 23:02:42 +00005741 // If nothing changed, just retain this statement.
5742 if (!getDerived().AlwaysRebuild() &&
5743 Body.get() == S->getSubStmt())
5744 return SemaRef.Owned(S);
5745
5746 // Build a new statement.
5747 return getDerived().RebuildObjCAutoreleasePoolStmt(
5748 S->getAtLoc(), Body.get());
5749}
5750
5751template<typename Derived>
5752StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005753TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005754 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005755 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005756 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005757 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005758 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005759
Douglas Gregorc3203e72010-04-22 23:10:45 +00005760 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005761 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005762 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005763 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005764
Douglas Gregorc3203e72010-04-22 23:10:45 +00005765 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005766 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005767 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005768 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005769
Douglas Gregorc3203e72010-04-22 23:10:45 +00005770 // If nothing changed, just retain this statement.
5771 if (!getDerived().AlwaysRebuild() &&
5772 Element.get() == S->getElement() &&
5773 Collection.get() == S->getCollection() &&
5774 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005775 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005776
Douglas Gregorc3203e72010-04-22 23:10:45 +00005777 // Build a new statement.
5778 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005779 Element.get(),
5780 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005781 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005782 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005783}
5784
5785
5786template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005787StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005788TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5789 // Transform the exception declaration, if any.
5790 VarDecl *Var = 0;
5791 if (S->getExceptionDecl()) {
5792 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005793 TypeSourceInfo *T = getDerived().TransformType(
5794 ExceptionDecl->getTypeSourceInfo());
5795 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005796 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005797
Douglas Gregor83cb9422010-09-09 17:09:21 +00005798 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005799 ExceptionDecl->getInnerLocStart(),
5800 ExceptionDecl->getLocation(),
5801 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005802 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005803 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005804 }
Mike Stump1eb44332009-09-09 15:08:12 +00005805
Douglas Gregor43959a92009-08-20 07:17:43 +00005806 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005807 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005808 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005809 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005810
Douglas Gregor43959a92009-08-20 07:17:43 +00005811 if (!getDerived().AlwaysRebuild() &&
5812 !Var &&
5813 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005814 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005815
5816 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5817 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005818 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005819}
Mike Stump1eb44332009-09-09 15:08:12 +00005820
Douglas Gregor43959a92009-08-20 07:17:43 +00005821template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005822StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005823TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5824 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005825 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005826 = getDerived().TransformCompoundStmt(S->getTryBlock());
5827 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005828 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005829
Douglas Gregor43959a92009-08-20 07:17:43 +00005830 // Transform the handlers.
5831 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005832 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00005833 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005834 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005835 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5836 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005837 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005838
Douglas Gregor43959a92009-08-20 07:17:43 +00005839 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5840 Handlers.push_back(Handler.takeAs<Stmt>());
5841 }
Mike Stump1eb44332009-09-09 15:08:12 +00005842
Douglas Gregor43959a92009-08-20 07:17:43 +00005843 if (!getDerived().AlwaysRebuild() &&
5844 TryBlock.get() == S->getTryBlock() &&
5845 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005846 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005847
John McCall9ae2f072010-08-23 23:25:46 +00005848 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005849 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00005850}
Mike Stump1eb44332009-09-09 15:08:12 +00005851
Richard Smithad762fc2011-04-14 22:09:26 +00005852template<typename Derived>
5853StmtResult
5854TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5855 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5856 if (Range.isInvalid())
5857 return StmtError();
5858
5859 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5860 if (BeginEnd.isInvalid())
5861 return StmtError();
5862
5863 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5864 if (Cond.isInvalid())
5865 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005866 if (Cond.get())
5867 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5868 if (Cond.isInvalid())
5869 return StmtError();
5870 if (Cond.get())
5871 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005872
5873 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5874 if (Inc.isInvalid())
5875 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005876 if (Inc.get())
5877 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005878
5879 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5880 if (LoopVar.isInvalid())
5881 return StmtError();
5882
5883 StmtResult NewStmt = S;
5884 if (getDerived().AlwaysRebuild() ||
5885 Range.get() != S->getRangeStmt() ||
5886 BeginEnd.get() != S->getBeginEndStmt() ||
5887 Cond.get() != S->getCond() ||
5888 Inc.get() != S->getInc() ||
5889 LoopVar.get() != S->getLoopVarStmt())
5890 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5891 S->getColonLoc(), Range.get(),
5892 BeginEnd.get(), Cond.get(),
5893 Inc.get(), LoopVar.get(),
5894 S->getRParenLoc());
5895
5896 StmtResult Body = getDerived().TransformStmt(S->getBody());
5897 if (Body.isInvalid())
5898 return StmtError();
5899
5900 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5901 // it now so we have a new statement to attach the body to.
5902 if (Body.get() != S->getBody() && NewStmt.get() == S)
5903 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5904 S->getColonLoc(), Range.get(),
5905 BeginEnd.get(), Cond.get(),
5906 Inc.get(), LoopVar.get(),
5907 S->getRParenLoc());
5908
5909 if (NewStmt.get() == S)
5910 return SemaRef.Owned(S);
5911
5912 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5913}
5914
John Wiegley28bbe4b2011-04-28 01:08:34 +00005915template<typename Derived>
5916StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005917TreeTransform<Derived>::TransformMSDependentExistsStmt(
5918 MSDependentExistsStmt *S) {
5919 // Transform the nested-name-specifier, if any.
5920 NestedNameSpecifierLoc QualifierLoc;
5921 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005922 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00005923 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5924 if (!QualifierLoc)
5925 return StmtError();
5926 }
5927
5928 // Transform the declaration name.
5929 DeclarationNameInfo NameInfo = S->getNameInfo();
5930 if (NameInfo.getName()) {
5931 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5932 if (!NameInfo.getName())
5933 return StmtError();
5934 }
5935
5936 // Check whether anything changed.
5937 if (!getDerived().AlwaysRebuild() &&
5938 QualifierLoc == S->getQualifierLoc() &&
5939 NameInfo.getName() == S->getNameInfo().getName())
5940 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005941
Douglas Gregorba0513d2011-10-25 01:33:02 +00005942 // Determine whether this name exists, if we can.
5943 CXXScopeSpec SS;
5944 SS.Adopt(QualifierLoc);
5945 bool Dependent = false;
5946 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5947 case Sema::IER_Exists:
5948 if (S->isIfExists())
5949 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005950
Douglas Gregorba0513d2011-10-25 01:33:02 +00005951 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5952
5953 case Sema::IER_DoesNotExist:
5954 if (S->isIfNotExists())
5955 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005956
Douglas Gregorba0513d2011-10-25 01:33:02 +00005957 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005958
Douglas Gregorba0513d2011-10-25 01:33:02 +00005959 case Sema::IER_Dependent:
5960 Dependent = true;
5961 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005962
Douglas Gregor65019ac2011-10-25 03:44:56 +00005963 case Sema::IER_Error:
5964 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005965 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005966
Douglas Gregorba0513d2011-10-25 01:33:02 +00005967 // We need to continue with the instantiation, so do so now.
5968 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5969 if (SubStmt.isInvalid())
5970 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005971
Douglas Gregorba0513d2011-10-25 01:33:02 +00005972 // If we have resolved the name, just transform to the substatement.
5973 if (!Dependent)
5974 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005975
Douglas Gregorba0513d2011-10-25 01:33:02 +00005976 // The name is still dependent, so build a dependent expression again.
5977 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5978 S->isIfExists(),
5979 QualifierLoc,
5980 NameInfo,
5981 SubStmt.get());
5982}
5983
5984template<typename Derived>
5985StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00005986TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5987 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5988 if(TryBlock.isInvalid()) return StmtError();
5989
5990 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5991 if(!getDerived().AlwaysRebuild() &&
5992 TryBlock.get() == S->getTryBlock() &&
5993 Handler.get() == S->getHandler())
5994 return SemaRef.Owned(S);
5995
5996 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5997 S->getTryLoc(),
5998 TryBlock.take(),
5999 Handler.take());
6000}
6001
6002template<typename Derived>
6003StmtResult
6004TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6005 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6006 if(Block.isInvalid()) return StmtError();
6007
6008 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6009 Block.take());
6010}
6011
6012template<typename Derived>
6013StmtResult
6014TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6015 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6016 if(FilterExpr.isInvalid()) return StmtError();
6017
6018 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6019 if(Block.isInvalid()) return StmtError();
6020
6021 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6022 FilterExpr.take(),
6023 Block.take());
6024}
6025
6026template<typename Derived>
6027StmtResult
6028TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6029 if(isa<SEHFinallyStmt>(Handler))
6030 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6031 else
6032 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6033}
6034
Douglas Gregor43959a92009-08-20 07:17:43 +00006035//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006036// Expression transformation
6037//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006038template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006039ExprResult
John McCall454feb92009-12-08 09:21:05 +00006040TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006041 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006042}
Mike Stump1eb44332009-09-09 15:08:12 +00006043
6044template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006045ExprResult
John McCall454feb92009-12-08 09:21:05 +00006046TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006047 NestedNameSpecifierLoc QualifierLoc;
6048 if (E->getQualifierLoc()) {
6049 QualifierLoc
6050 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6051 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006052 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006053 }
John McCalldbd872f2009-12-08 09:08:17 +00006054
6055 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006056 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6057 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006058 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006059 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006060
John McCallec8045d2010-08-17 21:27:17 +00006061 DeclarationNameInfo NameInfo = E->getNameInfo();
6062 if (NameInfo.getName()) {
6063 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6064 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006065 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006066 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006067
6068 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006069 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006070 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006071 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006072 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006073
6074 // Mark it referenced in the new context regardless.
6075 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006076 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006077
John McCall3fa5cae2010-10-26 07:05:15 +00006078 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006079 }
John McCalldbd872f2009-12-08 09:08:17 +00006080
6081 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006082 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006083 TemplateArgs = &TransArgs;
6084 TransArgs.setLAngleLoc(E->getLAngleLoc());
6085 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006086 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6087 E->getNumTemplateArgs(),
6088 TransArgs))
6089 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006090 }
6091
Chad Rosier4a9d7952012-08-08 18:46:20 +00006092 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006093 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006094}
Mike Stump1eb44332009-09-09 15:08:12 +00006095
Douglas Gregorb98b1992009-08-11 05:31:07 +00006096template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006097ExprResult
John McCall454feb92009-12-08 09:21:05 +00006098TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006099 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006100}
Mike Stump1eb44332009-09-09 15:08:12 +00006101
Douglas Gregorb98b1992009-08-11 05:31:07 +00006102template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006103ExprResult
John McCall454feb92009-12-08 09:21:05 +00006104TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006105 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006106}
Mike Stump1eb44332009-09-09 15:08:12 +00006107
Douglas Gregorb98b1992009-08-11 05:31:07 +00006108template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006109ExprResult
John McCall454feb92009-12-08 09:21:05 +00006110TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006111 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006112}
Mike Stump1eb44332009-09-09 15:08:12 +00006113
Douglas Gregorb98b1992009-08-11 05:31:07 +00006114template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006115ExprResult
John McCall454feb92009-12-08 09:21:05 +00006116TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006117 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006118}
Mike Stump1eb44332009-09-09 15:08:12 +00006119
Douglas Gregorb98b1992009-08-11 05:31:07 +00006120template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006121ExprResult
John McCall454feb92009-12-08 09:21:05 +00006122TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006123 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006124}
6125
6126template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006127ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006128TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6129 return SemaRef.MaybeBindToTemporary(E);
6130}
6131
6132template<typename Derived>
6133ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006134TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6135 ExprResult ControllingExpr =
6136 getDerived().TransformExpr(E->getControllingExpr());
6137 if (ControllingExpr.isInvalid())
6138 return ExprError();
6139
Chris Lattner686775d2011-07-20 06:58:45 +00006140 SmallVector<Expr *, 4> AssocExprs;
6141 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006142 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6143 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6144 if (TS) {
6145 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6146 if (!AssocType)
6147 return ExprError();
6148 AssocTypes.push_back(AssocType);
6149 } else {
6150 AssocTypes.push_back(0);
6151 }
6152
6153 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6154 if (AssocExpr.isInvalid())
6155 return ExprError();
6156 AssocExprs.push_back(AssocExpr.release());
6157 }
6158
6159 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6160 E->getDefaultLoc(),
6161 E->getRParenLoc(),
6162 ControllingExpr.release(),
6163 AssocTypes.data(),
6164 AssocExprs.data(),
6165 E->getNumAssocs());
6166}
6167
6168template<typename Derived>
6169ExprResult
John McCall454feb92009-12-08 09:21:05 +00006170TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006171 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006172 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006173 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006174
Douglas Gregorb98b1992009-08-11 05:31:07 +00006175 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006176 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006177
John McCall9ae2f072010-08-23 23:25:46 +00006178 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006179 E->getRParen());
6180}
6181
Mike Stump1eb44332009-09-09 15:08:12 +00006182template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006183ExprResult
John McCall454feb92009-12-08 09:21:05 +00006184TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006185 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006186 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006187 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006188
Douglas Gregorb98b1992009-08-11 05:31:07 +00006189 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006190 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006191
Douglas Gregorb98b1992009-08-11 05:31:07 +00006192 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6193 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006194 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006195}
Mike Stump1eb44332009-09-09 15:08:12 +00006196
Douglas Gregorb98b1992009-08-11 05:31:07 +00006197template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006198ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006199TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6200 // Transform the type.
6201 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6202 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006203 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006204
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006205 // Transform all of the components into components similar to what the
6206 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006207 // FIXME: It would be slightly more efficient in the non-dependent case to
6208 // just map FieldDecls, rather than requiring the rebuilder to look for
6209 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006210 // template code that we don't care.
6211 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006212 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006213 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006214 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006215 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6216 const Node &ON = E->getComponent(I);
6217 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006218 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006219 Comp.LocStart = ON.getSourceRange().getBegin();
6220 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006221 switch (ON.getKind()) {
6222 case Node::Array: {
6223 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006224 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006225 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006226 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006227
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006228 ExprChanged = ExprChanged || Index.get() != FromIndex;
6229 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006230 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006231 break;
6232 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006233
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006234 case Node::Field:
6235 case Node::Identifier:
6236 Comp.isBrackets = false;
6237 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006238 if (!Comp.U.IdentInfo)
6239 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006240
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006241 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006242
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006243 case Node::Base:
6244 // Will be recomputed during the rebuild.
6245 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006246 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006247
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006248 Components.push_back(Comp);
6249 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006250
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006251 // If nothing changed, retain the existing expression.
6252 if (!getDerived().AlwaysRebuild() &&
6253 Type == E->getTypeSourceInfo() &&
6254 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006255 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006256
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006257 // Build a new offsetof expression.
6258 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6259 Components.data(), Components.size(),
6260 E->getRParenLoc());
6261}
6262
6263template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006264ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006265TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6266 assert(getDerived().AlreadyTransformed(E->getType()) &&
6267 "opaque value expression requires transformation");
6268 return SemaRef.Owned(E);
6269}
6270
6271template<typename Derived>
6272ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006273TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006274 // Rebuild the syntactic form. The original syntactic form has
6275 // opaque-value expressions in it, so strip those away and rebuild
6276 // the result. This is a really awful way of doing this, but the
6277 // better solution (rebuilding the semantic expressions and
6278 // rebinding OVEs as necessary) doesn't work; we'd need
6279 // TreeTransform to not strip away implicit conversions.
6280 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6281 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006282 if (result.isInvalid()) return ExprError();
6283
6284 // If that gives us a pseudo-object result back, the pseudo-object
6285 // expression must have been an lvalue-to-rvalue conversion which we
6286 // should reapply.
6287 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6288 result = SemaRef.checkPseudoObjectRValue(result.take());
6289
6290 return result;
6291}
6292
6293template<typename Derived>
6294ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006295TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6296 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006297 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006298 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006299
John McCalla93c9342009-12-07 02:54:59 +00006300 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006301 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006302 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006303
John McCall5ab75172009-11-04 07:28:41 +00006304 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006305 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006306
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006307 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6308 E->getKind(),
6309 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006310 }
Mike Stump1eb44332009-09-09 15:08:12 +00006311
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006312 // C++0x [expr.sizeof]p1:
6313 // The operand is either an expression, which is an unevaluated operand
6314 // [...]
6315 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006316
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006317 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6318 if (SubExpr.isInvalid())
6319 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006320
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006321 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6322 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006323
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006324 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6325 E->getOperatorLoc(),
6326 E->getKind(),
6327 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006328}
Mike Stump1eb44332009-09-09 15:08:12 +00006329
Douglas Gregorb98b1992009-08-11 05:31:07 +00006330template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006331ExprResult
John McCall454feb92009-12-08 09:21:05 +00006332TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006333 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006334 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006335 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006336
John McCall60d7b3a2010-08-24 06:29:42 +00006337 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006338 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006339 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006340
6341
Douglas Gregorb98b1992009-08-11 05:31:07 +00006342 if (!getDerived().AlwaysRebuild() &&
6343 LHS.get() == E->getLHS() &&
6344 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006345 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006346
John McCall9ae2f072010-08-23 23:25:46 +00006347 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006348 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006349 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006350 E->getRBracketLoc());
6351}
Mike Stump1eb44332009-09-09 15:08:12 +00006352
6353template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006354ExprResult
John McCall454feb92009-12-08 09:21:05 +00006355TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006356 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006357 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006358 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006359 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006360
6361 // Transform arguments.
6362 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006363 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006364 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006365 &ArgChanged))
6366 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006367
Douglas Gregorb98b1992009-08-11 05:31:07 +00006368 if (!getDerived().AlwaysRebuild() &&
6369 Callee.get() == E->getCallee() &&
6370 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006371 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006372
Douglas Gregorb98b1992009-08-11 05:31:07 +00006373 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006374 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006375 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006376 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006377 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006378 E->getRParenLoc());
6379}
Mike Stump1eb44332009-09-09 15:08:12 +00006380
6381template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006382ExprResult
John McCall454feb92009-12-08 09:21:05 +00006383TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006384 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006385 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006386 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006387
Douglas Gregor40d96a62011-02-28 21:54:11 +00006388 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006389 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006390 QualifierLoc
6391 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006392
Douglas Gregor40d96a62011-02-28 21:54:11 +00006393 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006394 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006395 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006396 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006397
Eli Friedmanf595cc42009-12-04 06:40:45 +00006398 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006399 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6400 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006401 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006402 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006403
John McCall6bb80172010-03-30 21:47:33 +00006404 NamedDecl *FoundDecl = E->getFoundDecl();
6405 if (FoundDecl == E->getMemberDecl()) {
6406 FoundDecl = Member;
6407 } else {
6408 FoundDecl = cast_or_null<NamedDecl>(
6409 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6410 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006411 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006412 }
6413
Douglas Gregorb98b1992009-08-11 05:31:07 +00006414 if (!getDerived().AlwaysRebuild() &&
6415 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006416 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006417 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006418 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006419 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006420
Anders Carlsson1f240322009-12-22 05:24:09 +00006421 // Mark it referenced in the new context regardless.
6422 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006423 SemaRef.MarkMemberReferenced(E);
6424
John McCall3fa5cae2010-10-26 07:05:15 +00006425 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006426 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006427
John McCalld5532b62009-11-23 01:53:49 +00006428 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006429 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006430 TransArgs.setLAngleLoc(E->getLAngleLoc());
6431 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006432 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6433 E->getNumTemplateArgs(),
6434 TransArgs))
6435 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006436 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006437
Douglas Gregorb98b1992009-08-11 05:31:07 +00006438 // FIXME: Bogus source location for the operator
6439 SourceLocation FakeOperatorLoc
6440 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6441
John McCallc2233c52010-01-15 08:34:02 +00006442 // FIXME: to do this check properly, we will need to preserve the
6443 // first-qualifier-in-scope here, just in case we had a dependent
6444 // base (and therefore couldn't do the check) and a
6445 // nested-name-qualifier (and therefore could do the lookup).
6446 NamedDecl *FirstQualifierInScope = 0;
6447
John McCall9ae2f072010-08-23 23:25:46 +00006448 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006449 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006450 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006451 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006452 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006453 Member,
John McCall6bb80172010-03-30 21:47:33 +00006454 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006455 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006456 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006457 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006458}
Mike Stump1eb44332009-09-09 15:08:12 +00006459
Douglas Gregorb98b1992009-08-11 05:31:07 +00006460template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006461ExprResult
John McCall454feb92009-12-08 09:21:05 +00006462TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006463 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006464 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006465 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006466
John McCall60d7b3a2010-08-24 06:29:42 +00006467 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006468 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006469 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006470
Douglas Gregorb98b1992009-08-11 05:31:07 +00006471 if (!getDerived().AlwaysRebuild() &&
6472 LHS.get() == E->getLHS() &&
6473 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006474 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006475
Douglas Gregorb98b1992009-08-11 05:31:07 +00006476 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006477 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006478}
6479
Mike Stump1eb44332009-09-09 15:08:12 +00006480template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006481ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006482TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006483 CompoundAssignOperator *E) {
6484 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006485}
Mike Stump1eb44332009-09-09 15:08:12 +00006486
Douglas Gregorb98b1992009-08-11 05:31:07 +00006487template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006488ExprResult TreeTransform<Derived>::
6489TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6490 // Just rebuild the common and RHS expressions and see whether we
6491 // get any changes.
6492
6493 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6494 if (commonExpr.isInvalid())
6495 return ExprError();
6496
6497 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6498 if (rhs.isInvalid())
6499 return ExprError();
6500
6501 if (!getDerived().AlwaysRebuild() &&
6502 commonExpr.get() == e->getCommon() &&
6503 rhs.get() == e->getFalseExpr())
6504 return SemaRef.Owned(e);
6505
6506 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6507 e->getQuestionLoc(),
6508 0,
6509 e->getColonLoc(),
6510 rhs.get());
6511}
6512
6513template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006514ExprResult
John McCall454feb92009-12-08 09:21:05 +00006515TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006516 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006517 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006518 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006519
John McCall60d7b3a2010-08-24 06:29:42 +00006520 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006521 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006522 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006523
John McCall60d7b3a2010-08-24 06:29:42 +00006524 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006525 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006526 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006527
Douglas Gregorb98b1992009-08-11 05:31:07 +00006528 if (!getDerived().AlwaysRebuild() &&
6529 Cond.get() == E->getCond() &&
6530 LHS.get() == E->getLHS() &&
6531 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006532 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006533
John McCall9ae2f072010-08-23 23:25:46 +00006534 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006535 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006536 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006537 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006538 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006539}
Mike Stump1eb44332009-09-09 15:08:12 +00006540
6541template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006542ExprResult
John McCall454feb92009-12-08 09:21:05 +00006543TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006544 // Implicit casts are eliminated during transformation, since they
6545 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006546 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006547}
Mike Stump1eb44332009-09-09 15:08:12 +00006548
Douglas Gregorb98b1992009-08-11 05:31:07 +00006549template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006550ExprResult
John McCall454feb92009-12-08 09:21:05 +00006551TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006552 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6553 if (!Type)
6554 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006555
John McCall60d7b3a2010-08-24 06:29:42 +00006556 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006557 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006558 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006559 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006560
Douglas Gregorb98b1992009-08-11 05:31:07 +00006561 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006562 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006563 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006564 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006565
John McCall9d125032010-01-15 18:39:57 +00006566 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006567 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006568 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006569 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006570}
Mike Stump1eb44332009-09-09 15:08:12 +00006571
Douglas Gregorb98b1992009-08-11 05:31:07 +00006572template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006573ExprResult
John McCall454feb92009-12-08 09:21:05 +00006574TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006575 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6576 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6577 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006578 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006579
John McCall60d7b3a2010-08-24 06:29:42 +00006580 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006581 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006582 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006583
Douglas Gregorb98b1992009-08-11 05:31:07 +00006584 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006585 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006586 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006587 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006588
John McCall1d7d8d62010-01-19 22:33:45 +00006589 // Note: the expression type doesn't necessarily match the
6590 // type-as-written, but that's okay, because it should always be
6591 // derivable from the initializer.
6592
John McCall42f56b52010-01-18 19:35:47 +00006593 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006594 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006595 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006596}
Mike Stump1eb44332009-09-09 15:08:12 +00006597
Douglas Gregorb98b1992009-08-11 05:31:07 +00006598template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006599ExprResult
John McCall454feb92009-12-08 09:21:05 +00006600TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006601 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006602 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006603 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006604
Douglas Gregorb98b1992009-08-11 05:31:07 +00006605 if (!getDerived().AlwaysRebuild() &&
6606 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006607 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006608
Douglas Gregorb98b1992009-08-11 05:31:07 +00006609 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006610 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006611 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006612 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006613 E->getAccessorLoc(),
6614 E->getAccessor());
6615}
Mike Stump1eb44332009-09-09 15:08:12 +00006616
Douglas Gregorb98b1992009-08-11 05:31:07 +00006617template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006618ExprResult
John McCall454feb92009-12-08 09:21:05 +00006619TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006620 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006621
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006622 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006623 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006624 Inits, &InitChanged))
6625 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006626
Douglas Gregorb98b1992009-08-11 05:31:07 +00006627 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006628 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006629
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006630 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006631 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006632}
Mike Stump1eb44332009-09-09 15:08:12 +00006633
Douglas Gregorb98b1992009-08-11 05:31:07 +00006634template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006635ExprResult
John McCall454feb92009-12-08 09:21:05 +00006636TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006637 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006638
Douglas Gregor43959a92009-08-20 07:17:43 +00006639 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006640 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006641 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006642 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006643
Douglas Gregor43959a92009-08-20 07:17:43 +00006644 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006645 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006646 bool ExprChanged = false;
6647 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6648 DEnd = E->designators_end();
6649 D != DEnd; ++D) {
6650 if (D->isFieldDesignator()) {
6651 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6652 D->getDotLoc(),
6653 D->getFieldLoc()));
6654 continue;
6655 }
Mike Stump1eb44332009-09-09 15:08:12 +00006656
Douglas Gregorb98b1992009-08-11 05:31:07 +00006657 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006658 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006659 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006660 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006661
6662 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006663 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006664
Douglas Gregorb98b1992009-08-11 05:31:07 +00006665 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6666 ArrayExprs.push_back(Index.release());
6667 continue;
6668 }
Mike Stump1eb44332009-09-09 15:08:12 +00006669
Douglas Gregorb98b1992009-08-11 05:31:07 +00006670 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006671 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006672 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6673 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006674 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006675
John McCall60d7b3a2010-08-24 06:29:42 +00006676 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006677 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006678 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006679
6680 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006681 End.get(),
6682 D->getLBracketLoc(),
6683 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006684
Douglas Gregorb98b1992009-08-11 05:31:07 +00006685 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6686 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006687
Douglas Gregorb98b1992009-08-11 05:31:07 +00006688 ArrayExprs.push_back(Start.release());
6689 ArrayExprs.push_back(End.release());
6690 }
Mike Stump1eb44332009-09-09 15:08:12 +00006691
Douglas Gregorb98b1992009-08-11 05:31:07 +00006692 if (!getDerived().AlwaysRebuild() &&
6693 Init.get() == E->getInit() &&
6694 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006695 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006696
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006697 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006698 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006699 E->usesGNUSyntax(), Init.get());
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
Douglas Gregorb98b1992009-08-11 05:31:07 +00006704TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006705 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006706 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006707
Douglas Gregor5557b252009-10-28 00:29:27 +00006708 // FIXME: Will we ever have proper type location here? Will we actually
6709 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006710 QualType T = getDerived().TransformType(E->getType());
6711 if (T.isNull())
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() &&
6715 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006716 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006717
Douglas Gregorb98b1992009-08-11 05:31:07 +00006718 return getDerived().RebuildImplicitValueInitExpr(T);
6719}
Mike Stump1eb44332009-09-09 15:08:12 +00006720
Douglas Gregorb98b1992009-08-11 05:31:07 +00006721template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006722ExprResult
John McCall454feb92009-12-08 09:21:05 +00006723TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006724 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6725 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006726 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006727
John McCall60d7b3a2010-08-24 06:29:42 +00006728 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006729 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006730 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006731
Douglas Gregorb98b1992009-08-11 05:31:07 +00006732 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006733 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006734 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006735 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006736
John McCall9ae2f072010-08-23 23:25:46 +00006737 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006738 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006739}
6740
6741template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006742ExprResult
John McCall454feb92009-12-08 09:21:05 +00006743TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006744 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006745 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00006746 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6747 &ArgumentChanged))
6748 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006749
Douglas Gregorb98b1992009-08-11 05:31:07 +00006750 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006751 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006752 E->getRParenLoc());
6753}
Mike Stump1eb44332009-09-09 15:08:12 +00006754
Douglas Gregorb98b1992009-08-11 05:31:07 +00006755/// \brief Transform an address-of-label expression.
6756///
6757/// By default, the transformation of an address-of-label expression always
6758/// rebuilds the expression, so that the label identifier can be resolved to
6759/// the corresponding label statement by semantic analysis.
6760template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006761ExprResult
John McCall454feb92009-12-08 09:21:05 +00006762TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006763 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6764 E->getLabel());
6765 if (!LD)
6766 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006767
Douglas Gregorb98b1992009-08-11 05:31:07 +00006768 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006769 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006770}
Mike Stump1eb44332009-09-09 15:08:12 +00006771
6772template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006773ExprResult
John McCall454feb92009-12-08 09:21:05 +00006774TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006775 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006776 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006777 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006778 if (SubStmt.isInvalid()) {
6779 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006780 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006781 }
Mike Stump1eb44332009-09-09 15:08:12 +00006782
Douglas Gregorb98b1992009-08-11 05:31:07 +00006783 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006784 SubStmt.get() == E->getSubStmt()) {
6785 // Calling this an 'error' is unintuitive, but it does the right thing.
6786 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006787 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006788 }
Mike Stump1eb44332009-09-09 15:08:12 +00006789
6790 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006791 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006792 E->getRParenLoc());
6793}
Mike Stump1eb44332009-09-09 15:08:12 +00006794
Douglas Gregorb98b1992009-08-11 05:31:07 +00006795template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006796ExprResult
John McCall454feb92009-12-08 09:21:05 +00006797TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006798 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006799 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006800 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006801
John McCall60d7b3a2010-08-24 06:29:42 +00006802 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006803 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006804 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006805
John McCall60d7b3a2010-08-24 06:29:42 +00006806 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006807 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006808 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006809
Douglas Gregorb98b1992009-08-11 05:31:07 +00006810 if (!getDerived().AlwaysRebuild() &&
6811 Cond.get() == E->getCond() &&
6812 LHS.get() == E->getLHS() &&
6813 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006814 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006815
Douglas Gregorb98b1992009-08-11 05:31:07 +00006816 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006817 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006818 E->getRParenLoc());
6819}
Mike Stump1eb44332009-09-09 15:08:12 +00006820
Douglas Gregorb98b1992009-08-11 05:31:07 +00006821template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006822ExprResult
John McCall454feb92009-12-08 09:21:05 +00006823TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006824 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006825}
6826
6827template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006828ExprResult
John McCall454feb92009-12-08 09:21:05 +00006829TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006830 switch (E->getOperator()) {
6831 case OO_New:
6832 case OO_Delete:
6833 case OO_Array_New:
6834 case OO_Array_Delete:
6835 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006836
Douglas Gregor668d6d92009-12-13 20:44:55 +00006837 case OO_Call: {
6838 // This is a call to an object's operator().
6839 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6840
6841 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006842 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006843 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006844 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006845
6846 // FIXME: Poor location information
6847 SourceLocation FakeLParenLoc
6848 = SemaRef.PP.getLocForEndOfToken(
6849 static_cast<Expr *>(Object.get())->getLocEnd());
6850
6851 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006852 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006853 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006854 Args))
6855 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006856
John McCall9ae2f072010-08-23 23:25:46 +00006857 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006858 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006859 E->getLocEnd());
6860 }
6861
6862#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6863 case OO_##Name:
6864#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6865#include "clang/Basic/OperatorKinds.def"
6866 case OO_Subscript:
6867 // Handled below.
6868 break;
6869
6870 case OO_Conditional:
6871 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006872
6873 case OO_None:
6874 case NUM_OVERLOADED_OPERATORS:
6875 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006876 }
6877
John McCall60d7b3a2010-08-24 06:29:42 +00006878 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006879 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006880 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006881
John McCall60d7b3a2010-08-24 06:29:42 +00006882 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006883 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006884 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006885
John McCall60d7b3a2010-08-24 06:29:42 +00006886 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006887 if (E->getNumArgs() == 2) {
6888 Second = getDerived().TransformExpr(E->getArg(1));
6889 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006890 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006891 }
Mike Stump1eb44332009-09-09 15:08:12 +00006892
Douglas Gregorb98b1992009-08-11 05:31:07 +00006893 if (!getDerived().AlwaysRebuild() &&
6894 Callee.get() == E->getCallee() &&
6895 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006896 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006897 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006898
Douglas Gregorb98b1992009-08-11 05:31:07 +00006899 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6900 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006901 Callee.get(),
6902 First.get(),
6903 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006904}
Mike Stump1eb44332009-09-09 15:08:12 +00006905
Douglas Gregorb98b1992009-08-11 05:31:07 +00006906template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006907ExprResult
John McCall454feb92009-12-08 09:21:05 +00006908TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6909 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006910}
Mike Stump1eb44332009-09-09 15:08:12 +00006911
Douglas Gregorb98b1992009-08-11 05:31:07 +00006912template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006913ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006914TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6915 // Transform the callee.
6916 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6917 if (Callee.isInvalid())
6918 return ExprError();
6919
6920 // Transform exec config.
6921 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6922 if (EC.isInvalid())
6923 return ExprError();
6924
6925 // Transform arguments.
6926 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006927 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006928 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006929 &ArgChanged))
6930 return ExprError();
6931
6932 if (!getDerived().AlwaysRebuild() &&
6933 Callee.get() == E->getCallee() &&
6934 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006935 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006936
6937 // FIXME: Wrong source location information for the '('.
6938 SourceLocation FakeLParenLoc
6939 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6940 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006941 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006942 E->getRParenLoc(), EC.get());
6943}
6944
6945template<typename Derived>
6946ExprResult
John McCall454feb92009-12-08 09:21:05 +00006947TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006948 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6949 if (!Type)
6950 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006951
John McCall60d7b3a2010-08-24 06:29:42 +00006952 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006953 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006954 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006955 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006956
Douglas Gregorb98b1992009-08-11 05:31:07 +00006957 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006958 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006959 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006960 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006961
Douglas Gregorb98b1992009-08-11 05:31:07 +00006962 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006963 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006964 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6965 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6966 SourceLocation FakeRParenLoc
6967 = SemaRef.PP.getLocForEndOfToken(
6968 E->getSubExpr()->getSourceRange().getEnd());
6969 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006970 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006971 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006972 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006973 FakeRAngleLoc,
6974 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006975 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006976 FakeRParenLoc);
6977}
Mike Stump1eb44332009-09-09 15:08:12 +00006978
Douglas Gregorb98b1992009-08-11 05:31:07 +00006979template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006980ExprResult
John McCall454feb92009-12-08 09:21:05 +00006981TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6982 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006983}
Mike Stump1eb44332009-09-09 15:08:12 +00006984
6985template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006986ExprResult
John McCall454feb92009-12-08 09:21:05 +00006987TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6988 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006989}
6990
Douglas Gregorb98b1992009-08-11 05:31:07 +00006991template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006992ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006993TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006994 CXXReinterpretCastExpr *E) {
6995 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006996}
Mike Stump1eb44332009-09-09 15:08:12 +00006997
Douglas Gregorb98b1992009-08-11 05:31:07 +00006998template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006999ExprResult
John McCall454feb92009-12-08 09:21:05 +00007000TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7001 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007002}
Mike Stump1eb44332009-09-09 15:08:12 +00007003
Douglas Gregorb98b1992009-08-11 05:31:07 +00007004template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007005ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007006TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007007 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007008 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7009 if (!Type)
7010 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007011
John McCall60d7b3a2010-08-24 06:29:42 +00007012 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007013 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007014 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007015 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007016
Douglas Gregorb98b1992009-08-11 05:31:07 +00007017 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007018 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007019 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007020 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007021
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007022 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007023 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007024 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007025 E->getRParenLoc());
7026}
Mike Stump1eb44332009-09-09 15:08:12 +00007027
Douglas Gregorb98b1992009-08-11 05:31:07 +00007028template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007029ExprResult
John McCall454feb92009-12-08 09:21:05 +00007030TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007031 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007032 TypeSourceInfo *TInfo
7033 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7034 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007035 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007036
Douglas Gregorb98b1992009-08-11 05:31:07 +00007037 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007038 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007039 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007040
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007041 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7042 E->getLocStart(),
7043 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007044 E->getLocEnd());
7045 }
Mike Stump1eb44332009-09-09 15:08:12 +00007046
Eli Friedmanef331b72012-01-20 01:26:23 +00007047 // We don't know whether the subexpression is potentially evaluated until
7048 // after we perform semantic analysis. We speculatively assume it is
7049 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007050 // potentially evaluated.
Eli Friedmanef331b72012-01-20 01:26:23 +00007051 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00007052
John McCall60d7b3a2010-08-24 06:29:42 +00007053 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007054 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007055 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007056
Douglas Gregorb98b1992009-08-11 05:31:07 +00007057 if (!getDerived().AlwaysRebuild() &&
7058 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007059 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007060
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007061 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7062 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007063 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007064 E->getLocEnd());
7065}
7066
7067template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007068ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007069TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7070 if (E->isTypeOperand()) {
7071 TypeSourceInfo *TInfo
7072 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7073 if (!TInfo)
7074 return ExprError();
7075
7076 if (!getDerived().AlwaysRebuild() &&
7077 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007078 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007079
Douglas Gregor3c52a212011-03-06 17:40:41 +00007080 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007081 E->getLocStart(),
7082 TInfo,
7083 E->getLocEnd());
7084 }
7085
Francois Pichet01b7c302010-09-08 12:20:18 +00007086 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7087
7088 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7089 if (SubExpr.isInvalid())
7090 return ExprError();
7091
7092 if (!getDerived().AlwaysRebuild() &&
7093 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007094 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007095
7096 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7097 E->getLocStart(),
7098 SubExpr.get(),
7099 E->getLocEnd());
7100}
7101
7102template<typename Derived>
7103ExprResult
John McCall454feb92009-12-08 09:21:05 +00007104TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007105 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007106}
Mike Stump1eb44332009-09-09 15:08:12 +00007107
Douglas Gregorb98b1992009-08-11 05:31:07 +00007108template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007109ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007110TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007111 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007112 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007113}
Mike Stump1eb44332009-09-09 15:08:12 +00007114
Douglas Gregorb98b1992009-08-11 05:31:07 +00007115template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007116ExprResult
John McCall454feb92009-12-08 09:21:05 +00007117TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007118 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007119 QualType T;
7120 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7121 T = MD->getThisType(getSema().Context);
7122 else
7123 T = getSema().Context.getPointerType(
7124 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007125
Douglas Gregorec79d872012-02-24 17:41:38 +00007126 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7127 // Make sure that we capture 'this'.
7128 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007129 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007130 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007131
Douglas Gregor828a1972010-01-07 23:12:05 +00007132 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007133}
Mike Stump1eb44332009-09-09 15:08:12 +00007134
Douglas Gregorb98b1992009-08-11 05:31:07 +00007135template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007136ExprResult
John McCall454feb92009-12-08 09:21:05 +00007137TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007138 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007139 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007140 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007141
Douglas Gregorb98b1992009-08-11 05:31:07 +00007142 if (!getDerived().AlwaysRebuild() &&
7143 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007144 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007145
Douglas Gregorbca01b42011-07-06 22:04:06 +00007146 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7147 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007148}
Mike Stump1eb44332009-09-09 15:08:12 +00007149
Douglas Gregorb98b1992009-08-11 05:31:07 +00007150template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007151ExprResult
John McCall454feb92009-12-08 09:21:05 +00007152TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007153 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007154 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7155 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007156 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007157 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007158
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007159 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007160 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007161 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007162
Douglas Gregor036aed12009-12-23 23:03:06 +00007163 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007164}
Mike Stump1eb44332009-09-09 15:08:12 +00007165
Douglas Gregorb98b1992009-08-11 05:31:07 +00007166template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007167ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007168TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7169 CXXScalarValueInitExpr *E) {
7170 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7171 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007172 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007173
Douglas Gregorb98b1992009-08-11 05:31:07 +00007174 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007175 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007176 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007177
Chad Rosier4a9d7952012-08-08 18:46:20 +00007178 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007179 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007180 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007181}
Mike Stump1eb44332009-09-09 15:08:12 +00007182
Douglas Gregorb98b1992009-08-11 05:31:07 +00007183template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007184ExprResult
John McCall454feb92009-12-08 09:21:05 +00007185TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007186 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007187 TypeSourceInfo *AllocTypeInfo
7188 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7189 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007190 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007191
Douglas Gregorb98b1992009-08-11 05:31:07 +00007192 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007193 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007194 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007195 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007196
Douglas Gregorb98b1992009-08-11 05:31:07 +00007197 // Transform the placement arguments (if any).
7198 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007199 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007200 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007201 E->getNumPlacementArgs(), true,
7202 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007203 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007204
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007205 // Transform the initializer (if any).
7206 Expr *OldInit = E->getInitializer();
7207 ExprResult NewInit;
7208 if (OldInit)
7209 NewInit = getDerived().TransformExpr(OldInit);
7210 if (NewInit.isInvalid())
7211 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007212
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007213 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007214 FunctionDecl *OperatorNew = 0;
7215 if (E->getOperatorNew()) {
7216 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007217 getDerived().TransformDecl(E->getLocStart(),
7218 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007219 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007220 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007221 }
7222
7223 FunctionDecl *OperatorDelete = 0;
7224 if (E->getOperatorDelete()) {
7225 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007226 getDerived().TransformDecl(E->getLocStart(),
7227 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007228 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007229 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007230 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007231
Douglas Gregorb98b1992009-08-11 05:31:07 +00007232 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007233 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007234 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007235 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007236 OperatorNew == E->getOperatorNew() &&
7237 OperatorDelete == E->getOperatorDelete() &&
7238 !ArgumentChanged) {
7239 // Mark any declarations we need as referenced.
7240 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007241 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007242 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007243 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007244 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007245
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007246 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007247 QualType ElementType
7248 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7249 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7250 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7251 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007252 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007253 }
7254 }
7255 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007256
John McCall3fa5cae2010-10-26 07:05:15 +00007257 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007258 }
Mike Stump1eb44332009-09-09 15:08:12 +00007259
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007260 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007261 if (!ArraySize.get()) {
7262 // If no array size was specified, but the new expression was
7263 // instantiated with an array type (e.g., "new T" where T is
7264 // instantiated with "int[4]"), extract the outer bound from the
7265 // array type as our array size. We do this with constant and
7266 // dependently-sized array types.
7267 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7268 if (!ArrayT) {
7269 // Do nothing
7270 } else if (const ConstantArrayType *ConsArrayT
7271 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007272 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007273 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007274 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007275 SemaRef.Context.getSizeType(),
7276 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007277 AllocType = ConsArrayT->getElementType();
7278 } else if (const DependentSizedArrayType *DepArrayT
7279 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7280 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007281 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007282 AllocType = DepArrayT->getElementType();
7283 }
7284 }
7285 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007286
Douglas Gregorb98b1992009-08-11 05:31:07 +00007287 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7288 E->isGlobalNew(),
7289 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007290 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007291 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007292 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007293 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007294 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007295 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007296 E->getDirectInitRange(),
7297 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007298}
Mike Stump1eb44332009-09-09 15:08:12 +00007299
Douglas Gregorb98b1992009-08-11 05:31:07 +00007300template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007301ExprResult
John McCall454feb92009-12-08 09:21:05 +00007302TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007303 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007304 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007305 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007306
Douglas Gregor1af74512010-02-26 00:38:10 +00007307 // Transform the delete operator, if known.
7308 FunctionDecl *OperatorDelete = 0;
7309 if (E->getOperatorDelete()) {
7310 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007311 getDerived().TransformDecl(E->getLocStart(),
7312 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007313 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007314 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007315 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007316
Douglas Gregorb98b1992009-08-11 05:31:07 +00007317 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007318 Operand.get() == E->getArgument() &&
7319 OperatorDelete == E->getOperatorDelete()) {
7320 // Mark any declarations we need as referenced.
7321 // FIXME: instantiation-specific.
7322 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007323 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007324
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007325 if (!E->getArgument()->isTypeDependent()) {
7326 QualType Destroyed = SemaRef.Context.getBaseElementType(
7327 E->getDestroyedType());
7328 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7329 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007330 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007331 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007332 }
7333 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007334
John McCall3fa5cae2010-10-26 07:05:15 +00007335 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007336 }
Mike Stump1eb44332009-09-09 15:08:12 +00007337
Douglas Gregorb98b1992009-08-11 05:31:07 +00007338 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7339 E->isGlobalDelete(),
7340 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007341 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007342}
Mike Stump1eb44332009-09-09 15:08:12 +00007343
Douglas Gregorb98b1992009-08-11 05:31:07 +00007344template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007345ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007346TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007347 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007348 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007349 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007350 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007351
John McCallb3d87482010-08-24 05:47:05 +00007352 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007353 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007354 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007355 E->getOperatorLoc(),
7356 E->isArrow()? tok::arrow : tok::period,
7357 ObjectTypePtr,
7358 MayBePseudoDestructor);
7359 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007360 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007361
John McCallb3d87482010-08-24 05:47:05 +00007362 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007363 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7364 if (QualifierLoc) {
7365 QualifierLoc
7366 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7367 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007368 return ExprError();
7369 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007370 CXXScopeSpec SS;
7371 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007372
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007373 PseudoDestructorTypeStorage Destroyed;
7374 if (E->getDestroyedTypeInfo()) {
7375 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007376 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007377 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007378 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007379 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007380 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007381 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007382 // We aren't likely to be able to resolve the identifier down to a type
7383 // now anyway, so just retain the identifier.
7384 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7385 E->getDestroyedTypeLoc());
7386 } else {
7387 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007388 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007389 *E->getDestroyedTypeIdentifier(),
7390 E->getDestroyedTypeLoc(),
7391 /*Scope=*/0,
7392 SS, ObjectTypePtr,
7393 false);
7394 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007395 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007396
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007397 Destroyed
7398 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7399 E->getDestroyedTypeLoc());
7400 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007401
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007402 TypeSourceInfo *ScopeTypeInfo = 0;
7403 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007404 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007405 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007406 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007407 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007408
John McCall9ae2f072010-08-23 23:25:46 +00007409 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007410 E->getOperatorLoc(),
7411 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007412 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007413 ScopeTypeInfo,
7414 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007415 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007416 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007417}
Mike Stump1eb44332009-09-09 15:08:12 +00007418
Douglas Gregora71d8192009-09-04 17:36:40 +00007419template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007420ExprResult
John McCallba135432009-11-21 08:51:07 +00007421TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007422 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007423 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7424 Sema::LookupOrdinaryName);
7425
7426 // Transform all the decls.
7427 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7428 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007429 NamedDecl *InstD = static_cast<NamedDecl*>(
7430 getDerived().TransformDecl(Old->getNameLoc(),
7431 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007432 if (!InstD) {
7433 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7434 // This can happen because of dependent hiding.
7435 if (isa<UsingShadowDecl>(*I))
7436 continue;
7437 else
John McCallf312b1e2010-08-26 23:41:50 +00007438 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007439 }
John McCallf7a1a742009-11-24 19:00:30 +00007440
7441 // Expand using declarations.
7442 if (isa<UsingDecl>(InstD)) {
7443 UsingDecl *UD = cast<UsingDecl>(InstD);
7444 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7445 E = UD->shadow_end(); I != E; ++I)
7446 R.addDecl(*I);
7447 continue;
7448 }
7449
7450 R.addDecl(InstD);
7451 }
7452
7453 // Resolve a kind, but don't do any further analysis. If it's
7454 // ambiguous, the callee needs to deal with it.
7455 R.resolveKind();
7456
7457 // Rebuild the nested-name qualifier, if present.
7458 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007459 if (Old->getQualifierLoc()) {
7460 NestedNameSpecifierLoc QualifierLoc
7461 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7462 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007463 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007464
Douglas Gregor4c9be892011-02-28 20:01:57 +00007465 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007466 }
7467
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007468 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007469 CXXRecordDecl *NamingClass
7470 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7471 Old->getNameLoc(),
7472 Old->getNamingClass()));
7473 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007474 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007475
Douglas Gregor66c45152010-04-27 16:10:10 +00007476 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007477 }
7478
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007479 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7480
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007481 // If we have neither explicit template arguments, nor the template keyword,
7482 // it's a normal declaration name.
7483 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007484 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7485
7486 // If we have template arguments, rebuild them, then rebuild the
7487 // templateid expression.
7488 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007489 if (Old->hasExplicitTemplateArgs() &&
7490 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007491 Old->getNumTemplateArgs(),
7492 TransArgs))
7493 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007494
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007495 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007496 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007497}
Mike Stump1eb44332009-09-09 15:08:12 +00007498
Douglas Gregorb98b1992009-08-11 05:31:07 +00007499template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007500ExprResult
John McCall454feb92009-12-08 09:21:05 +00007501TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007502 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7503 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007504 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007505
Douglas Gregorb98b1992009-08-11 05:31:07 +00007506 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007507 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007508 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007509
Mike Stump1eb44332009-09-09 15:08:12 +00007510 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007511 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007512 T,
7513 E->getLocEnd());
7514}
Mike Stump1eb44332009-09-09 15:08:12 +00007515
Douglas Gregorb98b1992009-08-11 05:31:07 +00007516template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007517ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007518TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7519 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7520 if (!LhsT)
7521 return ExprError();
7522
7523 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7524 if (!RhsT)
7525 return ExprError();
7526
7527 if (!getDerived().AlwaysRebuild() &&
7528 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7529 return SemaRef.Owned(E);
7530
7531 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7532 E->getLocStart(),
7533 LhsT, RhsT,
7534 E->getLocEnd());
7535}
7536
7537template<typename Derived>
7538ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007539TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7540 bool ArgChanged = false;
7541 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7542 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7543 TypeSourceInfo *From = E->getArg(I);
7544 TypeLoc FromTL = From->getTypeLoc();
7545 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7546 TypeLocBuilder TLB;
7547 TLB.reserve(FromTL.getFullDataSize());
7548 QualType To = getDerived().TransformType(TLB, FromTL);
7549 if (To.isNull())
7550 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007551
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007552 if (To == From->getType())
7553 Args.push_back(From);
7554 else {
7555 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7556 ArgChanged = true;
7557 }
7558 continue;
7559 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007560
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007561 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007562
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007563 // We have a pack expansion. Instantiate it.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007564 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007565 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7566 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7567 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007568
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007569 // Determine whether the set of unexpanded parameter packs can and should
7570 // be expanded.
7571 bool Expand = true;
7572 bool RetainExpansion = false;
7573 llvm::Optional<unsigned> OrigNumExpansions
7574 = ExpansionTL.getTypePtr()->getNumExpansions();
7575 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7576 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7577 PatternTL.getSourceRange(),
7578 Unexpanded,
7579 Expand, RetainExpansion,
7580 NumExpansions))
7581 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007582
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007583 if (!Expand) {
7584 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007585 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007586 // expansion.
7587 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007588
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007589 TypeLocBuilder TLB;
7590 TLB.reserve(From->getTypeLoc().getFullDataSize());
7591
7592 QualType To = getDerived().TransformType(TLB, PatternTL);
7593 if (To.isNull())
7594 return ExprError();
7595
Chad Rosier4a9d7952012-08-08 18:46:20 +00007596 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007597 PatternTL.getSourceRange(),
7598 ExpansionTL.getEllipsisLoc(),
7599 NumExpansions);
7600 if (To.isNull())
7601 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007602
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007603 PackExpansionTypeLoc ToExpansionTL
7604 = TLB.push<PackExpansionTypeLoc>(To);
7605 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7606 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7607 continue;
7608 }
7609
7610 // Expand the pack expansion by substituting for each argument in the
7611 // pack(s).
7612 for (unsigned I = 0; I != *NumExpansions; ++I) {
7613 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7614 TypeLocBuilder TLB;
7615 TLB.reserve(PatternTL.getFullDataSize());
7616 QualType To = getDerived().TransformType(TLB, PatternTL);
7617 if (To.isNull())
7618 return ExprError();
7619
7620 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7621 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007622
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007623 if (!RetainExpansion)
7624 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007625
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007626 // If we're supposed to retain a pack expansion, do so by temporarily
7627 // forgetting the partially-substituted parameter pack.
7628 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7629
7630 TypeLocBuilder TLB;
7631 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007632
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007633 QualType To = getDerived().TransformType(TLB, PatternTL);
7634 if (To.isNull())
7635 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007636
7637 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007638 PatternTL.getSourceRange(),
7639 ExpansionTL.getEllipsisLoc(),
7640 NumExpansions);
7641 if (To.isNull())
7642 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007643
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007644 PackExpansionTypeLoc ToExpansionTL
7645 = TLB.push<PackExpansionTypeLoc>(To);
7646 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7647 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7648 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007649
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007650 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7651 return SemaRef.Owned(E);
7652
7653 return getDerived().RebuildTypeTrait(E->getTrait(),
7654 E->getLocStart(),
7655 Args,
7656 E->getLocEnd());
7657}
7658
7659template<typename Derived>
7660ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007661TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7662 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7663 if (!T)
7664 return ExprError();
7665
7666 if (!getDerived().AlwaysRebuild() &&
7667 T == E->getQueriedTypeSourceInfo())
7668 return SemaRef.Owned(E);
7669
7670 ExprResult SubExpr;
7671 {
7672 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7673 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7674 if (SubExpr.isInvalid())
7675 return ExprError();
7676
7677 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7678 return SemaRef.Owned(E);
7679 }
7680
7681 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7682 E->getLocStart(),
7683 T,
7684 SubExpr.get(),
7685 E->getLocEnd());
7686}
7687
7688template<typename Derived>
7689ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007690TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7691 ExprResult SubExpr;
7692 {
7693 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7694 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7695 if (SubExpr.isInvalid())
7696 return ExprError();
7697
7698 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7699 return SemaRef.Owned(E);
7700 }
7701
7702 return getDerived().RebuildExpressionTrait(
7703 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7704}
7705
7706template<typename Derived>
7707ExprResult
John McCall865d4472009-11-19 22:55:06 +00007708TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007709 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007710 NestedNameSpecifierLoc QualifierLoc
7711 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7712 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007713 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007714 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007715
John McCall43fed0d2010-11-12 08:19:04 +00007716 // TODO: If this is a conversion-function-id, verify that the
7717 // destination type name (if present) resolves the same way after
7718 // instantiation as it did in the local scope.
7719
Abramo Bagnara25777432010-08-11 22:01:17 +00007720 DeclarationNameInfo NameInfo
7721 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7722 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007723 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007724
John McCallf7a1a742009-11-24 19:00:30 +00007725 if (!E->hasExplicitTemplateArgs()) {
7726 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007727 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007728 // Note: it is sufficient to compare the Name component of NameInfo:
7729 // if name has not changed, DNLoc has not changed either.
7730 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007731 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007732
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007733 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007734 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007735 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007736 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007737 }
John McCalld5532b62009-11-23 01:53:49 +00007738
7739 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007740 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7741 E->getNumTemplateArgs(),
7742 TransArgs))
7743 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007744
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007745 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007746 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007747 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007748 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007749}
7750
7751template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007752ExprResult
John McCall454feb92009-12-08 09:21:05 +00007753TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007754 // CXXConstructExprs are always implicit, so when we have a
7755 // 1-argument construction we just transform that argument.
7756 if (E->getNumArgs() == 1 ||
7757 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7758 return getDerived().TransformExpr(E->getArg(0));
7759
Douglas Gregorb98b1992009-08-11 05:31:07 +00007760 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7761
7762 QualType T = getDerived().TransformType(E->getType());
7763 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007764 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007765
7766 CXXConstructorDecl *Constructor
7767 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007768 getDerived().TransformDecl(E->getLocStart(),
7769 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007770 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007771 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007772
Douglas Gregorb98b1992009-08-11 05:31:07 +00007773 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007774 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007775 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007776 &ArgumentChanged))
7777 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007778
Douglas Gregorb98b1992009-08-11 05:31:07 +00007779 if (!getDerived().AlwaysRebuild() &&
7780 T == E->getType() &&
7781 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007782 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007783 // Mark the constructor as referenced.
7784 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007785 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007786 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007787 }
Mike Stump1eb44332009-09-09 15:08:12 +00007788
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007789 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7790 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007791 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007792 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007793 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007794 E->getConstructionKind(),
7795 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007796}
Mike Stump1eb44332009-09-09 15:08:12 +00007797
Douglas Gregorb98b1992009-08-11 05:31:07 +00007798/// \brief Transform a C++ temporary-binding expression.
7799///
Douglas Gregor51326552009-12-24 18:51:59 +00007800/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7801/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007802template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007803ExprResult
John McCall454feb92009-12-08 09:21:05 +00007804TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007805 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007806}
Mike Stump1eb44332009-09-09 15:08:12 +00007807
John McCall4765fa02010-12-06 08:20:24 +00007808/// \brief Transform a C++ expression that contains cleanups that should
7809/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007810///
John McCall4765fa02010-12-06 08:20:24 +00007811/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007812/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007813template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007814ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007815TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007816 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007817}
Mike Stump1eb44332009-09-09 15:08:12 +00007818
Douglas Gregorb98b1992009-08-11 05:31:07 +00007819template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007820ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007821TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007822 CXXTemporaryObjectExpr *E) {
7823 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7824 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007825 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007826
Douglas Gregorb98b1992009-08-11 05:31:07 +00007827 CXXConstructorDecl *Constructor
7828 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00007829 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007830 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007831 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007832 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007833
Douglas Gregorb98b1992009-08-11 05:31:07 +00007834 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007835 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007836 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007837 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007838 &ArgumentChanged))
7839 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007840
Douglas Gregorb98b1992009-08-11 05:31:07 +00007841 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007842 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007843 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007844 !ArgumentChanged) {
7845 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007846 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007847 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007848 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007849
Douglas Gregorab6677e2010-09-08 00:15:04 +00007850 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7851 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007852 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007853 E->getLocEnd());
7854}
Mike Stump1eb44332009-09-09 15:08:12 +00007855
Douglas Gregorb98b1992009-08-11 05:31:07 +00007856template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007857ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007858TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007859 // Transform the type of the lambda parameters and start the definition of
7860 // the lambda itself.
7861 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00007862 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00007863 if (!MethodTy)
7864 return ExprError();
7865
Eli Friedman8da8a662012-09-19 01:18:11 +00007866 // Create the local class that will describe the lambda.
7867 CXXRecordDecl *Class
7868 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7869 MethodTy,
7870 /*KnownDependent=*/false);
7871 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7872
Douglas Gregorc6889e72012-02-14 22:28:59 +00007873 // Transform lambda parameters.
Douglas Gregorc6889e72012-02-14 22:28:59 +00007874 llvm::SmallVector<QualType, 4> ParamTypes;
7875 llvm::SmallVector<ParmVarDecl *, 4> Params;
7876 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7877 E->getCallOperator()->param_begin(),
7878 E->getCallOperator()->param_size(),
7879 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00007880 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00007881
Douglas Gregordfca6f52012-02-13 22:00:16 +00007882 // Build the call operator.
7883 CXXMethodDecl *CallOperator
7884 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007885 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007886 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007887 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007888 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00007889
Richard Smith612409e2012-07-25 03:56:55 +00007890 return getDerived().TransformLambdaScope(E, CallOperator);
7891}
7892
7893template<typename Derived>
7894ExprResult
7895TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
7896 CXXMethodDecl *CallOperator) {
Douglas Gregord5387e82012-02-14 00:00:48 +00007897 // Introduce the context of the call operator.
7898 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7899
Douglas Gregordfca6f52012-02-13 22:00:16 +00007900 // Enter the scope of the lambda.
7901 sema::LambdaScopeInfo *LSI
7902 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7903 E->getCaptureDefault(),
7904 E->hasExplicitParameters(),
7905 E->hasExplicitResultType(),
7906 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007907
Douglas Gregordfca6f52012-02-13 22:00:16 +00007908 // Transform captures.
Richard Smith612409e2012-07-25 03:56:55 +00007909 bool Invalid = false;
Douglas Gregordfca6f52012-02-13 22:00:16 +00007910 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007911 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007912 CEnd = E->capture_end();
7913 C != CEnd; ++C) {
7914 // When we hit the first implicit capture, tell Sema that we've finished
7915 // the list of explicit captures.
7916 if (!FinishedExplicitCaptures && C->isImplicit()) {
7917 getSema().finishLambdaExplicitCaptures(LSI);
7918 FinishedExplicitCaptures = true;
7919 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007920
Douglas Gregordfca6f52012-02-13 22:00:16 +00007921 // Capturing 'this' is trivial.
7922 if (C->capturesThis()) {
7923 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7924 continue;
7925 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007926
Douglas Gregora7365242012-02-14 19:27:52 +00007927 // Determine the capture kind for Sema.
7928 Sema::TryCaptureKind Kind
7929 = C->isImplicit()? Sema::TryCapture_Implicit
7930 : C->getCaptureKind() == LCK_ByCopy
7931 ? Sema::TryCapture_ExplicitByVal
7932 : Sema::TryCapture_ExplicitByRef;
7933 SourceLocation EllipsisLoc;
7934 if (C->isPackExpansion()) {
7935 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7936 bool ShouldExpand = false;
7937 bool RetainExpansion = false;
7938 llvm::Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007939 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7940 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00007941 Unexpanded,
7942 ShouldExpand, RetainExpansion,
7943 NumExpansions))
7944 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007945
Douglas Gregora7365242012-02-14 19:27:52 +00007946 if (ShouldExpand) {
7947 // The transform has determined that we should perform an expansion;
7948 // transform and capture each of the arguments.
7949 // expansion of the pattern. Do so.
7950 VarDecl *Pack = C->getCapturedVar();
7951 for (unsigned I = 0; I != *NumExpansions; ++I) {
7952 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7953 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00007954 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00007955 Pack));
7956 if (!CapturedVar) {
7957 Invalid = true;
7958 continue;
7959 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007960
Douglas Gregora7365242012-02-14 19:27:52 +00007961 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007962 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
7963 }
Douglas Gregora7365242012-02-14 19:27:52 +00007964 continue;
7965 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007966
Douglas Gregora7365242012-02-14 19:27:52 +00007967 EllipsisLoc = C->getEllipsisLoc();
7968 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007969
Douglas Gregordfca6f52012-02-13 22:00:16 +00007970 // Transform the captured variable.
7971 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00007972 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007973 C->getCapturedVar()));
7974 if (!CapturedVar) {
7975 Invalid = true;
7976 continue;
7977 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007978
Douglas Gregordfca6f52012-02-13 22:00:16 +00007979 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00007980 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007981 }
7982 if (!FinishedExplicitCaptures)
7983 getSema().finishLambdaExplicitCaptures(LSI);
7984
Douglas Gregordfca6f52012-02-13 22:00:16 +00007985
7986 // Enter a new evaluation context to insulate the lambda from any
7987 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007988 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007989
7990 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007991 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00007992 /*IsInstantiation=*/true);
7993 return ExprError();
7994 }
7995
7996 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00007997 StmtResult Body = getDerived().TransformStmt(E->getBody());
7998 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007999 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008000 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008001 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008002 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008003
Chad Rosier4a9d7952012-08-08 18:46:20 +00008004 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008005 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008006}
8007
8008template<typename Derived>
8009ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008010TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008011 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008012 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8013 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008014 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008015
Douglas Gregorb98b1992009-08-11 05:31:07 +00008016 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008017 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008018 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008019 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008020 &ArgumentChanged))
8021 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008022
Douglas Gregorb98b1992009-08-11 05:31:07 +00008023 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008024 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008025 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008026 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008027
Douglas Gregorb98b1992009-08-11 05:31:07 +00008028 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008029 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008030 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008031 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008032 E->getRParenLoc());
8033}
Mike Stump1eb44332009-09-09 15:08:12 +00008034
Douglas Gregorb98b1992009-08-11 05:31:07 +00008035template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008036ExprResult
John McCall865d4472009-11-19 22:55:06 +00008037TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008038 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008039 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008040 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008041 Expr *OldBase;
8042 QualType BaseType;
8043 QualType ObjectType;
8044 if (!E->isImplicitAccess()) {
8045 OldBase = E->getBase();
8046 Base = getDerived().TransformExpr(OldBase);
8047 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008048 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008049
John McCallaa81e162009-12-01 22:10:20 +00008050 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008051 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008052 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008053 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008054 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008055 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008056 ObjectTy,
8057 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008058 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008059 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008060
John McCallb3d87482010-08-24 05:47:05 +00008061 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008062 BaseType = ((Expr*) Base.get())->getType();
8063 } else {
8064 OldBase = 0;
8065 BaseType = getDerived().TransformType(E->getBaseType());
8066 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8067 }
Mike Stump1eb44332009-09-09 15:08:12 +00008068
Douglas Gregor6cd21982009-10-20 05:58:46 +00008069 // Transform the first part of the nested-name-specifier that qualifies
8070 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008071 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008072 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008073 E->getFirstQualifierFoundInScope(),
8074 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008075
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008076 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008077 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008078 QualifierLoc
8079 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8080 ObjectType,
8081 FirstQualifierInScope);
8082 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008083 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008084 }
Mike Stump1eb44332009-09-09 15:08:12 +00008085
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008086 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8087
John McCall43fed0d2010-11-12 08:19:04 +00008088 // TODO: If this is a conversion-function-id, verify that the
8089 // destination type name (if present) resolves the same way after
8090 // instantiation as it did in the local scope.
8091
Abramo Bagnara25777432010-08-11 22:01:17 +00008092 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008093 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008094 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008095 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008096
John McCallaa81e162009-12-01 22:10:20 +00008097 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008098 // This is a reference to a member without an explicitly-specified
8099 // template argument list. Optimize for this common case.
8100 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008101 Base.get() == OldBase &&
8102 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008103 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008104 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008105 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008106 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008107
John McCall9ae2f072010-08-23 23:25:46 +00008108 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008109 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008110 E->isArrow(),
8111 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008112 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008113 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008114 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008115 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008116 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008117 }
8118
John McCalld5532b62009-11-23 01:53:49 +00008119 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008120 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8121 E->getNumTemplateArgs(),
8122 TransArgs))
8123 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008124
John McCall9ae2f072010-08-23 23:25:46 +00008125 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008126 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008127 E->isArrow(),
8128 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008129 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008130 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008131 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008132 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008133 &TransArgs);
8134}
8135
8136template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008137ExprResult
John McCall454feb92009-12-08 09:21:05 +00008138TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008139 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008140 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008141 QualType BaseType;
8142 if (!Old->isImplicitAccess()) {
8143 Base = getDerived().TransformExpr(Old->getBase());
8144 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008145 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008146 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8147 Old->isArrow());
8148 if (Base.isInvalid())
8149 return ExprError();
8150 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008151 } else {
8152 BaseType = getDerived().TransformType(Old->getBaseType());
8153 }
John McCall129e2df2009-11-30 22:42:35 +00008154
Douglas Gregor4c9be892011-02-28 20:01:57 +00008155 NestedNameSpecifierLoc QualifierLoc;
8156 if (Old->getQualifierLoc()) {
8157 QualifierLoc
8158 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8159 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008160 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008161 }
8162
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008163 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8164
Abramo Bagnara25777432010-08-11 22:01:17 +00008165 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008166 Sema::LookupOrdinaryName);
8167
8168 // Transform all the decls.
8169 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8170 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008171 NamedDecl *InstD = static_cast<NamedDecl*>(
8172 getDerived().TransformDecl(Old->getMemberLoc(),
8173 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008174 if (!InstD) {
8175 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8176 // This can happen because of dependent hiding.
8177 if (isa<UsingShadowDecl>(*I))
8178 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008179 else {
8180 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008181 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008182 }
John McCall9f54ad42009-12-10 09:41:52 +00008183 }
John McCall129e2df2009-11-30 22:42:35 +00008184
8185 // Expand using declarations.
8186 if (isa<UsingDecl>(InstD)) {
8187 UsingDecl *UD = cast<UsingDecl>(InstD);
8188 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8189 E = UD->shadow_end(); I != E; ++I)
8190 R.addDecl(*I);
8191 continue;
8192 }
8193
8194 R.addDecl(InstD);
8195 }
8196
8197 R.resolveKind();
8198
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008199 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008200 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008201 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008202 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008203 Old->getMemberLoc(),
8204 Old->getNamingClass()));
8205 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008206 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008207
Douglas Gregor66c45152010-04-27 16:10:10 +00008208 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008209 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008210
John McCall129e2df2009-11-30 22:42:35 +00008211 TemplateArgumentListInfo TransArgs;
8212 if (Old->hasExplicitTemplateArgs()) {
8213 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8214 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008215 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8216 Old->getNumTemplateArgs(),
8217 TransArgs))
8218 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008219 }
John McCallc2233c52010-01-15 08:34:02 +00008220
8221 // FIXME: to do this check properly, we will need to preserve the
8222 // first-qualifier-in-scope here, just in case we had a dependent
8223 // base (and therefore couldn't do the check) and a
8224 // nested-name-qualifier (and therefore could do the lookup).
8225 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008226
John McCall9ae2f072010-08-23 23:25:46 +00008227 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008228 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008229 Old->getOperatorLoc(),
8230 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008231 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008232 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008233 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008234 R,
8235 (Old->hasExplicitTemplateArgs()
8236 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008237}
8238
8239template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008240ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008241TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008242 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008243 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8244 if (SubExpr.isInvalid())
8245 return ExprError();
8246
8247 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008248 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008249
8250 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8251}
8252
8253template<typename Derived>
8254ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008255TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008256 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8257 if (Pattern.isInvalid())
8258 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008259
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008260 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8261 return SemaRef.Owned(E);
8262
Douglas Gregor67fd1252011-01-14 21:20:45 +00008263 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8264 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008265}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008266
8267template<typename Derived>
8268ExprResult
8269TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8270 // If E is not value-dependent, then nothing will change when we transform it.
8271 // Note: This is an instantiation-centric view.
8272 if (!E->isValueDependent())
8273 return SemaRef.Owned(E);
8274
8275 // Note: None of the implementations of TryExpandParameterPacks can ever
8276 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008277 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008278 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8279 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008280 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008281 llvm::Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008282 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008283 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008284 ShouldExpand, RetainExpansion,
8285 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008286 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008287
Douglas Gregor089e8932011-10-10 18:59:29 +00008288 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008289 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008290
Douglas Gregor089e8932011-10-10 18:59:29 +00008291 NamedDecl *Pack = E->getPack();
8292 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008293 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008294 Pack));
8295 if (!Pack)
8296 return ExprError();
8297 }
8298
Chad Rosier4a9d7952012-08-08 18:46:20 +00008299
Douglas Gregoree8aff02011-01-04 17:33:58 +00008300 // We now know the length of the parameter pack, so build a new expression
8301 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008302 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8303 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008304 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008305}
8306
Douglas Gregorbe230c32011-01-03 17:17:50 +00008307template<typename Derived>
8308ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008309TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8310 SubstNonTypeTemplateParmPackExpr *E) {
8311 // Default behavior is to do nothing with this transformation.
8312 return SemaRef.Owned(E);
8313}
8314
8315template<typename Derived>
8316ExprResult
John McCall91a57552011-07-15 05:09:51 +00008317TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8318 SubstNonTypeTemplateParmExpr *E) {
8319 // Default behavior is to do nothing with this transformation.
8320 return SemaRef.Owned(E);
8321}
8322
8323template<typename Derived>
8324ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008325TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8326 // Default behavior is to do nothing with this transformation.
8327 return SemaRef.Owned(E);
8328}
8329
8330template<typename Derived>
8331ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008332TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8333 MaterializeTemporaryExpr *E) {
8334 return getDerived().TransformExpr(E->GetTemporaryExpr());
8335}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008336
Douglas Gregor03e80032011-06-21 17:03:29 +00008337template<typename Derived>
8338ExprResult
John McCall454feb92009-12-08 09:21:05 +00008339TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008340 return SemaRef.MaybeBindToTemporary(E);
8341}
8342
8343template<typename Derived>
8344ExprResult
8345TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008346 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008347}
8348
8349template<typename Derived>
8350ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008351TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8352 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8353 if (SubExpr.isInvalid())
8354 return ExprError();
8355
8356 if (!getDerived().AlwaysRebuild() &&
8357 SubExpr.get() == E->getSubExpr())
8358 return SemaRef.Owned(E);
8359
8360 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008361}
8362
8363template<typename Derived>
8364ExprResult
8365TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8366 // Transform each of the elements.
8367 llvm::SmallVector<Expr *, 8> Elements;
8368 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008369 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008370 /*IsCall=*/false, Elements, &ArgChanged))
8371 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008372
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008373 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8374 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008375
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008376 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8377 Elements.data(),
8378 Elements.size());
8379}
8380
8381template<typename Derived>
8382ExprResult
8383TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008384 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008385 // Transform each of the elements.
8386 llvm::SmallVector<ObjCDictionaryElement, 8> Elements;
8387 bool ArgChanged = false;
8388 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8389 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008390
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008391 if (OrigElement.isPackExpansion()) {
8392 // This key/value element is a pack expansion.
8393 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8394 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8395 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8396 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8397
8398 // Determine whether the set of unexpanded parameter packs can
8399 // and should be expanded.
8400 bool Expand = true;
8401 bool RetainExpansion = false;
8402 llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8403 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
8404 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8405 OrigElement.Value->getLocEnd());
8406 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8407 PatternRange,
8408 Unexpanded,
8409 Expand, RetainExpansion,
8410 NumExpansions))
8411 return ExprError();
8412
8413 if (!Expand) {
8414 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008415 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008416 // expansion.
8417 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8418 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8419 if (Key.isInvalid())
8420 return ExprError();
8421
8422 if (Key.get() != OrigElement.Key)
8423 ArgChanged = true;
8424
8425 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8426 if (Value.isInvalid())
8427 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008428
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008429 if (Value.get() != OrigElement.Value)
8430 ArgChanged = true;
8431
Chad Rosier4a9d7952012-08-08 18:46:20 +00008432 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008433 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8434 };
8435 Elements.push_back(Expansion);
8436 continue;
8437 }
8438
8439 // Record right away that the argument was changed. This needs
8440 // to happen even if the array expands to nothing.
8441 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008442
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008443 // The transform has determined that we should perform an elementwise
8444 // expansion of the pattern. Do so.
8445 for (unsigned I = 0; I != *NumExpansions; ++I) {
8446 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8447 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8448 if (Key.isInvalid())
8449 return ExprError();
8450
8451 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8452 if (Value.isInvalid())
8453 return ExprError();
8454
Chad Rosier4a9d7952012-08-08 18:46:20 +00008455 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008456 Key.get(), Value.get(), SourceLocation(), NumExpansions
8457 };
8458
8459 // If any unexpanded parameter packs remain, we still have a
8460 // pack expansion.
8461 if (Key.get()->containsUnexpandedParameterPack() ||
8462 Value.get()->containsUnexpandedParameterPack())
8463 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008464
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008465 Elements.push_back(Element);
8466 }
8467
8468 // We've finished with this pack expansion.
8469 continue;
8470 }
8471
8472 // Transform and check key.
8473 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8474 if (Key.isInvalid())
8475 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008476
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008477 if (Key.get() != OrigElement.Key)
8478 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008479
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008480 // Transform and check value.
8481 ExprResult Value
8482 = getDerived().TransformExpr(OrigElement.Value);
8483 if (Value.isInvalid())
8484 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008485
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008486 if (Value.get() != OrigElement.Value)
8487 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008488
8489 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008490 Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8491 };
8492 Elements.push_back(Element);
8493 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008494
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008495 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8496 return SemaRef.MaybeBindToTemporary(E);
8497
8498 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8499 Elements.data(),
8500 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008501}
8502
Mike Stump1eb44332009-09-09 15:08:12 +00008503template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008504ExprResult
John McCall454feb92009-12-08 09:21:05 +00008505TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008506 TypeSourceInfo *EncodedTypeInfo
8507 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8508 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008509 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008510
Douglas Gregorb98b1992009-08-11 05:31:07 +00008511 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008512 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008513 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008514
8515 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008516 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008517 E->getRParenLoc());
8518}
Mike Stump1eb44332009-09-09 15:08:12 +00008519
Douglas Gregorb98b1992009-08-11 05:31:07 +00008520template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008521ExprResult TreeTransform<Derived>::
8522TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8523 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8524 if (result.isInvalid()) return ExprError();
8525 Expr *subExpr = result.take();
8526
8527 if (!getDerived().AlwaysRebuild() &&
8528 subExpr == E->getSubExpr())
8529 return SemaRef.Owned(E);
8530
8531 return SemaRef.Owned(new(SemaRef.Context)
8532 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8533}
8534
8535template<typename Derived>
8536ExprResult TreeTransform<Derived>::
8537TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008538 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008539 = getDerived().TransformType(E->getTypeInfoAsWritten());
8540 if (!TSInfo)
8541 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008542
John McCallf85e1932011-06-15 23:02:42 +00008543 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008544 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008545 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008546
John McCallf85e1932011-06-15 23:02:42 +00008547 if (!getDerived().AlwaysRebuild() &&
8548 TSInfo == E->getTypeInfoAsWritten() &&
8549 Result.get() == E->getSubExpr())
8550 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008551
John McCallf85e1932011-06-15 23:02:42 +00008552 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008553 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008554 Result.get());
8555}
8556
8557template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008558ExprResult
John McCall454feb92009-12-08 09:21:05 +00008559TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008560 // Transform arguments.
8561 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008562 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008563 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008564 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008565 &ArgChanged))
8566 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008567
Douglas Gregor92e986e2010-04-22 16:44:27 +00008568 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8569 // Class message: transform the receiver type.
8570 TypeSourceInfo *ReceiverTypeInfo
8571 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8572 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008573 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008574
Douglas Gregor92e986e2010-04-22 16:44:27 +00008575 // If nothing changed, just retain the existing message send.
8576 if (!getDerived().AlwaysRebuild() &&
8577 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008578 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008579
8580 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008581 SmallVector<SourceLocation, 16> SelLocs;
8582 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008583 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8584 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008585 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008586 E->getMethodDecl(),
8587 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008588 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008589 E->getRightLoc());
8590 }
8591
8592 // Instance message: transform the receiver
8593 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8594 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008595 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008596 = getDerived().TransformExpr(E->getInstanceReceiver());
8597 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008598 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008599
8600 // If nothing changed, just retain the existing message send.
8601 if (!getDerived().AlwaysRebuild() &&
8602 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008603 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008604
Douglas Gregor92e986e2010-04-22 16:44:27 +00008605 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008606 SmallVector<SourceLocation, 16> SelLocs;
8607 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008608 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008609 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008610 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008611 E->getMethodDecl(),
8612 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008613 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008614 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008615}
8616
Mike Stump1eb44332009-09-09 15:08:12 +00008617template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008618ExprResult
John McCall454feb92009-12-08 09:21:05 +00008619TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008620 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008621}
8622
Mike Stump1eb44332009-09-09 15:08:12 +00008623template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008624ExprResult
John McCall454feb92009-12-08 09:21:05 +00008625TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008626 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008627}
8628
Mike Stump1eb44332009-09-09 15:08:12 +00008629template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008630ExprResult
John McCall454feb92009-12-08 09:21:05 +00008631TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008632 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008633 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008634 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008635 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008636
8637 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008638
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008639 // If nothing changed, just retain the existing expression.
8640 if (!getDerived().AlwaysRebuild() &&
8641 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008642 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008643
John McCall9ae2f072010-08-23 23:25:46 +00008644 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008645 E->getLocation(),
8646 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008647}
8648
Mike Stump1eb44332009-09-09 15:08:12 +00008649template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008650ExprResult
John McCall454feb92009-12-08 09:21:05 +00008651TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008652 // 'super' and types never change. Property never changes. Just
8653 // retain the existing expression.
8654 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008655 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008656
Douglas Gregore3303542010-04-26 20:47:02 +00008657 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008658 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008659 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008660 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008661
Douglas Gregore3303542010-04-26 20:47:02 +00008662 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008663
Douglas Gregore3303542010-04-26 20:47:02 +00008664 // If nothing changed, just retain the existing expression.
8665 if (!getDerived().AlwaysRebuild() &&
8666 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008667 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008668
John McCall12f78a62010-12-02 01:19:52 +00008669 if (E->isExplicitProperty())
8670 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8671 E->getExplicitProperty(),
8672 E->getLocation());
8673
8674 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008675 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008676 E->getImplicitPropertyGetter(),
8677 E->getImplicitPropertySetter(),
8678 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008679}
8680
Mike Stump1eb44332009-09-09 15:08:12 +00008681template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008682ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008683TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8684 // Transform the base expression.
8685 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8686 if (Base.isInvalid())
8687 return ExprError();
8688
8689 // Transform the key expression.
8690 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8691 if (Key.isInvalid())
8692 return ExprError();
8693
8694 // If nothing changed, just retain the existing expression.
8695 if (!getDerived().AlwaysRebuild() &&
8696 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8697 return SemaRef.Owned(E);
8698
Chad Rosier4a9d7952012-08-08 18:46:20 +00008699 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008700 Base.get(), Key.get(),
8701 E->getAtIndexMethodDecl(),
8702 E->setAtIndexMethodDecl());
8703}
8704
8705template<typename Derived>
8706ExprResult
John McCall454feb92009-12-08 09:21:05 +00008707TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008708 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008709 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008710 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008711 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008712
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008713 // If nothing changed, just retain the existing expression.
8714 if (!getDerived().AlwaysRebuild() &&
8715 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008716 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008717
John McCall9ae2f072010-08-23 23:25:46 +00008718 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008719 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008720}
8721
Mike Stump1eb44332009-09-09 15:08:12 +00008722template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008723ExprResult
John McCall454feb92009-12-08 09:21:05 +00008724TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008725 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008726 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008727 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008728 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008729 SubExprs, &ArgumentChanged))
8730 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008731
Douglas Gregorb98b1992009-08-11 05:31:07 +00008732 if (!getDerived().AlwaysRebuild() &&
8733 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008734 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008735
Douglas Gregorb98b1992009-08-11 05:31:07 +00008736 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008737 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008738 E->getRParenLoc());
8739}
8740
Mike Stump1eb44332009-09-09 15:08:12 +00008741template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008742ExprResult
John McCall454feb92009-12-08 09:21:05 +00008743TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008744 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008745
John McCallc6ac9c32011-02-04 18:33:18 +00008746 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8747 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8748
8749 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008750 blockScope->TheDecl->setBlockMissingReturnType(
8751 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008752
Chris Lattner686775d2011-07-20 06:58:45 +00008753 SmallVector<ParmVarDecl*, 4> params;
8754 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008755
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008756 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008757 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8758 oldBlock->param_begin(),
8759 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008760 0, paramTypes, &params)) {
8761 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008762 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008763 }
John McCallc6ac9c32011-02-04 18:33:18 +00008764
8765 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008766 QualType exprResultType =
8767 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008768
8769 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008770 if (exprResultType->isObjCObjectType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008771 getSema().Diag(E->getCaretLocation(),
8772 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008773 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008774 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008775 return ExprError();
8776 }
John McCall711c52b2011-01-05 12:14:39 +00008777
John McCallc6ac9c32011-02-04 18:33:18 +00008778 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008779 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008780 paramTypes.data(),
8781 paramTypes.size(),
8782 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008783 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008784 exprFunctionType->getExtInfo());
8785 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008786
8787 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008788 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008789 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008790
8791 if (!oldBlock->blockMissingReturnType()) {
8792 blockScope->HasImplicitReturnType = false;
8793 blockScope->ReturnType = exprResultType;
8794 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008795
John McCall711c52b2011-01-05 12:14:39 +00008796 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008797 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008798 if (body.isInvalid()) {
8799 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008800 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008801 }
John McCall711c52b2011-01-05 12:14:39 +00008802
John McCallc6ac9c32011-02-04 18:33:18 +00008803#ifndef NDEBUG
8804 // In builds with assertions, make sure that we captured everything we
8805 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008806 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8807 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8808 e = oldBlock->capture_end(); i != e; ++i) {
8809 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008810
Douglas Gregorfc921372011-05-20 15:32:55 +00008811 // Ignore parameter packs.
8812 if (isa<ParmVarDecl>(oldCapture) &&
8813 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8814 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008815
Douglas Gregorfc921372011-05-20 15:32:55 +00008816 VarDecl *newCapture =
8817 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8818 oldCapture));
8819 assert(blockScope->CaptureMap.count(newCapture));
8820 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008821 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008822 }
8823#endif
8824
8825 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8826 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008827}
8828
Mike Stump1eb44332009-09-09 15:08:12 +00008829template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008830ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008831TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008832 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008833}
Eli Friedman276b0612011-10-11 02:20:01 +00008834
8835template<typename Derived>
8836ExprResult
8837TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008838 QualType RetTy = getDerived().TransformType(E->getType());
8839 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008840 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008841 SubExprs.reserve(E->getNumSubExprs());
8842 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8843 SubExprs, &ArgumentChanged))
8844 return ExprError();
8845
8846 if (!getDerived().AlwaysRebuild() &&
8847 !ArgumentChanged)
8848 return SemaRef.Owned(E);
8849
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008850 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008851 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008852}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008853
Douglas Gregorb98b1992009-08-11 05:31:07 +00008854//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008855// Type reconstruction
8856//===----------------------------------------------------------------------===//
8857
Mike Stump1eb44332009-09-09 15:08:12 +00008858template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008859QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8860 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008861 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008862 getDerived().getBaseEntity());
8863}
8864
Mike Stump1eb44332009-09-09 15:08:12 +00008865template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008866QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8867 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008868 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008869 getDerived().getBaseEntity());
8870}
8871
Mike Stump1eb44332009-09-09 15:08:12 +00008872template<typename Derived>
8873QualType
John McCall85737a72009-10-30 00:06:24 +00008874TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8875 bool WrittenAsLValue,
8876 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008877 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008878 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008879}
8880
8881template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008882QualType
John McCall85737a72009-10-30 00:06:24 +00008883TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8884 QualType ClassType,
8885 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008886 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008887 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008888}
8889
8890template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008891QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008892TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8893 ArrayType::ArraySizeModifier SizeMod,
8894 const llvm::APInt *Size,
8895 Expr *SizeExpr,
8896 unsigned IndexTypeQuals,
8897 SourceRange BracketsRange) {
8898 if (SizeExpr || !Size)
8899 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8900 IndexTypeQuals, BracketsRange,
8901 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008902
8903 QualType Types[] = {
8904 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8905 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8906 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008907 };
8908 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8909 QualType SizeType;
8910 for (unsigned I = 0; I != NumTypes; ++I)
8911 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8912 SizeType = Types[I];
8913 break;
8914 }
Mike Stump1eb44332009-09-09 15:08:12 +00008915
Eli Friedman01f276d2012-01-25 23:20:27 +00008916 // Note that we can return a VariableArrayType here in the case where
8917 // the element type was a dependent VariableArrayType.
8918 IntegerLiteral *ArraySize
8919 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8920 /*FIXME*/BracketsRange.getBegin());
8921 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008922 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008923 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008924}
Mike Stump1eb44332009-09-09 15:08:12 +00008925
Douglas Gregor577f75a2009-08-04 16:50:30 +00008926template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008927QualType
8928TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008929 ArrayType::ArraySizeModifier SizeMod,
8930 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008931 unsigned IndexTypeQuals,
8932 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008933 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008934 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008935}
8936
8937template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008938QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008939TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008940 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008941 unsigned IndexTypeQuals,
8942 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008943 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008944 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008945}
Mike Stump1eb44332009-09-09 15:08:12 +00008946
Douglas Gregor577f75a2009-08-04 16:50:30 +00008947template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008948QualType
8949TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008950 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008951 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008952 unsigned IndexTypeQuals,
8953 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008954 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008955 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008956 IndexTypeQuals, BracketsRange);
8957}
8958
8959template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008960QualType
8961TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008962 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008963 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008964 unsigned IndexTypeQuals,
8965 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008966 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008967 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008968 IndexTypeQuals, BracketsRange);
8969}
8970
8971template<typename Derived>
8972QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008973 unsigned NumElements,
8974 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008975 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008976 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008977}
Mike Stump1eb44332009-09-09 15:08:12 +00008978
Douglas Gregor577f75a2009-08-04 16:50:30 +00008979template<typename Derived>
8980QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8981 unsigned NumElements,
8982 SourceLocation AttributeLoc) {
8983 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8984 NumElements, true);
8985 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008986 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8987 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008988 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008989}
Mike Stump1eb44332009-09-09 15:08:12 +00008990
Douglas Gregor577f75a2009-08-04 16:50:30 +00008991template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008992QualType
8993TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008994 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008995 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008996 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008997}
Mike Stump1eb44332009-09-09 15:08:12 +00008998
Douglas Gregor577f75a2009-08-04 16:50:30 +00008999template<typename Derived>
9000QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00009001 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009002 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00009003 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009004 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00009005 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00009006 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00009007 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00009008 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009009 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009010 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009011 getDerived().getBaseEntity(),
9012 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009013}
Mike Stump1eb44332009-09-09 15:08:12 +00009014
Douglas Gregor577f75a2009-08-04 16:50:30 +00009015template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009016QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9017 return SemaRef.Context.getFunctionNoProtoType(T);
9018}
9019
9020template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009021QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9022 assert(D && "no decl found");
9023 if (D->isInvalidDecl()) return QualType();
9024
Douglas Gregor92e986e2010-04-22 16:44:27 +00009025 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009026 TypeDecl *Ty;
9027 if (isa<UsingDecl>(D)) {
9028 UsingDecl *Using = cast<UsingDecl>(D);
9029 assert(Using->isTypeName() &&
9030 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9031
9032 // A valid resolved using typename decl points to exactly one type decl.
9033 assert(++Using->shadow_begin() == Using->shadow_end());
9034 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009035
John McCalled976492009-12-04 22:46:56 +00009036 } else {
9037 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9038 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9039 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9040 }
9041
9042 return SemaRef.Context.getTypeDeclType(Ty);
9043}
9044
9045template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009046QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9047 SourceLocation Loc) {
9048 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009049}
9050
9051template<typename Derived>
9052QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9053 return SemaRef.Context.getTypeOfType(Underlying);
9054}
9055
9056template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009057QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9058 SourceLocation Loc) {
9059 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009060}
9061
9062template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009063QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9064 UnaryTransformType::UTTKind UKind,
9065 SourceLocation Loc) {
9066 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9067}
9068
9069template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009070QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009071 TemplateName Template,
9072 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009073 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009074 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009075}
Mike Stump1eb44332009-09-09 15:08:12 +00009076
Douglas Gregordcee1a12009-08-06 05:28:30 +00009077template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009078QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9079 SourceLocation KWLoc) {
9080 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9081}
9082
9083template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009084TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009085TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009086 bool TemplateKW,
9087 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009088 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009089 Template);
9090}
9091
9092template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009093TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009094TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9095 const IdentifierInfo &Name,
9096 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009097 QualType ObjectType,
9098 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009099 UnqualifiedId TemplateName;
9100 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009101 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009102 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009103 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009104 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009105 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009106 /*EnteringContext=*/false,
9107 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009108 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009109}
Mike Stump1eb44332009-09-09 15:08:12 +00009110
Douglas Gregorb98b1992009-08-11 05:31:07 +00009111template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009112TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009113TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009114 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009115 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009116 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009117 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009118 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009119 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009120 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009121 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009122 Sema::TemplateTy Template;
9123 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009124 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009125 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009126 /*EnteringContext=*/false,
9127 Template);
9128 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009129}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009130
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009131template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009132ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009133TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9134 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009135 Expr *OrigCallee,
9136 Expr *First,
9137 Expr *Second) {
9138 Expr *Callee = OrigCallee->IgnoreParenCasts();
9139 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009140
Douglas Gregorb98b1992009-08-11 05:31:07 +00009141 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009142 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009143 if (!First->getType()->isOverloadableType() &&
9144 !Second->getType()->isOverloadableType())
9145 return getSema().CreateBuiltinArraySubscriptExpr(First,
9146 Callee->getLocStart(),
9147 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009148 } else if (Op == OO_Arrow) {
9149 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009150 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9151 } else if (Second == 0 || isPostIncDec) {
9152 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009153 // The argument is not of overloadable type, so try to create a
9154 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009155 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009156 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009157
John McCall9ae2f072010-08-23 23:25:46 +00009158 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009159 }
9160 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009161 if (!First->getType()->isOverloadableType() &&
9162 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009163 // Neither of the arguments is an overloadable type, so try to
9164 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009165 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009166 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009167 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009168 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009169 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009170
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009171 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009172 }
9173 }
Mike Stump1eb44332009-09-09 15:08:12 +00009174
9175 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009176 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009177 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009178
John McCall9ae2f072010-08-23 23:25:46 +00009179 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009180 assert(ULE->requiresADL());
9181
9182 // FIXME: Do we have to check
9183 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009184 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009185 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009186 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00009187 }
Mike Stump1eb44332009-09-09 15:08:12 +00009188
Douglas Gregorb98b1992009-08-11 05:31:07 +00009189 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009190 Expr *Args[2] = { First, Second };
9191 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009192
Douglas Gregorb98b1992009-08-11 05:31:07 +00009193 // Create the overloaded operator invocation for unary operators.
9194 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009195 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009196 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009197 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009198 }
Mike Stump1eb44332009-09-09 15:08:12 +00009199
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009200 if (Op == OO_Subscript) {
9201 SourceLocation LBrace;
9202 SourceLocation RBrace;
9203
9204 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9205 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9206 LBrace = SourceLocation::getFromRawEncoding(
9207 NameLoc.CXXOperatorName.BeginOpNameLoc);
9208 RBrace = SourceLocation::getFromRawEncoding(
9209 NameLoc.CXXOperatorName.EndOpNameLoc);
9210 } else {
9211 LBrace = Callee->getLocStart();
9212 RBrace = OpLoc;
9213 }
9214
9215 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9216 First, Second);
9217 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009218
Douglas Gregorb98b1992009-08-11 05:31:07 +00009219 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009220 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009221 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009222 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9223 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009224 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009225
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009226 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009227}
Mike Stump1eb44332009-09-09 15:08:12 +00009228
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009229template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009230ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009231TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009232 SourceLocation OperatorLoc,
9233 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009234 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009235 TypeSourceInfo *ScopeType,
9236 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009237 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009238 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009239 QualType BaseType = Base->getType();
9240 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009241 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009242 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009243 !BaseType->getAs<PointerType>()->getPointeeType()
9244 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009245 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009246 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009247 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009248 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009249 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009250 /*FIXME?*/true);
9251 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009252
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009253 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009254 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9255 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9256 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9257 NameInfo.setNamedTypeInfo(DestroyedType);
9258
Richard Smith6314db92012-05-15 06:15:11 +00009259 // The scope type is now known to be a valid nested name specifier
9260 // component. Tack it on to the end of the nested name specifier.
9261 if (ScopeType)
9262 SS.Extend(SemaRef.Context, SourceLocation(),
9263 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009264
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009265 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009266 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009267 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009268 SS, TemplateKWLoc,
9269 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009270 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009271 /*TemplateArgs*/ 0);
9272}
9273
Douglas Gregor577f75a2009-08-04 16:50:30 +00009274} // end namespace clang
9275
9276#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H