blob: 90d5840378170b026f0cd915d19087360a45e0d1 [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.
John McCall60d7b3a2010-08-24 06:29:42 +00001165 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001166 bool IsSimple,
1167 bool IsVolatile,
1168 unsigned NumOutputs,
1169 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001170 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001171 MultiExprArg Constraints,
1172 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001173 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001174 MultiExprArg Clobbers,
1175 SourceLocation RParenLoc,
1176 bool MSAsm) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001177 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001178 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001179 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001180 RParenLoc, MSAsm);
1181 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001182
Chad Rosier8cd64b42012-06-11 20:47:18 +00001183 /// \brief Build a new MS style inline asm statement.
1184 ///
1185 /// By default, performs semantic analysis to build the new statement.
1186 /// Subclasses may override this routine to provide different behavior.
1187 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc,
Chad Rosier79efe242012-08-07 00:29:06 +00001188 ArrayRef<Token> AsmToks,
Chad Rosier62f22b82012-08-08 19:48:07 +00001189 ArrayRef<unsigned> LineEnds,
Chad Rosier8cd64b42012-06-11 20:47:18 +00001190 SourceLocation EndLoc) {
Chad Rosier62f22b82012-08-08 19:48:07 +00001191 return getSema().ActOnMSAsmStmt(AsmLoc, AsmToks, LineEnds, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001192 }
1193
James Dennett699c9042012-06-15 07:13:21 +00001194 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001195 ///
1196 /// By default, performs semantic analysis to build the new statement.
1197 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001198 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001199 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001200 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001201 Stmt *Finally) {
1202 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1203 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001204 }
1205
Douglas Gregorbe270a02010-04-26 17:57:08 +00001206 /// \brief Rebuild an Objective-C exception declaration.
1207 ///
1208 /// By default, performs semantic analysis to build the new declaration.
1209 /// Subclasses may override this routine to provide different behavior.
1210 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1211 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001212 return getSema().BuildObjCExceptionDecl(TInfo, T,
1213 ExceptionDecl->getInnerLocStart(),
1214 ExceptionDecl->getLocation(),
1215 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001216 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001217
James Dennett699c9042012-06-15 07:13:21 +00001218 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001219 ///
1220 /// By default, performs semantic analysis to build the new statement.
1221 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001222 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001223 SourceLocation RParenLoc,
1224 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001225 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001226 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001227 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001228 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001229
James Dennett699c9042012-06-15 07:13:21 +00001230 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001231 ///
1232 /// By default, performs semantic analysis to build the new statement.
1233 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001234 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001235 Stmt *Body) {
1236 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001237 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001238
James Dennett699c9042012-06-15 07:13:21 +00001239 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001240 ///
1241 /// By default, performs semantic analysis to build the new statement.
1242 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001243 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001244 Expr *Operand) {
1245 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001246 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001247
James Dennett699c9042012-06-15 07:13:21 +00001248 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001249 ///
1250 /// By default, performs semantic analysis to build the new statement.
1251 /// Subclasses may override this routine to provide different behavior.
1252 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1253 Expr *object) {
1254 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1255 }
1256
James Dennett699c9042012-06-15 07:13:21 +00001257 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001258 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001259 /// By default, performs semantic analysis to build the new statement.
1260 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001261 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001262 Expr *Object, Stmt *Body) {
1263 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001264 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001265
James Dennett699c9042012-06-15 07:13:21 +00001266 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001267 ///
1268 /// By default, performs semantic analysis to build the new statement.
1269 /// Subclasses may override this routine to provide different behavior.
1270 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1271 Stmt *Body) {
1272 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1273 }
John McCall990567c2011-07-27 01:07:15 +00001274
Douglas Gregorc3203e72010-04-22 23:10:45 +00001275 /// \brief Build a new Objective-C fast enumeration statement.
1276 ///
1277 /// By default, performs semantic analysis to build the new statement.
1278 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001279 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001280 SourceLocation LParenLoc,
1281 Stmt *Element,
1282 Expr *Collection,
1283 SourceLocation RParenLoc,
1284 Stmt *Body) {
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001285 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
1286 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001287 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001288 RParenLoc);
1289 if (ForEachStmt.isInvalid())
1290 return StmtError();
1291
1292 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001293 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001294
Douglas Gregor43959a92009-08-20 07:17:43 +00001295 /// \brief Build a new C++ exception declaration.
1296 ///
1297 /// By default, performs semantic analysis to build the new decaration.
1298 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001299 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001300 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001301 SourceLocation StartLoc,
1302 SourceLocation IdLoc,
1303 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001304 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1305 StartLoc, IdLoc, Id);
1306 if (Var)
1307 getSema().CurContext->addDecl(Var);
1308 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001309 }
1310
1311 /// \brief Build a new C++ catch statement.
1312 ///
1313 /// By default, performs semantic analysis to build the new statement.
1314 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001315 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001316 VarDecl *ExceptionDecl,
1317 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001318 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1319 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001320 }
Mike Stump1eb44332009-09-09 15:08:12 +00001321
Douglas Gregor43959a92009-08-20 07:17:43 +00001322 /// \brief Build a new C++ try statement.
1323 ///
1324 /// By default, performs semantic analysis to build the new statement.
1325 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001326 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001327 Stmt *TryBlock,
1328 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001329 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001330 }
Mike Stump1eb44332009-09-09 15:08:12 +00001331
Richard Smithad762fc2011-04-14 22:09:26 +00001332 /// \brief Build a new C++0x range-based for statement.
1333 ///
1334 /// By default, performs semantic analysis to build the new statement.
1335 /// Subclasses may override this routine to provide different behavior.
1336 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1337 SourceLocation ColonLoc,
1338 Stmt *Range, Stmt *BeginEnd,
1339 Expr *Cond, Expr *Inc,
1340 Stmt *LoopVar,
1341 SourceLocation RParenLoc) {
1342 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1343 Cond, Inc, LoopVar, RParenLoc);
1344 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001345
1346 /// \brief Build a new C++0x range-based for statement.
1347 ///
1348 /// By default, performs semantic analysis to build the new statement.
1349 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001350 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001351 bool IsIfExists,
1352 NestedNameSpecifierLoc QualifierLoc,
1353 DeclarationNameInfo NameInfo,
1354 Stmt *Nested) {
1355 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1356 QualifierLoc, NameInfo, Nested);
1357 }
1358
Richard Smithad762fc2011-04-14 22:09:26 +00001359 /// \brief Attach body to a C++0x range-based for statement.
1360 ///
1361 /// By default, performs semantic analysis to finish the new statement.
1362 /// Subclasses may override this routine to provide different behavior.
1363 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1364 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1365 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001366
John Wiegley28bbe4b2011-04-28 01:08:34 +00001367 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1368 SourceLocation TryLoc,
1369 Stmt *TryBlock,
1370 Stmt *Handler) {
1371 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1372 }
1373
1374 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1375 Expr *FilterExpr,
1376 Stmt *Block) {
1377 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1378 }
1379
1380 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1381 Stmt *Block) {
1382 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1383 }
1384
Douglas Gregorb98b1992009-08-11 05:31:07 +00001385 /// \brief Build a new expression that references a declaration.
1386 ///
1387 /// By default, performs semantic analysis to build the new expression.
1388 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001389 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001390 LookupResult &R,
1391 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001392 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1393 }
1394
1395
1396 /// \brief Build a new expression that references a declaration.
1397 ///
1398 /// By default, performs semantic analysis to build the new expression.
1399 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001400 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001401 ValueDecl *VD,
1402 const DeclarationNameInfo &NameInfo,
1403 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001404 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001405 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001406
1407 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001408
1409 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001410 }
Mike Stump1eb44332009-09-09 15:08:12 +00001411
Douglas Gregorb98b1992009-08-11 05:31:07 +00001412 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001413 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001414 /// By default, performs semantic analysis to build the new expression.
1415 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001416 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001417 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001418 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001419 }
1420
Douglas Gregora71d8192009-09-04 17:36:40 +00001421 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001422 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001423 /// By default, performs semantic analysis to build the new expression.
1424 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001425 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001426 SourceLocation OperatorLoc,
1427 bool isArrow,
1428 CXXScopeSpec &SS,
1429 TypeSourceInfo *ScopeType,
1430 SourceLocation CCLoc,
1431 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001432 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001433
Douglas Gregorb98b1992009-08-11 05:31:07 +00001434 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001435 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001436 /// 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 RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001439 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001440 Expr *SubExpr) {
1441 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001442 }
Mike Stump1eb44332009-09-09 15:08:12 +00001443
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001444 /// \brief Build a new builtin offsetof expression.
1445 ///
1446 /// By default, performs semantic analysis to build the new expression.
1447 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001448 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001449 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001450 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001451 unsigned NumComponents,
1452 SourceLocation RParenLoc) {
1453 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1454 NumComponents, RParenLoc);
1455 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001456
1457 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001458 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001459 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001460 /// By default, performs semantic analysis to build the new expression.
1461 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001462 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1463 SourceLocation OpLoc,
1464 UnaryExprOrTypeTrait ExprKind,
1465 SourceRange R) {
1466 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001467 }
1468
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001469 /// \brief Build a new sizeof, alignof or vec step expression with an
1470 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001471 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001472 /// By default, performs semantic analysis to build the new expression.
1473 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001474 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1475 UnaryExprOrTypeTrait ExprKind,
1476 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001477 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001478 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001479 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001480 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001481
Douglas Gregorb98b1992009-08-11 05:31:07 +00001482 return move(Result);
1483 }
Mike Stump1eb44332009-09-09 15:08:12 +00001484
Douglas Gregorb98b1992009-08-11 05:31:07 +00001485 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001486 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001487 /// By default, performs semantic analysis to build the new expression.
1488 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001489 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001490 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001491 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001492 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001493 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1494 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001495 RBracketLoc);
1496 }
1497
1498 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001499 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001500 /// By default, performs semantic analysis to build the new expression.
1501 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001502 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001503 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001504 SourceLocation RParenLoc,
1505 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001506 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001507 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001508 }
1509
1510 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001511 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001512 /// By default, performs semantic analysis to build the new expression.
1513 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001514 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001515 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001516 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001517 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001518 const DeclarationNameInfo &MemberNameInfo,
1519 ValueDecl *Member,
1520 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001521 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001522 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001523 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1524 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001525 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001526 // We have a reference to an unnamed field. This is always the
1527 // base of an anonymous struct/union member access, i.e. the
1528 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001529 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001530 assert(Member->getType()->isRecordType() &&
1531 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001532
Richard Smith9138b4e2011-10-26 19:06:56 +00001533 BaseResult =
1534 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001535 QualifierLoc.getNestedNameSpecifier(),
1536 FoundDecl, Member);
1537 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001538 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001539 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001540 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001541 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001542 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001543 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001544 cast<FieldDecl>(Member)->getType(),
1545 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001546 return getSema().Owned(ME);
1547 }
Mike Stump1eb44332009-09-09 15:08:12 +00001548
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001549 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001550 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001551
John Wiegley429bb272011-04-08 18:41:53 +00001552 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001553 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001554
John McCall6bb80172010-03-30 21:47:33 +00001555 // FIXME: this involves duplicating earlier analysis in a lot of
1556 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001557 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001558 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001559 R.resolveKind();
1560
John McCall9ae2f072010-08-23 23:25:46 +00001561 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001562 SS, TemplateKWLoc,
1563 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001564 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001565 }
Mike Stump1eb44332009-09-09 15:08:12 +00001566
Douglas Gregorb98b1992009-08-11 05:31:07 +00001567 /// \brief Build a new binary 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 RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001572 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001573 Expr *LHS, Expr *RHS) {
1574 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001575 }
1576
1577 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001578 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001579 /// By default, performs semantic analysis to build the new expression.
1580 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001581 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001582 SourceLocation QuestionLoc,
1583 Expr *LHS,
1584 SourceLocation ColonLoc,
1585 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001586 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1587 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001588 }
1589
Douglas Gregorb98b1992009-08-11 05:31:07 +00001590 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001591 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001592 /// By default, performs semantic analysis to build the new expression.
1593 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001594 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001595 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001596 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001597 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001598 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001599 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001600 }
Mike Stump1eb44332009-09-09 15:08:12 +00001601
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001603 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001604 /// By default, performs semantic analysis to build the new expression.
1605 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001606 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001607 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001608 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001609 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001610 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001611 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001612 }
Mike Stump1eb44332009-09-09 15:08:12 +00001613
Douglas Gregorb98b1992009-08-11 05:31:07 +00001614 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001615 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001616 /// By default, performs semantic analysis to build the new expression.
1617 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001618 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001619 SourceLocation OpLoc,
1620 SourceLocation AccessorLoc,
1621 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001622
John McCall129e2df2009-11-30 22:42:35 +00001623 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001624 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001625 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001626 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001627 SS, SourceLocation(),
1628 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001629 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001630 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001631 }
Mike Stump1eb44332009-09-09 15:08:12 +00001632
Douglas Gregorb98b1992009-08-11 05:31:07 +00001633 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001634 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001635 /// By default, performs semantic analysis to build the new expression.
1636 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001637 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001638 MultiExprArg Inits,
1639 SourceLocation RBraceLoc,
1640 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001641 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001642 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1643 if (Result.isInvalid() || ResultTy->isDependentType())
1644 return move(Result);
Chad Rosier4a9d7952012-08-08 18:46:20 +00001645
Douglas Gregore48319a2009-11-09 17:16:50 +00001646 // Patch in the result type we were given, which may have been computed
1647 // when the initial InitListExpr was built.
1648 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1649 ILE->setType(ResultTy);
1650 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001651 }
Mike Stump1eb44332009-09-09 15:08:12 +00001652
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001654 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001655 /// By default, performs semantic analysis to build the new expression.
1656 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001657 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001658 MultiExprArg ArrayExprs,
1659 SourceLocation EqualOrColonLoc,
1660 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001661 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001662 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001663 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001664 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001665 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001666 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001667
Douglas Gregorb98b1992009-08-11 05:31:07 +00001668 ArrayExprs.release();
1669 return move(Result);
1670 }
Mike Stump1eb44332009-09-09 15:08:12 +00001671
Douglas Gregorb98b1992009-08-11 05:31:07 +00001672 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001673 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001674 /// By default, builds the implicit value initialization without performing
1675 /// any semantic analysis. Subclasses may override this routine to provide
1676 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001677 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001678 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1679 }
Mike Stump1eb44332009-09-09 15:08:12 +00001680
Douglas Gregorb98b1992009-08-11 05:31:07 +00001681 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001682 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001683 /// By default, performs semantic analysis to build the new expression.
1684 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001685 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001686 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001687 SourceLocation RParenLoc) {
1688 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001689 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001690 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001691 }
1692
1693 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001694 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001695 /// By default, performs semantic analysis to build the new expression.
1696 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001697 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001698 MultiExprArg SubExprs,
1699 SourceLocation RParenLoc) {
1700 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001701 }
Mike Stump1eb44332009-09-09 15:08:12 +00001702
Douglas Gregorb98b1992009-08-11 05:31:07 +00001703 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001704 ///
1705 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001706 /// rather than attempting to map the label statement itself.
1707 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001708 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001709 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001710 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001711 }
Mike Stump1eb44332009-09-09 15:08:12 +00001712
Douglas Gregorb98b1992009-08-11 05:31:07 +00001713 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001714 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001715 /// By default, performs semantic analysis to build the new expression.
1716 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001717 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001718 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001719 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001720 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001721 }
Mike Stump1eb44332009-09-09 15:08:12 +00001722
Douglas Gregorb98b1992009-08-11 05:31:07 +00001723 /// \brief Build a new __builtin_choose_expr expression.
1724 ///
1725 /// By default, performs semantic analysis to build the new expression.
1726 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001727 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001728 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001729 SourceLocation RParenLoc) {
1730 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001731 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001732 RParenLoc);
1733 }
Mike Stump1eb44332009-09-09 15:08:12 +00001734
Peter Collingbournef111d932011-04-15 00:35:48 +00001735 /// \brief Build a new generic selection expression.
1736 ///
1737 /// By default, performs semantic analysis to build the new expression.
1738 /// Subclasses may override this routine to provide different behavior.
1739 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1740 SourceLocation DefaultLoc,
1741 SourceLocation RParenLoc,
1742 Expr *ControllingExpr,
1743 TypeSourceInfo **Types,
1744 Expr **Exprs,
1745 unsigned NumAssocs) {
1746 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1747 ControllingExpr, Types, Exprs,
1748 NumAssocs);
1749 }
1750
Douglas Gregorb98b1992009-08-11 05:31:07 +00001751 /// \brief Build a new overloaded operator call expression.
1752 ///
1753 /// By default, performs semantic analysis to build the new expression.
1754 /// The semantic analysis provides the behavior of template instantiation,
1755 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001756 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001757 /// argument-dependent lookup, etc. Subclasses may override this routine to
1758 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001759 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001760 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001761 Expr *Callee,
1762 Expr *First,
1763 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001764
1765 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001766 /// reinterpret_cast.
1767 ///
1768 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001769 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001770 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001771 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001772 Stmt::StmtClass Class,
1773 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001774 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001775 SourceLocation RAngleLoc,
1776 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001777 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001778 SourceLocation RParenLoc) {
1779 switch (Class) {
1780 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001781 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001782 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001783 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001784
1785 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001786 return getDerived().RebuildCXXDynamicCastExpr(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 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001791 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001792 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001793 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001794 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001795
Douglas Gregorb98b1992009-08-11 05:31:07 +00001796 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001797 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001798 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001799 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001800
Douglas Gregorb98b1992009-08-11 05:31:07 +00001801 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001802 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001803 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001804 }
Mike Stump1eb44332009-09-09 15:08:12 +00001805
Douglas Gregorb98b1992009-08-11 05:31:07 +00001806 /// \brief Build a new C++ static_cast expression.
1807 ///
1808 /// By default, performs semantic analysis to build the new expression.
1809 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001810 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001811 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001812 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001813 SourceLocation RAngleLoc,
1814 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001815 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001816 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001817 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001818 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001819 SourceRange(LAngleLoc, RAngleLoc),
1820 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001821 }
1822
1823 /// \brief Build a new C++ dynamic_cast expression.
1824 ///
1825 /// By default, performs semantic analysis to build the new expression.
1826 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001827 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001828 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001829 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001830 SourceLocation RAngleLoc,
1831 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001832 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001833 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001834 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001835 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001836 SourceRange(LAngleLoc, RAngleLoc),
1837 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001838 }
1839
1840 /// \brief Build a new C++ reinterpret_cast expression.
1841 ///
1842 /// By default, performs semantic analysis to build the new expression.
1843 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001844 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001845 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001846 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001847 SourceLocation RAngleLoc,
1848 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001849 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001850 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001851 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001852 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001853 SourceRange(LAngleLoc, RAngleLoc),
1854 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001855 }
1856
1857 /// \brief Build a new C++ const_cast expression.
1858 ///
1859 /// By default, performs semantic analysis to build the new expression.
1860 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001861 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001862 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001863 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001864 SourceLocation RAngleLoc,
1865 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001866 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001867 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001868 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001869 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001870 SourceRange(LAngleLoc, RAngleLoc),
1871 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001872 }
Mike Stump1eb44332009-09-09 15:08:12 +00001873
Douglas Gregorb98b1992009-08-11 05:31:07 +00001874 /// \brief Build a new C++ functional-style cast expression.
1875 ///
1876 /// By default, performs semantic analysis to build the new expression.
1877 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001878 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1879 SourceLocation LParenLoc,
1880 Expr *Sub,
1881 SourceLocation RParenLoc) {
1882 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001883 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001884 RParenLoc);
1885 }
Mike Stump1eb44332009-09-09 15:08:12 +00001886
Douglas Gregorb98b1992009-08-11 05:31:07 +00001887 /// \brief Build a new C++ typeid(type) expression.
1888 ///
1889 /// By default, performs semantic analysis to build the new expression.
1890 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001891 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001892 SourceLocation TypeidLoc,
1893 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001894 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001895 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001896 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001897 }
Mike Stump1eb44332009-09-09 15:08:12 +00001898
Francois Pichet01b7c302010-09-08 12:20:18 +00001899
Douglas Gregorb98b1992009-08-11 05:31:07 +00001900 /// \brief Build a new C++ typeid(expr) expression.
1901 ///
1902 /// By default, performs semantic analysis to build the new expression.
1903 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001904 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001905 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001906 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001907 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001908 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001909 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001910 }
1911
Francois Pichet01b7c302010-09-08 12:20:18 +00001912 /// \brief Build a new C++ __uuidof(type) expression.
1913 ///
1914 /// By default, performs semantic analysis to build the new expression.
1915 /// Subclasses may override this routine to provide different behavior.
1916 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1917 SourceLocation TypeidLoc,
1918 TypeSourceInfo *Operand,
1919 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001920 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00001921 RParenLoc);
1922 }
1923
1924 /// \brief Build a new C++ __uuidof(expr) expression.
1925 ///
1926 /// By default, performs semantic analysis to build the new expression.
1927 /// Subclasses may override this routine to provide different behavior.
1928 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1929 SourceLocation TypeidLoc,
1930 Expr *Operand,
1931 SourceLocation RParenLoc) {
1932 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1933 RParenLoc);
1934 }
1935
Douglas Gregorb98b1992009-08-11 05:31:07 +00001936 /// \brief Build a new C++ "this" expression.
1937 ///
1938 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001939 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001940 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001941 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001942 QualType ThisType,
1943 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001944 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001945 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001946 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1947 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001948 }
1949
1950 /// \brief Build a new C++ throw expression.
1951 ///
1952 /// By default, performs semantic analysis to build the new expression.
1953 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001954 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1955 bool IsThrownVariableInScope) {
1956 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001957 }
1958
1959 /// \brief Build a new C++ default-argument expression.
1960 ///
1961 /// By default, builds a new default-argument expression, which does not
1962 /// require any semantic analysis. Subclasses may override this routine to
1963 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001964 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001965 ParmVarDecl *Param) {
1966 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1967 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001968 }
1969
1970 /// \brief Build a new C++ zero-initialization expression.
1971 ///
1972 /// By default, performs semantic analysis to build the new expression.
1973 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001974 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1975 SourceLocation LParenLoc,
1976 SourceLocation RParenLoc) {
1977 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001978 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001979 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001980 }
Mike Stump1eb44332009-09-09 15:08:12 +00001981
Douglas Gregorb98b1992009-08-11 05:31:07 +00001982 /// \brief Build a new C++ "new" expression.
1983 ///
1984 /// By default, performs semantic analysis to build the new expression.
1985 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001986 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001987 bool UseGlobal,
1988 SourceLocation PlacementLParen,
1989 MultiExprArg PlacementArgs,
1990 SourceLocation PlacementRParen,
1991 SourceRange TypeIdParens,
1992 QualType AllocatedType,
1993 TypeSourceInfo *AllocatedTypeInfo,
1994 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001995 SourceRange DirectInitRange,
1996 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00001997 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001998 PlacementLParen,
1999 move(PlacementArgs),
2000 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002001 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002002 AllocatedType,
2003 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002004 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002005 DirectInitRange,
2006 Initializer);
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 C++ "delete" 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 RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002014 bool IsGlobalDelete,
2015 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002016 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002017 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002018 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002019 }
Mike Stump1eb44332009-09-09 15:08:12 +00002020
Douglas Gregorb98b1992009-08-11 05:31:07 +00002021 /// \brief Build a new unary type trait expression.
2022 ///
2023 /// By default, performs semantic analysis to build the new expression.
2024 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002025 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002026 SourceLocation StartLoc,
2027 TypeSourceInfo *T,
2028 SourceLocation RParenLoc) {
2029 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002030 }
2031
Francois Pichet6ad6f282010-12-07 00:08:36 +00002032 /// \brief Build a new binary 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 RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2037 SourceLocation StartLoc,
2038 TypeSourceInfo *LhsT,
2039 TypeSourceInfo *RhsT,
2040 SourceLocation RParenLoc) {
2041 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2042 }
2043
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002044 /// \brief Build a new type trait expression.
2045 ///
2046 /// By default, performs semantic analysis to build the new expression.
2047 /// Subclasses may override this routine to provide different behavior.
2048 ExprResult RebuildTypeTrait(TypeTrait Trait,
2049 SourceLocation StartLoc,
2050 ArrayRef<TypeSourceInfo *> Args,
2051 SourceLocation RParenLoc) {
2052 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2053 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002054
John Wiegley21ff2e52011-04-28 00:16:57 +00002055 /// \brief Build a new array type 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 RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2060 SourceLocation StartLoc,
2061 TypeSourceInfo *TSInfo,
2062 Expr *DimExpr,
2063 SourceLocation RParenLoc) {
2064 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2065 }
2066
John Wiegley55262202011-04-25 06:54:41 +00002067 /// \brief Build a new expression trait expression.
2068 ///
2069 /// By default, performs semantic analysis to build the new expression.
2070 /// Subclasses may override this routine to provide different behavior.
2071 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2072 SourceLocation StartLoc,
2073 Expr *Queried,
2074 SourceLocation RParenLoc) {
2075 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2076 }
2077
Mike Stump1eb44332009-09-09 15:08:12 +00002078 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002079 /// expression.
2080 ///
2081 /// By default, performs semantic analysis to build the new expression.
2082 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002083 ExprResult RebuildDependentScopeDeclRefExpr(
2084 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002085 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002086 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002087 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002088 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002089 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002090
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002091 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002092 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002093 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002094
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002095 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002096 }
2097
2098 /// \brief Build a new template-id expression.
2099 ///
2100 /// By default, performs semantic analysis to build the new expression.
2101 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002102 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002103 SourceLocation TemplateKWLoc,
2104 LookupResult &R,
2105 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002106 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002107 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2108 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002109 }
2110
2111 /// \brief Build a new object-construction expression.
2112 ///
2113 /// By default, performs semantic analysis to build the new expression.
2114 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002115 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002116 SourceLocation Loc,
2117 CXXConstructorDecl *Constructor,
2118 bool IsElidable,
2119 MultiExprArg Args,
2120 bool HadMultipleCandidates,
2121 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002122 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002123 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00002124 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002125 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002126 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002127 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002128
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002129 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002130 move_arg(ConvertedArgs),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002131 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002132 RequiresZeroInit, ConstructKind,
2133 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002134 }
2135
2136 /// \brief Build a new object-construction expression.
2137 ///
2138 /// By default, performs semantic analysis to build the new expression.
2139 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002140 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2141 SourceLocation LParenLoc,
2142 MultiExprArg Args,
2143 SourceLocation RParenLoc) {
2144 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002145 LParenLoc,
2146 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002147 RParenLoc);
2148 }
2149
2150 /// \brief Build a new object-construction expression.
2151 ///
2152 /// By default, performs semantic analysis to build the new expression.
2153 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002154 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2155 SourceLocation LParenLoc,
2156 MultiExprArg Args,
2157 SourceLocation RParenLoc) {
2158 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002159 LParenLoc,
2160 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002161 RParenLoc);
2162 }
Mike Stump1eb44332009-09-09 15:08:12 +00002163
Douglas Gregorb98b1992009-08-11 05:31:07 +00002164 /// \brief Build a new member reference expression.
2165 ///
2166 /// By default, performs semantic analysis to build the new expression.
2167 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002168 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002169 QualType BaseType,
2170 bool IsArrow,
2171 SourceLocation OperatorLoc,
2172 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002173 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002174 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002175 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002176 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002177 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002178 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002179
John McCall9ae2f072010-08-23 23:25:46 +00002180 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002181 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002182 SS, TemplateKWLoc,
2183 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002184 MemberNameInfo,
2185 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002186 }
2187
John McCall129e2df2009-11-30 22:42:35 +00002188 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002189 ///
2190 /// By default, performs semantic analysis to build the new expression.
2191 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002192 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2193 SourceLocation OperatorLoc,
2194 bool IsArrow,
2195 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002196 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002197 NamedDecl *FirstQualifierInScope,
2198 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002199 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002200 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002201 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002202
John McCall9ae2f072010-08-23 23:25:46 +00002203 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002204 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002205 SS, TemplateKWLoc,
2206 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002207 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002208 }
Mike Stump1eb44332009-09-09 15:08:12 +00002209
Sebastian Redl2e156222010-09-10 20:55:43 +00002210 /// \brief Build a new noexcept expression.
2211 ///
2212 /// By default, performs semantic analysis to build the new expression.
2213 /// Subclasses may override this routine to provide different behavior.
2214 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2215 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2216 }
2217
Douglas Gregoree8aff02011-01-04 17:33:58 +00002218 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002219 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2220 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002221 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002222 llvm::Optional<unsigned> Length) {
2223 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002224 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2225 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002226 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002227
2228 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2229 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002230 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002231 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002232
Patrick Beardeb382ec2012-04-19 00:25:12 +00002233 /// \brief Build a new Objective-C boxed expression.
2234 ///
2235 /// By default, performs semantic analysis to build the new expression.
2236 /// Subclasses may override this routine to provide different behavior.
2237 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2238 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2239 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002240
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002241 /// \brief Build a new Objective-C array literal.
2242 ///
2243 /// By default, performs semantic analysis to build the new expression.
2244 /// Subclasses may override this routine to provide different behavior.
2245 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2246 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002247 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002248 MultiExprArg(Elements, NumElements));
2249 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002250
2251 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002252 Expr *Base, Expr *Key,
2253 ObjCMethodDecl *getterMethod,
2254 ObjCMethodDecl *setterMethod) {
2255 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2256 getterMethod, setterMethod);
2257 }
2258
2259 /// \brief Build a new Objective-C dictionary literal.
2260 ///
2261 /// By default, performs semantic analysis to build the new expression.
2262 /// Subclasses may override this routine to provide different behavior.
2263 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2264 ObjCDictionaryElement *Elements,
2265 unsigned NumElements) {
2266 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2267 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002268
James Dennett699c9042012-06-15 07:13:21 +00002269 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002270 ///
2271 /// By default, performs semantic analysis to build the new expression.
2272 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002273 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002274 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002275 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002276 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002277 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002278 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002279
Douglas Gregor92e986e2010-04-22 16:44:27 +00002280 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002281 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002282 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002283 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002284 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002285 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002286 MultiExprArg Args,
2287 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002288 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2289 ReceiverTypeInfo->getType(),
2290 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002291 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002292 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002293 }
2294
2295 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002296 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002297 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002298 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002299 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002300 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002301 MultiExprArg Args,
2302 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002303 return SemaRef.BuildInstanceMessage(Receiver,
2304 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002305 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002306 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002307 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002308 }
2309
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002310 /// \brief Build a new Objective-C ivar reference expression.
2311 ///
2312 /// By default, performs semantic analysis to build the new expression.
2313 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002314 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002315 SourceLocation IvarLoc,
2316 bool IsArrow, bool IsFreeIvar) {
2317 // FIXME: We lose track of the IsFreeIvar bit.
2318 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002319 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002320 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2321 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002322 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002323 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002324 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002325 false);
John Wiegley429bb272011-04-08 18:41:53 +00002326 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002327 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002328
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002329 if (Result.get())
2330 return move(Result);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002331
John Wiegley429bb272011-04-08 18:41:53 +00002332 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002333 /*FIXME:*/IvarLoc, IsArrow,
2334 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002335 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002336 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002337 /*TemplateArgs=*/0);
2338 }
Douglas Gregore3303542010-04-26 20:47:02 +00002339
2340 /// \brief Build a new Objective-C property reference expression.
2341 ///
2342 /// By default, performs semantic analysis to build the new expression.
2343 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002344 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002345 ObjCPropertyDecl *Property,
2346 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002347 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002348 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002349 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2350 Sema::LookupMemberName);
2351 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002352 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002353 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002354 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002355 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002356 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002357
Douglas Gregore3303542010-04-26 20:47:02 +00002358 if (Result.get())
2359 return move(Result);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002360
John Wiegley429bb272011-04-08 18:41:53 +00002361 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002362 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002363 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002364 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002365 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002366 /*TemplateArgs=*/0);
2367 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002368
John McCall12f78a62010-12-02 01:19:52 +00002369 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002370 ///
2371 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002372 /// Subclasses may override this routine to provide different behavior.
2373 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2374 ObjCMethodDecl *Getter,
2375 ObjCMethodDecl *Setter,
2376 SourceLocation PropertyLoc) {
2377 // Since these expressions can only be value-dependent, we do not
2378 // need to perform semantic analysis again.
2379 return Owned(
2380 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2381 VK_LValue, OK_ObjCProperty,
2382 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002383 }
2384
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002385 /// \brief Build a new Objective-C "isa" expression.
2386 ///
2387 /// By default, performs semantic analysis to build the new expression.
2388 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002389 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002390 bool IsArrow) {
2391 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002392 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002393 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2394 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002395 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002396 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002397 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002398 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002399 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002400
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002401 if (Result.get())
2402 return move(Result);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002403
John Wiegley429bb272011-04-08 18:41:53 +00002404 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002405 /*FIXME:*/IsaLoc, IsArrow,
2406 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002407 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002408 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002409 /*TemplateArgs=*/0);
2410 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002411
Douglas Gregorb98b1992009-08-11 05:31:07 +00002412 /// \brief Build a new shuffle vector expression.
2413 ///
2414 /// By default, performs semantic analysis to build the new expression.
2415 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002416 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002417 MultiExprArg SubExprs,
2418 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002419 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002420 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002421 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2422 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2423 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2424 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002425
Douglas Gregorb98b1992009-08-11 05:31:07 +00002426 // Build a reference to the __builtin_shufflevector builtin
2427 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002428 ExprResult Callee
John McCallf4b88a42012-03-10 09:33:50 +00002429 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, false,
2430 Builtin->getType(),
John Wiegley429bb272011-04-08 18:41:53 +00002431 VK_LValue, BuiltinLoc));
2432 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2433 if (Callee.isInvalid())
2434 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002435
2436 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002437 unsigned NumSubExprs = SubExprs.size();
2438 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002439 ExprResult TheCall = SemaRef.Owned(
2440 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002441 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002442 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002443 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002444 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002445
Douglas Gregorb98b1992009-08-11 05:31:07 +00002446 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002447 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002448 }
John McCall43fed0d2010-11-12 08:19:04 +00002449
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002450 /// \brief Build a new template argument pack expansion.
2451 ///
2452 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002453 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002454 /// different behavior.
2455 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002456 SourceLocation EllipsisLoc,
2457 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002458 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002459 case TemplateArgument::Expression: {
2460 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002461 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2462 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002463 if (Result.isInvalid())
2464 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002465
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002466 return TemplateArgumentLoc(Result.get(), Result.get());
2467 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002468
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002469 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002470 return TemplateArgumentLoc(TemplateArgument(
2471 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002472 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002473 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002474 Pattern.getTemplateNameLoc(),
2475 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002476
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002477 case TemplateArgument::Null:
2478 case TemplateArgument::Integral:
2479 case TemplateArgument::Declaration:
2480 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002481 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002482 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002483
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002484 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002485 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002486 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002487 EllipsisLoc,
2488 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002489 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2490 Expansion);
2491 break;
2492 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002493
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002494 return TemplateArgumentLoc();
2495 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002496
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002497 /// \brief Build a new expression pack expansion.
2498 ///
2499 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002500 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002501 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002502 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2503 llvm::Optional<unsigned> NumExpansions) {
2504 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002505 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002506
2507 /// \brief Build a new atomic operation expression.
2508 ///
2509 /// By default, performs semantic analysis to build the new expression.
2510 /// Subclasses may override this routine to provide different behavior.
2511 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2512 MultiExprArg SubExprs,
2513 QualType RetTy,
2514 AtomicExpr::AtomicOp Op,
2515 SourceLocation RParenLoc) {
2516 // Just create the expression; there is not any interesting semantic
2517 // analysis here because we can't actually build an AtomicExpr until
2518 // we are sure it is semantically sound.
2519 unsigned NumSubExprs = SubExprs.size();
2520 Expr **Subs = (Expr **)SubExprs.release();
2521 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2522 NumSubExprs, RetTy, Op,
2523 RParenLoc);
2524 }
2525
John McCall43fed0d2010-11-12 08:19:04 +00002526private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002527 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2528 QualType ObjectType,
2529 NamedDecl *FirstQualifierInScope,
2530 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002531
2532 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2533 QualType ObjectType,
2534 NamedDecl *FirstQualifierInScope,
2535 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002536};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002537
Douglas Gregor43959a92009-08-20 07:17:43 +00002538template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002539StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002540 if (!S)
2541 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002542
Douglas Gregor43959a92009-08-20 07:17:43 +00002543 switch (S->getStmtClass()) {
2544 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002545
Douglas Gregor43959a92009-08-20 07:17:43 +00002546 // Transform individual statement nodes
2547#define STMT(Node, Parent) \
2548 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002549#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002550#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002551#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002552
Douglas Gregor43959a92009-08-20 07:17:43 +00002553 // Transform expressions by calling TransformExpr.
2554#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002555#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002556#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002557#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002558 {
John McCall60d7b3a2010-08-24 06:29:42 +00002559 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002560 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002561 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002562
John McCall9ae2f072010-08-23 23:25:46 +00002563 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002564 }
Mike Stump1eb44332009-09-09 15:08:12 +00002565 }
2566
John McCall3fa5cae2010-10-26 07:05:15 +00002567 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002568}
Mike Stump1eb44332009-09-09 15:08:12 +00002569
2570
Douglas Gregor670444e2009-08-04 22:27:00 +00002571template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002572ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002573 if (!E)
2574 return SemaRef.Owned(E);
2575
2576 switch (E->getStmtClass()) {
2577 case Stmt::NoStmtClass: break;
2578#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002579#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002580#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002581 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002582#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002583 }
2584
John McCall3fa5cae2010-10-26 07:05:15 +00002585 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002586}
2587
2588template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002589bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2590 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002591 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002592 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002593 bool *ArgChanged) {
2594 for (unsigned I = 0; I != NumInputs; ++I) {
2595 // If requested, drop call arguments that need to be dropped.
2596 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2597 if (ArgChanged)
2598 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002599
Douglas Gregoraa165f82011-01-03 19:04:46 +00002600 break;
2601 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002602
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002603 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2604 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002605
Chris Lattner686775d2011-07-20 06:58:45 +00002606 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002607 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2608 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002609
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002610 // Determine whether the set of unexpanded parameter packs can and should
2611 // be expanded.
2612 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002613 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002614 llvm::Optional<unsigned> OrigNumExpansions
2615 = Expansion->getNumExpansions();
2616 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002617 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2618 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002619 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002620 Expand, RetainExpansion,
2621 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002622 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002623
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002624 if (!Expand) {
2625 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002626 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002627 // expansion.
2628 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2629 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2630 if (OutPattern.isInvalid())
2631 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002632
2633 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002634 Expansion->getEllipsisLoc(),
2635 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002636 if (Out.isInvalid())
2637 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002638
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002639 if (ArgChanged)
2640 *ArgChanged = true;
2641 Outputs.push_back(Out.get());
2642 continue;
2643 }
John McCallc8fc90a2011-07-06 07:30:07 +00002644
2645 // Record right away that the argument was changed. This needs
2646 // to happen even if the array expands to nothing.
2647 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002648
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002649 // The transform has determined that we should perform an elementwise
2650 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002651 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002652 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2653 ExprResult Out = getDerived().TransformExpr(Pattern);
2654 if (Out.isInvalid())
2655 return true;
2656
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002657 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002658 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2659 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002660 if (Out.isInvalid())
2661 return true;
2662 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002663
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002664 Outputs.push_back(Out.get());
2665 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002666
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002667 continue;
2668 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002669
Douglas Gregoraa165f82011-01-03 19:04:46 +00002670 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2671 if (Result.isInvalid())
2672 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002673
Douglas Gregoraa165f82011-01-03 19:04:46 +00002674 if (Result.get() != Inputs[I] && ArgChanged)
2675 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002676
2677 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002678 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002679
Douglas Gregoraa165f82011-01-03 19:04:46 +00002680 return false;
2681}
2682
2683template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002684NestedNameSpecifierLoc
2685TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2686 NestedNameSpecifierLoc NNS,
2687 QualType ObjectType,
2688 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002689 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002690 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002691 Qualifier = Qualifier.getPrefix())
2692 Qualifiers.push_back(Qualifier);
2693
2694 CXXScopeSpec SS;
2695 while (!Qualifiers.empty()) {
2696 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2697 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002698
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002699 switch (QNNS->getKind()) {
2700 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002701 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002702 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002703 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002704 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002705 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002706 FirstQualifierInScope, false))
2707 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002708
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002709 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002710
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002711 case NestedNameSpecifier::Namespace: {
2712 NamespaceDecl *NS
2713 = cast_or_null<NamespaceDecl>(
2714 getDerived().TransformDecl(
2715 Q.getLocalBeginLoc(),
2716 QNNS->getAsNamespace()));
2717 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2718 break;
2719 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002720
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002721 case NestedNameSpecifier::NamespaceAlias: {
2722 NamespaceAliasDecl *Alias
2723 = cast_or_null<NamespaceAliasDecl>(
2724 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2725 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002726 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002727 Q.getLocalEndLoc());
2728 break;
2729 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002730
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002731 case NestedNameSpecifier::Global:
2732 // There is no meaningful transformation that one could perform on the
2733 // global scope.
2734 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2735 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002736
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002737 case NestedNameSpecifier::TypeSpecWithTemplate:
2738 case NestedNameSpecifier::TypeSpec: {
2739 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2740 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002741
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002742 if (!TL)
2743 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002744
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002745 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00002746 (SemaRef.getLangOpts().CPlusPlus0x &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002747 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002748 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002749 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002750 if (TL.getType()->isEnumeralType())
2751 SemaRef.Diag(TL.getBeginLoc(),
2752 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002753 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2754 Q.getLocalEndLoc());
2755 break;
2756 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002757 // If the nested-name-specifier is an invalid type def, don't emit an
2758 // error because a previous error should have already been emitted.
2759 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2760 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002761 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002762 << TL.getType() << SS.getRange();
2763 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002764 return NestedNameSpecifierLoc();
2765 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002766 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002767
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002768 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002769 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002770 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002771 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002772
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002773 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002774 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002775 !getDerived().AlwaysRebuild())
2776 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002777
2778 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002779 // nested-name-specifier, do so.
2780 if (SS.location_size() == NNS.getDataLength() &&
2781 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2782 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2783
2784 // Allocate new nested-name-specifier location information.
2785 return SS.getWithLocInContext(SemaRef.Context);
2786}
2787
2788template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002789DeclarationNameInfo
2790TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002791::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002792 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002793 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002794 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002795
2796 switch (Name.getNameKind()) {
2797 case DeclarationName::Identifier:
2798 case DeclarationName::ObjCZeroArgSelector:
2799 case DeclarationName::ObjCOneArgSelector:
2800 case DeclarationName::ObjCMultiArgSelector:
2801 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002802 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002803 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002804 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002805
Douglas Gregor81499bb2009-09-03 22:13:48 +00002806 case DeclarationName::CXXConstructorName:
2807 case DeclarationName::CXXDestructorName:
2808 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002809 TypeSourceInfo *NewTInfo;
2810 CanQualType NewCanTy;
2811 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002812 NewTInfo = getDerived().TransformType(OldTInfo);
2813 if (!NewTInfo)
2814 return DeclarationNameInfo();
2815 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002816 }
2817 else {
2818 NewTInfo = 0;
2819 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002820 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002821 if (NewT.isNull())
2822 return DeclarationNameInfo();
2823 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2824 }
Mike Stump1eb44332009-09-09 15:08:12 +00002825
Abramo Bagnara25777432010-08-11 22:01:17 +00002826 DeclarationName NewName
2827 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2828 NewCanTy);
2829 DeclarationNameInfo NewNameInfo(NameInfo);
2830 NewNameInfo.setName(NewName);
2831 NewNameInfo.setNamedTypeInfo(NewTInfo);
2832 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002833 }
Mike Stump1eb44332009-09-09 15:08:12 +00002834 }
2835
David Blaikieb219cfc2011-09-23 05:06:16 +00002836 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002837}
2838
2839template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002840TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002841TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2842 TemplateName Name,
2843 SourceLocation NameLoc,
2844 QualType ObjectType,
2845 NamedDecl *FirstQualifierInScope) {
2846 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2847 TemplateDecl *Template = QTN->getTemplateDecl();
2848 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002849
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002850 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002851 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002852 Template));
2853 if (!TransTemplate)
2854 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002855
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002856 if (!getDerived().AlwaysRebuild() &&
2857 SS.getScopeRep() == QTN->getQualifier() &&
2858 TransTemplate == Template)
2859 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002860
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002861 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2862 TransTemplate);
2863 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002864
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002865 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2866 if (SS.getScopeRep()) {
2867 // These apply to the scope specifier, not the template.
2868 ObjectType = QualType();
2869 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002870 }
2871
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002872 if (!getDerived().AlwaysRebuild() &&
2873 SS.getScopeRep() == DTN->getQualifier() &&
2874 ObjectType.isNull())
2875 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002876
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002877 if (DTN->isIdentifier()) {
2878 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002879 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002880 NameLoc,
2881 ObjectType,
2882 FirstQualifierInScope);
2883 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002884
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002885 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2886 ObjectType);
2887 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002888
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002889 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2890 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002891 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002892 Template));
2893 if (!TransTemplate)
2894 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002895
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002896 if (!getDerived().AlwaysRebuild() &&
2897 TransTemplate == Template)
2898 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002899
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002900 return TemplateName(TransTemplate);
2901 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002902
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002903 if (SubstTemplateTemplateParmPackStorage *SubstPack
2904 = Name.getAsSubstTemplateTemplateParmPack()) {
2905 TemplateTemplateParmDecl *TransParam
2906 = cast_or_null<TemplateTemplateParmDecl>(
2907 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2908 if (!TransParam)
2909 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002910
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002911 if (!getDerived().AlwaysRebuild() &&
2912 TransParam == SubstPack->getParameterPack())
2913 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002914
2915 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002916 SubstPack->getArgumentPack());
2917 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002918
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002919 // These should be getting filtered out before they reach the AST.
2920 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002921}
2922
2923template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002924void TreeTransform<Derived>::InventTemplateArgumentLoc(
2925 const TemplateArgument &Arg,
2926 TemplateArgumentLoc &Output) {
2927 SourceLocation Loc = getDerived().getBaseLocation();
2928 switch (Arg.getKind()) {
2929 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002930 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002931 break;
2932
2933 case TemplateArgument::Type:
2934 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002935 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002936
John McCall833ca992009-10-29 08:12:44 +00002937 break;
2938
Douglas Gregor788cd062009-11-11 01:00:40 +00002939 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002940 case TemplateArgument::TemplateExpansion: {
2941 NestedNameSpecifierLocBuilder Builder;
2942 TemplateName Template = Arg.getAsTemplate();
2943 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2944 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2945 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2946 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002947
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002948 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002949 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002950 Builder.getWithLocInContext(SemaRef.Context),
2951 Loc);
2952 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00002953 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002954 Builder.getWithLocInContext(SemaRef.Context),
2955 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002956
Douglas Gregor788cd062009-11-11 01:00:40 +00002957 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002958 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002959
John McCall833ca992009-10-29 08:12:44 +00002960 case TemplateArgument::Expression:
2961 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2962 break;
2963
2964 case TemplateArgument::Declaration:
2965 case TemplateArgument::Integral:
2966 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002967 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002968 break;
2969 }
2970}
2971
2972template<typename Derived>
2973bool TreeTransform<Derived>::TransformTemplateArgument(
2974 const TemplateArgumentLoc &Input,
2975 TemplateArgumentLoc &Output) {
2976 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002977 switch (Arg.getKind()) {
2978 case TemplateArgument::Null:
2979 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002980 Output = Input;
2981 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002982
Douglas Gregor670444e2009-08-04 22:27:00 +00002983 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002984 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002985 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002986 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002987
2988 DI = getDerived().TransformType(DI);
2989 if (!DI) return true;
2990
2991 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2992 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002993 }
Mike Stump1eb44332009-09-09 15:08:12 +00002994
Douglas Gregor670444e2009-08-04 22:27:00 +00002995 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002996 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002997 DeclarationName Name;
2998 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2999 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00003000 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003001 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00003002 if (!D) return true;
3003
John McCall828bff22009-10-29 18:45:58 +00003004 Expr *SourceExpr = Input.getSourceDeclExpression();
3005 if (SourceExpr) {
3006 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003007 Sema::ConstantEvaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00003008 ExprResult E = getDerived().TransformExpr(SourceExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003009 E = SemaRef.ActOnConstantExpression(E);
John McCall9ae2f072010-08-23 23:25:46 +00003010 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00003011 }
3012
3013 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00003014 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003015 }
Mike Stump1eb44332009-09-09 15:08:12 +00003016
Douglas Gregor788cd062009-11-11 01:00:40 +00003017 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003018 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3019 if (QualifierLoc) {
3020 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3021 if (!QualifierLoc)
3022 return true;
3023 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003024
Douglas Gregor1d752d72011-03-02 18:46:51 +00003025 CXXScopeSpec SS;
3026 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003027 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003028 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3029 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003030 if (Template.isNull())
3031 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003032
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003033 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003034 Input.getTemplateNameLoc());
3035 return false;
3036 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003037
3038 case TemplateArgument::TemplateExpansion:
3039 llvm_unreachable("Caller should expand pack expansions");
3040
Douglas Gregor670444e2009-08-04 22:27:00 +00003041 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003042 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003043 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003044 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003045
John McCall833ca992009-10-29 08:12:44 +00003046 Expr *InputExpr = Input.getSourceExpression();
3047 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3048
Chris Lattner223de242011-04-25 20:37:58 +00003049 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003050 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003051 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003052 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003053 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003054 }
Mike Stump1eb44332009-09-09 15:08:12 +00003055
Douglas Gregor670444e2009-08-04 22:27:00 +00003056 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00003057 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00003058 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00003059 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00003060 AEnd = Arg.pack_end();
3061 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00003062
John McCall833ca992009-10-29 08:12:44 +00003063 // FIXME: preserve source information here when we start
3064 // caring about parameter packs.
3065
John McCall828bff22009-10-29 18:45:58 +00003066 TemplateArgumentLoc InputArg;
3067 TemplateArgumentLoc OutputArg;
3068 getDerived().InventTemplateArgumentLoc(*A, InputArg);
3069 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00003070 return true;
3071
John McCall828bff22009-10-29 18:45:58 +00003072 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00003073 }
Douglas Gregor910f8002010-11-07 23:05:16 +00003074
3075 TemplateArgument *TransformedArgsPtr
3076 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
3077 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
3078 TransformedArgsPtr);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003079 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
3080 TransformedArgs.size()),
Douglas Gregor910f8002010-11-07 23:05:16 +00003081 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003082 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003083 }
3084 }
Mike Stump1eb44332009-09-09 15:08:12 +00003085
Douglas Gregor670444e2009-08-04 22:27:00 +00003086 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003087 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003088}
3089
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003090/// \brief Iterator adaptor that invents template argument location information
3091/// for each of the template arguments in its underlying iterator.
3092template<typename Derived, typename InputIterator>
3093class TemplateArgumentLocInventIterator {
3094 TreeTransform<Derived> &Self;
3095 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003096
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003097public:
3098 typedef TemplateArgumentLoc value_type;
3099 typedef TemplateArgumentLoc reference;
3100 typedef typename std::iterator_traits<InputIterator>::difference_type
3101 difference_type;
3102 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003103
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003104 class pointer {
3105 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003106
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003107 public:
3108 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003109
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003110 const TemplateArgumentLoc *operator->() const { return &Arg; }
3111 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003112
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003113 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003114
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003115 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3116 InputIterator Iter)
3117 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003118
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003119 TemplateArgumentLocInventIterator &operator++() {
3120 ++Iter;
3121 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003122 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003123
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003124 TemplateArgumentLocInventIterator operator++(int) {
3125 TemplateArgumentLocInventIterator Old(*this);
3126 ++(*this);
3127 return Old;
3128 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003129
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003130 reference operator*() const {
3131 TemplateArgumentLoc Result;
3132 Self.InventTemplateArgumentLoc(*Iter, Result);
3133 return Result;
3134 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003135
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003136 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003137
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003138 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3139 const TemplateArgumentLocInventIterator &Y) {
3140 return X.Iter == Y.Iter;
3141 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003142
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003143 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3144 const TemplateArgumentLocInventIterator &Y) {
3145 return X.Iter != Y.Iter;
3146 }
3147};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003148
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003149template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003150template<typename InputIterator>
3151bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3152 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003153 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003154 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003155 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003156 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003157
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003158 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3159 // Unpack argument packs, which we translate them into separate
3160 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003161 // FIXME: We could do much better if we could guarantee that the
3162 // TemplateArgumentLocInfo for the pack expansion would be usable for
3163 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003164 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003165 TemplateArgument::pack_iterator>
3166 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003167 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003168 In.getArgument().pack_begin()),
3169 PackLocIterator(*this,
3170 In.getArgument().pack_end()),
3171 Outputs))
3172 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003173
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003174 continue;
3175 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003176
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003177 if (In.getArgument().isPackExpansion()) {
3178 // We have a pack expansion, for which we will be substituting into
3179 // the pattern.
3180 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003181 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003182 TemplateArgumentLoc Pattern
Chad Rosier4a9d7952012-08-08 18:46:20 +00003183 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
Douglas Gregorcded4f62011-01-14 17:04:44 +00003184 getSema().Context);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003185
Chris Lattner686775d2011-07-20 06:58:45 +00003186 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003187 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3188 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003189
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003190 // Determine whether the set of unexpanded parameter packs can and should
3191 // be expanded.
3192 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003193 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003194 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003195 if (getDerived().TryExpandParameterPacks(Ellipsis,
3196 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003197 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003198 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003199 RetainExpansion,
3200 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003201 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003202
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003203 if (!Expand) {
3204 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003205 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003206 // expansion.
3207 TemplateArgumentLoc OutPattern;
3208 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3209 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3210 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003211
Douglas Gregorcded4f62011-01-14 17:04:44 +00003212 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3213 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003214 if (Out.getArgument().isNull())
3215 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003216
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003217 Outputs.addArgument(Out);
3218 continue;
3219 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003220
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003221 // The transform has determined that we should perform an elementwise
3222 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003223 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003224 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3225
3226 if (getDerived().TransformTemplateArgument(Pattern, Out))
3227 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003228
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003229 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003230 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3231 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003232 if (Out.getArgument().isNull())
3233 return true;
3234 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003235
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003236 Outputs.addArgument(Out);
3237 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003238
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003239 // If we're supposed to retain a pack expansion, do so by temporarily
3240 // forgetting the partially-substituted parameter pack.
3241 if (RetainExpansion) {
3242 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003243
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003244 if (getDerived().TransformTemplateArgument(Pattern, Out))
3245 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003246
Douglas Gregorcded4f62011-01-14 17:04:44 +00003247 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3248 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003249 if (Out.getArgument().isNull())
3250 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003251
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003252 Outputs.addArgument(Out);
3253 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003254
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003255 continue;
3256 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003257
3258 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003259 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003260 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003261
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003262 Outputs.addArgument(Out);
3263 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003264
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003265 return false;
3266
3267}
3268
Douglas Gregor577f75a2009-08-04 16:50:30 +00003269//===----------------------------------------------------------------------===//
3270// Type transformation
3271//===----------------------------------------------------------------------===//
3272
3273template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003274QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003275 if (getDerived().AlreadyTransformed(T))
3276 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003277
John McCalla2becad2009-10-21 00:40:46 +00003278 // Temporary workaround. All of these transformations should
3279 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003280 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3281 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003282
John McCall43fed0d2010-11-12 08:19:04 +00003283 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003284
John McCalla2becad2009-10-21 00:40:46 +00003285 if (!NewDI)
3286 return QualType();
3287
3288 return NewDI->getType();
3289}
3290
3291template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003292TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003293 // Refine the base location to the type's location.
3294 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3295 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003296 if (getDerived().AlreadyTransformed(DI->getType()))
3297 return DI;
3298
3299 TypeLocBuilder TLB;
3300
3301 TypeLoc TL = DI->getTypeLoc();
3302 TLB.reserve(TL.getFullDataSize());
3303
John McCall43fed0d2010-11-12 08:19:04 +00003304 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003305 if (Result.isNull())
3306 return 0;
3307
John McCalla93c9342009-12-07 02:54:59 +00003308 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003309}
3310
3311template<typename Derived>
3312QualType
John McCall43fed0d2010-11-12 08:19:04 +00003313TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003314 switch (T.getTypeLocClass()) {
3315#define ABSTRACT_TYPELOC(CLASS, PARENT)
3316#define TYPELOC(CLASS, PARENT) \
3317 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003318 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003319#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003320 }
Mike Stump1eb44332009-09-09 15:08:12 +00003321
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003322 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003323}
3324
3325/// FIXME: By default, this routine adds type qualifiers only to types
3326/// that can have qualifiers, and silently suppresses those qualifiers
3327/// that are not permitted (e.g., qualifiers on reference or function
3328/// types). This is the right thing for template instantiation, but
3329/// probably not for other clients.
3330template<typename Derived>
3331QualType
3332TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003333 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003334 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003335
John McCall43fed0d2010-11-12 08:19:04 +00003336 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003337 if (Result.isNull())
3338 return QualType();
3339
3340 // Silently suppress qualifiers if the result type can't be qualified.
3341 // FIXME: this is the right thing for template instantiation, but
3342 // probably not for other clients.
3343 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003344 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003345
John McCallf85e1932011-06-15 23:02:42 +00003346 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003347 // resulting type.
3348 if (Quals.hasObjCLifetime()) {
3349 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3350 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003351 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003352 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003353 // A lifetime qualifier applied to a substituted template parameter
3354 // overrides the lifetime qualifier from the template argument.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003355 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003356 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3357 QualType Replacement = SubstTypeParam->getReplacementType();
3358 Qualifiers Qs = Replacement.getQualifiers();
3359 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003360 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003361 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3362 Qs);
3363 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003364 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003365 Replacement);
3366 TLB.TypeWasModifiedSafely(Result);
3367 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003368 // Otherwise, complain about the addition of a qualifier to an
3369 // already-qualified type.
3370 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003371 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003372 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003373
Douglas Gregore559ca12011-06-17 22:11:49 +00003374 Quals.removeObjCLifetime();
3375 }
3376 }
3377 }
John McCall28654742010-06-05 06:41:15 +00003378 if (!Quals.empty()) {
3379 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3380 TLB.push<QualifiedTypeLoc>(Result);
3381 // No location information to preserve.
3382 }
John McCalla2becad2009-10-21 00:40:46 +00003383
3384 return Result;
3385}
3386
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003387template<typename Derived>
3388TypeLoc
3389TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3390 QualType ObjectType,
3391 NamedDecl *UnqualLookup,
3392 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003393 QualType T = TL.getType();
3394 if (getDerived().AlreadyTransformed(T))
3395 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003396
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003397 TypeLocBuilder TLB;
3398 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003399
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003400 if (isa<TemplateSpecializationType>(T)) {
3401 TemplateSpecializationTypeLoc SpecTL
3402 = cast<TemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003403
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003404 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003405 getDerived().TransformTemplateName(SS,
3406 SpecTL.getTypePtr()->getTemplateName(),
3407 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003408 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003409 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003410 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003411
3412 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003413 Template);
3414 } else if (isa<DependentTemplateSpecializationType>(T)) {
3415 DependentTemplateSpecializationTypeLoc SpecTL
3416 = cast<DependentTemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003417
Douglas Gregora88f09f2011-02-28 17:23:35 +00003418 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003419 = getDerived().RebuildTemplateName(SS,
3420 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003421 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003422 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003423 if (Template.isNull())
3424 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003425
3426 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003427 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003428 Template,
3429 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003430 } else {
3431 // Nothing special needs to be done for these.
3432 Result = getDerived().TransformType(TLB, TL);
3433 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003434
3435 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003436 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003437
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003438 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3439}
3440
Douglas Gregorb71d8212011-03-02 18:32:08 +00003441template<typename Derived>
3442TypeSourceInfo *
3443TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3444 QualType ObjectType,
3445 NamedDecl *UnqualLookup,
3446 CXXScopeSpec &SS) {
3447 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003448
Douglas Gregorb71d8212011-03-02 18:32:08 +00003449 QualType T = TSInfo->getType();
3450 if (getDerived().AlreadyTransformed(T))
3451 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003452
Douglas Gregorb71d8212011-03-02 18:32:08 +00003453 TypeLocBuilder TLB;
3454 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003455
Douglas Gregorb71d8212011-03-02 18:32:08 +00003456 TypeLoc TL = TSInfo->getTypeLoc();
3457 if (isa<TemplateSpecializationType>(T)) {
3458 TemplateSpecializationTypeLoc SpecTL
3459 = cast<TemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003460
Douglas Gregorb71d8212011-03-02 18:32:08 +00003461 TemplateName Template
3462 = getDerived().TransformTemplateName(SS,
3463 SpecTL.getTypePtr()->getTemplateName(),
3464 SpecTL.getTemplateNameLoc(),
3465 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003466 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003467 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003468
3469 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003470 Template);
3471 } else if (isa<DependentTemplateSpecializationType>(T)) {
3472 DependentTemplateSpecializationTypeLoc SpecTL
3473 = cast<DependentTemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003474
Douglas Gregorb71d8212011-03-02 18:32:08 +00003475 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003476 = getDerived().RebuildTemplateName(SS,
3477 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003478 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003479 ObjectType, UnqualLookup);
3480 if (Template.isNull())
3481 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003482
3483 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003484 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003485 Template,
3486 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003487 } else {
3488 // Nothing special needs to be done for these.
3489 Result = getDerived().TransformType(TLB, TL);
3490 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003491
3492 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003493 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003494
Douglas Gregorb71d8212011-03-02 18:32:08 +00003495 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3496}
3497
John McCalla2becad2009-10-21 00:40:46 +00003498template <class TyLoc> static inline
3499QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3500 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3501 NewT.setNameLoc(T.getNameLoc());
3502 return T.getType();
3503}
3504
John McCalla2becad2009-10-21 00:40:46 +00003505template<typename Derived>
3506QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003507 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003508 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3509 NewT.setBuiltinLoc(T.getBuiltinLoc());
3510 if (T.needsExtraLocalData())
3511 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3512 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003513}
Mike Stump1eb44332009-09-09 15:08:12 +00003514
Douglas Gregor577f75a2009-08-04 16:50:30 +00003515template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003516QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003517 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003518 // FIXME: recurse?
3519 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003520}
Mike Stump1eb44332009-09-09 15:08:12 +00003521
Douglas Gregor577f75a2009-08-04 16:50:30 +00003522template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003523QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003524 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003525 QualType PointeeType
3526 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003527 if (PointeeType.isNull())
3528 return QualType();
3529
3530 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003531 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003532 // A dependent pointer type 'T *' has is being transformed such
3533 // that an Objective-C class type is being replaced for 'T'. The
3534 // resulting pointer type is an ObjCObjectPointerType, not a
3535 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003536 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003537
John McCallc12c5bb2010-05-15 11:32:37 +00003538 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3539 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003540 return Result;
3541 }
John McCall43fed0d2010-11-12 08:19:04 +00003542
Douglas Gregor92e986e2010-04-22 16:44:27 +00003543 if (getDerived().AlwaysRebuild() ||
3544 PointeeType != TL.getPointeeLoc().getType()) {
3545 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3546 if (Result.isNull())
3547 return QualType();
3548 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003549
John McCallf85e1932011-06-15 23:02:42 +00003550 // Objective-C ARC can add lifetime qualifiers to the type that we're
3551 // pointing to.
3552 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003553
Douglas Gregor92e986e2010-04-22 16:44:27 +00003554 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3555 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003556 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003557}
Mike Stump1eb44332009-09-09 15:08:12 +00003558
3559template<typename Derived>
3560QualType
John McCalla2becad2009-10-21 00:40:46 +00003561TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003562 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003563 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003564 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3565 if (PointeeType.isNull())
3566 return QualType();
3567
3568 QualType Result = TL.getType();
3569 if (getDerived().AlwaysRebuild() ||
3570 PointeeType != TL.getPointeeLoc().getType()) {
3571 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003572 TL.getSigilLoc());
3573 if (Result.isNull())
3574 return QualType();
3575 }
3576
Douglas Gregor39968ad2010-04-22 16:50:51 +00003577 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003578 NewT.setSigilLoc(TL.getSigilLoc());
3579 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003580}
3581
John McCall85737a72009-10-30 00:06:24 +00003582/// Transforms a reference type. Note that somewhat paradoxically we
3583/// don't care whether the type itself is an l-value type or an r-value
3584/// type; we only care if the type was *written* as an l-value type
3585/// or an r-value type.
3586template<typename Derived>
3587QualType
3588TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003589 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003590 const ReferenceType *T = TL.getTypePtr();
3591
3592 // Note that this works with the pointee-as-written.
3593 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3594 if (PointeeType.isNull())
3595 return QualType();
3596
3597 QualType Result = TL.getType();
3598 if (getDerived().AlwaysRebuild() ||
3599 PointeeType != T->getPointeeTypeAsWritten()) {
3600 Result = getDerived().RebuildReferenceType(PointeeType,
3601 T->isSpelledAsLValue(),
3602 TL.getSigilLoc());
3603 if (Result.isNull())
3604 return QualType();
3605 }
3606
John McCallf85e1932011-06-15 23:02:42 +00003607 // Objective-C ARC can add lifetime qualifiers to the type that we're
3608 // referring to.
3609 TLB.TypeWasModifiedSafely(
3610 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3611
John McCall85737a72009-10-30 00:06:24 +00003612 // r-value references can be rebuilt as l-value references.
3613 ReferenceTypeLoc NewTL;
3614 if (isa<LValueReferenceType>(Result))
3615 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3616 else
3617 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3618 NewTL.setSigilLoc(TL.getSigilLoc());
3619
3620 return Result;
3621}
3622
Mike Stump1eb44332009-09-09 15:08:12 +00003623template<typename Derived>
3624QualType
John McCalla2becad2009-10-21 00:40:46 +00003625TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003626 LValueReferenceTypeLoc TL) {
3627 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003628}
3629
Mike Stump1eb44332009-09-09 15:08:12 +00003630template<typename Derived>
3631QualType
John McCalla2becad2009-10-21 00:40:46 +00003632TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003633 RValueReferenceTypeLoc TL) {
3634 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003635}
Mike Stump1eb44332009-09-09 15:08:12 +00003636
Douglas Gregor577f75a2009-08-04 16:50:30 +00003637template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003638QualType
John McCalla2becad2009-10-21 00:40:46 +00003639TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003640 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003641 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003642 if (PointeeType.isNull())
3643 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003644
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003645 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3646 TypeSourceInfo* NewClsTInfo = 0;
3647 if (OldClsTInfo) {
3648 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3649 if (!NewClsTInfo)
3650 return QualType();
3651 }
3652
3653 const MemberPointerType *T = TL.getTypePtr();
3654 QualType OldClsType = QualType(T->getClass(), 0);
3655 QualType NewClsType;
3656 if (NewClsTInfo)
3657 NewClsType = NewClsTInfo->getType();
3658 else {
3659 NewClsType = getDerived().TransformType(OldClsType);
3660 if (NewClsType.isNull())
3661 return QualType();
3662 }
Mike Stump1eb44332009-09-09 15:08:12 +00003663
John McCalla2becad2009-10-21 00:40:46 +00003664 QualType Result = TL.getType();
3665 if (getDerived().AlwaysRebuild() ||
3666 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003667 NewClsType != OldClsType) {
3668 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003669 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003670 if (Result.isNull())
3671 return QualType();
3672 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003673
John McCalla2becad2009-10-21 00:40:46 +00003674 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3675 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003676 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003677
3678 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003679}
3680
Mike Stump1eb44332009-09-09 15:08:12 +00003681template<typename Derived>
3682QualType
John McCalla2becad2009-10-21 00:40:46 +00003683TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003684 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003685 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003686 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003687 if (ElementType.isNull())
3688 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003689
John McCalla2becad2009-10-21 00:40:46 +00003690 QualType Result = TL.getType();
3691 if (getDerived().AlwaysRebuild() ||
3692 ElementType != T->getElementType()) {
3693 Result = getDerived().RebuildConstantArrayType(ElementType,
3694 T->getSizeModifier(),
3695 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003696 T->getIndexTypeCVRQualifiers(),
3697 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003698 if (Result.isNull())
3699 return QualType();
3700 }
Eli Friedman457a3772012-01-25 22:19:07 +00003701
3702 // We might have either a ConstantArrayType or a VariableArrayType now:
3703 // a ConstantArrayType is allowed to have an element type which is a
3704 // VariableArrayType if the type is dependent. Fortunately, all array
3705 // types have the same location layout.
3706 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003707 NewTL.setLBracketLoc(TL.getLBracketLoc());
3708 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003709
John McCalla2becad2009-10-21 00:40:46 +00003710 Expr *Size = TL.getSizeExpr();
3711 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003712 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3713 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003714 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003715 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003716 }
3717 NewTL.setSizeExpr(Size);
3718
3719 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003720}
Mike Stump1eb44332009-09-09 15:08:12 +00003721
Douglas Gregor577f75a2009-08-04 16:50:30 +00003722template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003723QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003724 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003725 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003726 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003727 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003728 if (ElementType.isNull())
3729 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003730
John McCalla2becad2009-10-21 00:40:46 +00003731 QualType Result = TL.getType();
3732 if (getDerived().AlwaysRebuild() ||
3733 ElementType != T->getElementType()) {
3734 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003735 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003736 T->getIndexTypeCVRQualifiers(),
3737 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003738 if (Result.isNull())
3739 return QualType();
3740 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003741
John McCalla2becad2009-10-21 00:40:46 +00003742 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3743 NewTL.setLBracketLoc(TL.getLBracketLoc());
3744 NewTL.setRBracketLoc(TL.getRBracketLoc());
3745 NewTL.setSizeExpr(0);
3746
3747 return Result;
3748}
3749
3750template<typename Derived>
3751QualType
3752TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003753 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003754 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003755 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3756 if (ElementType.isNull())
3757 return QualType();
3758
John McCall60d7b3a2010-08-24 06:29:42 +00003759 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003760 = getDerived().TransformExpr(T->getSizeExpr());
3761 if (SizeResult.isInvalid())
3762 return QualType();
3763
John McCall9ae2f072010-08-23 23:25:46 +00003764 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003765
3766 QualType Result = TL.getType();
3767 if (getDerived().AlwaysRebuild() ||
3768 ElementType != T->getElementType() ||
3769 Size != T->getSizeExpr()) {
3770 Result = getDerived().RebuildVariableArrayType(ElementType,
3771 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003772 Size,
John McCalla2becad2009-10-21 00:40:46 +00003773 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003774 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003775 if (Result.isNull())
3776 return QualType();
3777 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003778
John McCalla2becad2009-10-21 00:40:46 +00003779 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3780 NewTL.setLBracketLoc(TL.getLBracketLoc());
3781 NewTL.setRBracketLoc(TL.getRBracketLoc());
3782 NewTL.setSizeExpr(Size);
3783
3784 return Result;
3785}
3786
3787template<typename Derived>
3788QualType
3789TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003790 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003791 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003792 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3793 if (ElementType.isNull())
3794 return QualType();
3795
Richard Smithf6702a32011-12-20 02:08:33 +00003796 // Array bounds are constant expressions.
3797 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3798 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003799
John McCall3b657512011-01-19 10:06:00 +00003800 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3801 Expr *origSize = TL.getSizeExpr();
3802 if (!origSize) origSize = T->getSizeExpr();
3803
3804 ExprResult sizeResult
3805 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003806 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003807 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003808 return QualType();
3809
John McCall3b657512011-01-19 10:06:00 +00003810 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003811
3812 QualType Result = TL.getType();
3813 if (getDerived().AlwaysRebuild() ||
3814 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003815 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003816 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3817 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003818 size,
John McCalla2becad2009-10-21 00:40:46 +00003819 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003820 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003821 if (Result.isNull())
3822 return QualType();
3823 }
John McCalla2becad2009-10-21 00:40:46 +00003824
3825 // We might have any sort of array type now, but fortunately they
3826 // all have the same location layout.
3827 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3828 NewTL.setLBracketLoc(TL.getLBracketLoc());
3829 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003830 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003831
3832 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003833}
Mike Stump1eb44332009-09-09 15:08:12 +00003834
3835template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003836QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003837 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003838 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003839 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003840
3841 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003842 QualType ElementType = getDerived().TransformType(T->getElementType());
3843 if (ElementType.isNull())
3844 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003845
Richard Smithf6702a32011-12-20 02:08:33 +00003846 // Vector sizes are constant expressions.
3847 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3848 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003849
John McCall60d7b3a2010-08-24 06:29:42 +00003850 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003851 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003852 if (Size.isInvalid())
3853 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003854
John McCalla2becad2009-10-21 00:40:46 +00003855 QualType Result = TL.getType();
3856 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003857 ElementType != T->getElementType() ||
3858 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003859 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003860 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003861 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003862 if (Result.isNull())
3863 return QualType();
3864 }
John McCalla2becad2009-10-21 00:40:46 +00003865
3866 // Result might be dependent or not.
3867 if (isa<DependentSizedExtVectorType>(Result)) {
3868 DependentSizedExtVectorTypeLoc NewTL
3869 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3870 NewTL.setNameLoc(TL.getNameLoc());
3871 } else {
3872 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3873 NewTL.setNameLoc(TL.getNameLoc());
3874 }
3875
3876 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003877}
Mike Stump1eb44332009-09-09 15:08:12 +00003878
3879template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003880QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003881 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003882 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003883 QualType ElementType = getDerived().TransformType(T->getElementType());
3884 if (ElementType.isNull())
3885 return QualType();
3886
John McCalla2becad2009-10-21 00:40:46 +00003887 QualType Result = TL.getType();
3888 if (getDerived().AlwaysRebuild() ||
3889 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003890 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003891 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003892 if (Result.isNull())
3893 return QualType();
3894 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003895
John McCalla2becad2009-10-21 00:40:46 +00003896 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3897 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003898
John McCalla2becad2009-10-21 00:40:46 +00003899 return Result;
3900}
3901
3902template<typename Derived>
3903QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003904 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003905 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003906 QualType ElementType = getDerived().TransformType(T->getElementType());
3907 if (ElementType.isNull())
3908 return QualType();
3909
3910 QualType Result = TL.getType();
3911 if (getDerived().AlwaysRebuild() ||
3912 ElementType != T->getElementType()) {
3913 Result = getDerived().RebuildExtVectorType(ElementType,
3914 T->getNumElements(),
3915 /*FIXME*/ SourceLocation());
3916 if (Result.isNull())
3917 return QualType();
3918 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003919
John McCalla2becad2009-10-21 00:40:46 +00003920 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3921 NewTL.setNameLoc(TL.getNameLoc());
3922
3923 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003924}
Mike Stump1eb44332009-09-09 15:08:12 +00003925
3926template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003927ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003928TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003929 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003930 llvm::Optional<unsigned> NumExpansions,
3931 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003932 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003933 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003934
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003935 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003936 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003937 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003938 TypeLoc OldTL = OldDI->getTypeLoc();
3939 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003940
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003941 TypeLocBuilder TLB;
3942 TypeLoc NewTL = OldDI->getTypeLoc();
3943 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003944
3945 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003946 OldExpansionTL.getPatternLoc());
3947 if (Result.isNull())
3948 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003949
3950 Result = RebuildPackExpansionType(Result,
3951 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003952 OldExpansionTL.getEllipsisLoc(),
3953 NumExpansions);
3954 if (Result.isNull())
3955 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003956
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003957 PackExpansionTypeLoc NewExpansionTL
3958 = TLB.push<PackExpansionTypeLoc>(Result);
3959 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3960 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3961 } else
3962 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003963 if (!NewDI)
3964 return 0;
3965
John McCallfb44de92011-05-01 22:35:37 +00003966 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003967 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003968
3969 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3970 OldParm->getDeclContext(),
3971 OldParm->getInnerLocStart(),
3972 OldParm->getLocation(),
3973 OldParm->getIdentifier(),
3974 NewDI->getType(),
3975 NewDI,
3976 OldParm->getStorageClass(),
3977 OldParm->getStorageClassAsWritten(),
3978 /* DefArg */ NULL);
3979 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3980 OldParm->getFunctionScopeIndex() + indexAdjustment);
3981 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003982}
3983
3984template<typename Derived>
3985bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003986 TransformFunctionTypeParams(SourceLocation Loc,
3987 ParmVarDecl **Params, unsigned NumParams,
3988 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003989 SmallVectorImpl<QualType> &OutParamTypes,
3990 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003991 int indexAdjustment = 0;
3992
Douglas Gregora009b592011-01-07 00:20:55 +00003993 for (unsigned i = 0; i != NumParams; ++i) {
3994 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003995 assert(OldParm->getFunctionScopeIndex() == i);
3996
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003997 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003998 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003999 if (OldParm->isParameterPack()) {
4000 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004001 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004002
Douglas Gregor603cfb42011-01-05 23:12:31 +00004003 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004004 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
4005 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
4006 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4007 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004008 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4009
Douglas Gregor603cfb42011-01-05 23:12:31 +00004010 // Determine whether we should expand the parameter packs.
4011 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004012 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004013 llvm::Optional<unsigned> OrigNumExpansions
4014 = ExpansionTL.getTypePtr()->getNumExpansions();
4015 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004016 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4017 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004018 Unexpanded,
4019 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004020 RetainExpansion,
4021 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004022 return true;
4023 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004024
Douglas Gregor603cfb42011-01-05 23:12:31 +00004025 if (ShouldExpand) {
4026 // Expand the function parameter pack into multiple, separate
4027 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004028 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004029 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004030 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004031 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004032 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004033 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004034 OrigNumExpansions,
4035 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004036 if (!NewParm)
4037 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004038
Douglas Gregora009b592011-01-07 00:20:55 +00004039 OutParamTypes.push_back(NewParm->getType());
4040 if (PVars)
4041 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004042 }
Douglas Gregord3731192011-01-10 07:32:04 +00004043
4044 // If we're supposed to retain a pack expansion, do so by temporarily
4045 // forgetting the partially-substituted parameter pack.
4046 if (RetainExpansion) {
4047 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004048 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004049 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004050 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004051 OrigNumExpansions,
4052 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004053 if (!NewParm)
4054 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004055
Douglas Gregord3731192011-01-10 07:32:04 +00004056 OutParamTypes.push_back(NewParm->getType());
4057 if (PVars)
4058 PVars->push_back(NewParm);
4059 }
4060
John McCallfb44de92011-05-01 22:35:37 +00004061 // The next parameter should have the same adjustment as the
4062 // last thing we pushed, but we post-incremented indexAdjustment
4063 // on every push. Also, if we push nothing, the adjustment should
4064 // go down by one.
4065 indexAdjustment--;
4066
Douglas Gregor603cfb42011-01-05 23:12:31 +00004067 // We're done with the pack expansion.
4068 continue;
4069 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004070
4071 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004072 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004073 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4074 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004075 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004076 NumExpansions,
4077 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004078 } else {
4079 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004080 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004081 llvm::Optional<unsigned>(),
4082 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004083 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004084
John McCall21ef0fa2010-03-11 09:03:00 +00004085 if (!NewParm)
4086 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004087
Douglas Gregora009b592011-01-07 00:20:55 +00004088 OutParamTypes.push_back(NewParm->getType());
4089 if (PVars)
4090 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004091 continue;
4092 }
John McCall21ef0fa2010-03-11 09:03:00 +00004093
4094 // Deal with the possibility that we don't have a parameter
4095 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004096 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004097 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004098 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004099 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004100 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004101 = dyn_cast<PackExpansionType>(OldType)) {
4102 // We have a function parameter pack that may need to be expanded.
4103 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004104 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004105 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004106
Douglas Gregor603cfb42011-01-05 23:12:31 +00004107 // Determine whether we should expand the parameter packs.
4108 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004109 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004110 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004111 Unexpanded,
4112 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004113 RetainExpansion,
4114 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004115 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004116 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004117
Douglas Gregor603cfb42011-01-05 23:12:31 +00004118 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004119 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004120 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004121 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004122 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4123 QualType NewType = getDerived().TransformType(Pattern);
4124 if (NewType.isNull())
4125 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004126
Douglas Gregora009b592011-01-07 00:20:55 +00004127 OutParamTypes.push_back(NewType);
4128 if (PVars)
4129 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004130 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004131
Douglas Gregor603cfb42011-01-05 23:12:31 +00004132 // We're done with the pack expansion.
4133 continue;
4134 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004135
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004136 // If we're supposed to retain a pack expansion, do so by temporarily
4137 // forgetting the partially-substituted parameter pack.
4138 if (RetainExpansion) {
4139 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4140 QualType NewType = getDerived().TransformType(Pattern);
4141 if (NewType.isNull())
4142 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004143
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004144 OutParamTypes.push_back(NewType);
4145 if (PVars)
4146 PVars->push_back(0);
4147 }
Douglas Gregord3731192011-01-10 07:32:04 +00004148
Chad Rosier4a9d7952012-08-08 18:46:20 +00004149 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004150 // expansion.
4151 OldType = Expansion->getPattern();
4152 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004153 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4154 NewType = getDerived().TransformType(OldType);
4155 } else {
4156 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004157 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004158
Douglas Gregor603cfb42011-01-05 23:12:31 +00004159 if (NewType.isNull())
4160 return true;
4161
4162 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004163 NewType = getSema().Context.getPackExpansionType(NewType,
4164 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004165
Douglas Gregora009b592011-01-07 00:20:55 +00004166 OutParamTypes.push_back(NewType);
4167 if (PVars)
4168 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004169 }
4170
John McCallfb44de92011-05-01 22:35:37 +00004171#ifndef NDEBUG
4172 if (PVars) {
4173 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4174 if (ParmVarDecl *parm = (*PVars)[i])
4175 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004176 }
John McCallfb44de92011-05-01 22:35:37 +00004177#endif
4178
4179 return false;
4180}
John McCall21ef0fa2010-03-11 09:03:00 +00004181
4182template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004183QualType
John McCalla2becad2009-10-21 00:40:46 +00004184TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004185 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004186 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4187}
4188
4189template<typename Derived>
4190QualType
4191TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4192 FunctionProtoTypeLoc TL,
4193 CXXRecordDecl *ThisContext,
4194 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004195 // Transform the parameters and return type.
4196 //
Richard Smithe6975e92012-04-17 00:58:00 +00004197 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004198 // When the function has a trailing return type, we instantiate the
4199 // parameters before the return type, since the return type can then refer
4200 // to the parameters themselves (via decltype, sizeof, etc.).
4201 //
Chris Lattner686775d2011-07-20 06:58:45 +00004202 SmallVector<QualType, 4> ParamTypes;
4203 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004204 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004205
Douglas Gregordab60ad2010-10-01 18:44:50 +00004206 QualType ResultType;
4207
4208 if (TL.getTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004209 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004210 TL.getParmArray(),
4211 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004212 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004213 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004214 return QualType();
4215
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004216 {
4217 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004218 // If a declaration declares a member function or member function
4219 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004220 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004221 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004222 // declarator.
4223 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004224
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004225 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4226 if (ResultType.isNull())
4227 return QualType();
4228 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004229 }
4230 else {
4231 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4232 if (ResultType.isNull())
4233 return QualType();
4234
Chad Rosier4a9d7952012-08-08 18:46:20 +00004235 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004236 TL.getParmArray(),
4237 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004238 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004239 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004240 return QualType();
4241 }
4242
Richard Smithe6975e92012-04-17 00:58:00 +00004243 // FIXME: Need to transform the exception-specification too.
4244
John McCalla2becad2009-10-21 00:40:46 +00004245 QualType Result = TL.getType();
4246 if (getDerived().AlwaysRebuild() ||
4247 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004248 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004249 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4250 Result = getDerived().RebuildFunctionProtoType(ResultType,
4251 ParamTypes.data(),
4252 ParamTypes.size(),
4253 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004254 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004255 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004256 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004257 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004258 if (Result.isNull())
4259 return QualType();
4260 }
Mike Stump1eb44332009-09-09 15:08:12 +00004261
John McCalla2becad2009-10-21 00:40:46 +00004262 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004263 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4264 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004265 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004266 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4267 NewTL.setArg(i, ParamDecls[i]);
4268
4269 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004270}
Mike Stump1eb44332009-09-09 15:08:12 +00004271
Douglas Gregor577f75a2009-08-04 16:50:30 +00004272template<typename Derived>
4273QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004274 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004275 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004276 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004277 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4278 if (ResultType.isNull())
4279 return QualType();
4280
4281 QualType Result = TL.getType();
4282 if (getDerived().AlwaysRebuild() ||
4283 ResultType != T->getResultType())
4284 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4285
4286 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004287 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4288 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004289 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004290
4291 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004292}
Mike Stump1eb44332009-09-09 15:08:12 +00004293
John McCalled976492009-12-04 22:46:56 +00004294template<typename Derived> QualType
4295TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004296 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004297 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004298 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004299 if (!D)
4300 return QualType();
4301
4302 QualType Result = TL.getType();
4303 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4304 Result = getDerived().RebuildUnresolvedUsingType(D);
4305 if (Result.isNull())
4306 return QualType();
4307 }
4308
4309 // We might get an arbitrary type spec type back. We should at
4310 // least always get a type spec type, though.
4311 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4312 NewTL.setNameLoc(TL.getNameLoc());
4313
4314 return Result;
4315}
4316
Douglas Gregor577f75a2009-08-04 16:50:30 +00004317template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004318QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004319 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004320 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004321 TypedefNameDecl *Typedef
4322 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4323 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004324 if (!Typedef)
4325 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004326
John McCalla2becad2009-10-21 00:40:46 +00004327 QualType Result = TL.getType();
4328 if (getDerived().AlwaysRebuild() ||
4329 Typedef != T->getDecl()) {
4330 Result = getDerived().RebuildTypedefType(Typedef);
4331 if (Result.isNull())
4332 return QualType();
4333 }
Mike Stump1eb44332009-09-09 15:08:12 +00004334
John McCalla2becad2009-10-21 00:40:46 +00004335 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4336 NewTL.setNameLoc(TL.getNameLoc());
4337
4338 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004339}
Mike Stump1eb44332009-09-09 15:08:12 +00004340
Douglas Gregor577f75a2009-08-04 16:50:30 +00004341template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004342QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004343 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004344 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004345 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004346
John McCall60d7b3a2010-08-24 06:29:42 +00004347 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004348 if (E.isInvalid())
4349 return QualType();
4350
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004351 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4352 if (E.isInvalid())
4353 return QualType();
4354
John McCalla2becad2009-10-21 00:40:46 +00004355 QualType Result = TL.getType();
4356 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004357 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004358 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004359 if (Result.isNull())
4360 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004361 }
John McCalla2becad2009-10-21 00:40:46 +00004362 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004363
John McCalla2becad2009-10-21 00:40:46 +00004364 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004365 NewTL.setTypeofLoc(TL.getTypeofLoc());
4366 NewTL.setLParenLoc(TL.getLParenLoc());
4367 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004368
4369 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004370}
Mike Stump1eb44332009-09-09 15:08:12 +00004371
4372template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004373QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004374 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004375 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4376 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4377 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004378 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004379
John McCalla2becad2009-10-21 00:40:46 +00004380 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004381 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4382 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004383 if (Result.isNull())
4384 return QualType();
4385 }
Mike Stump1eb44332009-09-09 15:08:12 +00004386
John McCalla2becad2009-10-21 00:40:46 +00004387 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004388 NewTL.setTypeofLoc(TL.getTypeofLoc());
4389 NewTL.setLParenLoc(TL.getLParenLoc());
4390 NewTL.setRParenLoc(TL.getRParenLoc());
4391 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004392
4393 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004394}
Mike Stump1eb44332009-09-09 15:08:12 +00004395
4396template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004397QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004398 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004399 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004400
Douglas Gregor670444e2009-08-04 22:27:00 +00004401 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004402 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4403 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004404
John McCall60d7b3a2010-08-24 06:29:42 +00004405 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004406 if (E.isInvalid())
4407 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004408
Richard Smith76f3f692012-02-22 02:04:18 +00004409 E = getSema().ActOnDecltypeExpression(E.take());
4410 if (E.isInvalid())
4411 return QualType();
4412
John McCalla2becad2009-10-21 00:40:46 +00004413 QualType Result = TL.getType();
4414 if (getDerived().AlwaysRebuild() ||
4415 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004416 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004417 if (Result.isNull())
4418 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004419 }
John McCalla2becad2009-10-21 00:40:46 +00004420 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004421
John McCalla2becad2009-10-21 00:40:46 +00004422 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4423 NewTL.setNameLoc(TL.getNameLoc());
4424
4425 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004426}
4427
4428template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004429QualType TreeTransform<Derived>::TransformUnaryTransformType(
4430 TypeLocBuilder &TLB,
4431 UnaryTransformTypeLoc TL) {
4432 QualType Result = TL.getType();
4433 if (Result->isDependentType()) {
4434 const UnaryTransformType *T = TL.getTypePtr();
4435 QualType NewBase =
4436 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4437 Result = getDerived().RebuildUnaryTransformType(NewBase,
4438 T->getUTTKind(),
4439 TL.getKWLoc());
4440 if (Result.isNull())
4441 return QualType();
4442 }
4443
4444 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4445 NewTL.setKWLoc(TL.getKWLoc());
4446 NewTL.setParensRange(TL.getParensRange());
4447 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4448 return Result;
4449}
4450
4451template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004452QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4453 AutoTypeLoc TL) {
4454 const AutoType *T = TL.getTypePtr();
4455 QualType OldDeduced = T->getDeducedType();
4456 QualType NewDeduced;
4457 if (!OldDeduced.isNull()) {
4458 NewDeduced = getDerived().TransformType(OldDeduced);
4459 if (NewDeduced.isNull())
4460 return QualType();
4461 }
4462
4463 QualType Result = TL.getType();
4464 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4465 Result = getDerived().RebuildAutoType(NewDeduced);
4466 if (Result.isNull())
4467 return QualType();
4468 }
4469
4470 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4471 NewTL.setNameLoc(TL.getNameLoc());
4472
4473 return Result;
4474}
4475
4476template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004477QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004478 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004479 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004480 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004481 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4482 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004483 if (!Record)
4484 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004485
John McCalla2becad2009-10-21 00:40:46 +00004486 QualType Result = TL.getType();
4487 if (getDerived().AlwaysRebuild() ||
4488 Record != T->getDecl()) {
4489 Result = getDerived().RebuildRecordType(Record);
4490 if (Result.isNull())
4491 return QualType();
4492 }
Mike Stump1eb44332009-09-09 15:08:12 +00004493
John McCalla2becad2009-10-21 00:40:46 +00004494 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4495 NewTL.setNameLoc(TL.getNameLoc());
4496
4497 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004498}
Mike Stump1eb44332009-09-09 15:08:12 +00004499
4500template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004501QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004502 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004503 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004504 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004505 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4506 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004507 if (!Enum)
4508 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004509
John McCalla2becad2009-10-21 00:40:46 +00004510 QualType Result = TL.getType();
4511 if (getDerived().AlwaysRebuild() ||
4512 Enum != T->getDecl()) {
4513 Result = getDerived().RebuildEnumType(Enum);
4514 if (Result.isNull())
4515 return QualType();
4516 }
Mike Stump1eb44332009-09-09 15:08:12 +00004517
John McCalla2becad2009-10-21 00:40:46 +00004518 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4519 NewTL.setNameLoc(TL.getNameLoc());
4520
4521 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004522}
John McCall7da24312009-09-05 00:15:47 +00004523
John McCall3cb0ebd2010-03-10 03:28:59 +00004524template<typename Derived>
4525QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4526 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004527 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004528 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4529 TL.getTypePtr()->getDecl());
4530 if (!D) return QualType();
4531
4532 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4533 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4534 return T;
4535}
4536
Douglas Gregor577f75a2009-08-04 16:50:30 +00004537template<typename Derived>
4538QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004539 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004540 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004541 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004542}
4543
Mike Stump1eb44332009-09-09 15:08:12 +00004544template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004545QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004546 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004547 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004548 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004549
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004550 // Substitute into the replacement type, which itself might involve something
4551 // that needs to be transformed. This only tends to occur with default
4552 // template arguments of template template parameters.
4553 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4554 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4555 if (Replacement.isNull())
4556 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004557
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004558 // Always canonicalize the replacement type.
4559 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4560 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004561 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004562 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004563
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004564 // Propagate type-source information.
4565 SubstTemplateTypeParmTypeLoc NewTL
4566 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4567 NewTL.setNameLoc(TL.getNameLoc());
4568 return Result;
4569
John McCall49a832b2009-10-18 09:09:24 +00004570}
4571
4572template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004573QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4574 TypeLocBuilder &TLB,
4575 SubstTemplateTypeParmPackTypeLoc TL) {
4576 return TransformTypeSpecType(TLB, TL);
4577}
4578
4579template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004580QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004581 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004582 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004583 const TemplateSpecializationType *T = TL.getTypePtr();
4584
Douglas Gregor1d752d72011-03-02 18:46:51 +00004585 // The nested-name-specifier never matters in a TemplateSpecializationType,
4586 // because we can't have a dependent nested-name-specifier anyway.
4587 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004588 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004589 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4590 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004591 if (Template.isNull())
4592 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004593
John McCall43fed0d2010-11-12 08:19:04 +00004594 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4595}
4596
Eli Friedmanb001de72011-10-06 23:00:33 +00004597template<typename Derived>
4598QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4599 AtomicTypeLoc TL) {
4600 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4601 if (ValueType.isNull())
4602 return QualType();
4603
4604 QualType Result = TL.getType();
4605 if (getDerived().AlwaysRebuild() ||
4606 ValueType != TL.getValueLoc().getType()) {
4607 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4608 if (Result.isNull())
4609 return QualType();
4610 }
4611
4612 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4613 NewTL.setKWLoc(TL.getKWLoc());
4614 NewTL.setLParenLoc(TL.getLParenLoc());
4615 NewTL.setRParenLoc(TL.getRParenLoc());
4616
4617 return Result;
4618}
4619
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004620namespace {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004621 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004622 /// container that provides a \c getArgLoc() member function.
4623 ///
4624 /// This iterator is intended to be used with the iterator form of
4625 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4626 template<typename ArgLocContainer>
4627 class TemplateArgumentLocContainerIterator {
4628 ArgLocContainer *Container;
4629 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004630
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004631 public:
4632 typedef TemplateArgumentLoc value_type;
4633 typedef TemplateArgumentLoc reference;
4634 typedef int difference_type;
4635 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004636
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004637 class pointer {
4638 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004639
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004640 public:
4641 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004642
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004643 const TemplateArgumentLoc *operator->() const {
4644 return &Arg;
4645 }
4646 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004647
4648
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004649 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004650
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004651 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4652 unsigned Index)
4653 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004654
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004655 TemplateArgumentLocContainerIterator &operator++() {
4656 ++Index;
4657 return *this;
4658 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004659
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004660 TemplateArgumentLocContainerIterator operator++(int) {
4661 TemplateArgumentLocContainerIterator Old(*this);
4662 ++(*this);
4663 return Old;
4664 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004665
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004666 TemplateArgumentLoc operator*() const {
4667 return Container->getArgLoc(Index);
4668 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004669
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004670 pointer operator->() const {
4671 return pointer(Container->getArgLoc(Index));
4672 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004673
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004674 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004675 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004676 return X.Container == Y.Container && X.Index == Y.Index;
4677 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004678
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004679 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004680 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004681 return !(X == Y);
4682 }
4683 };
4684}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004685
4686
John McCall43fed0d2010-11-12 08:19:04 +00004687template <typename Derived>
4688QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4689 TypeLocBuilder &TLB,
4690 TemplateSpecializationTypeLoc TL,
4691 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004692 TemplateArgumentListInfo NewTemplateArgs;
4693 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4694 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004695 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4696 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004697 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004698 ArgIterator(TL, TL.getNumArgs()),
4699 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004700 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004701
John McCall833ca992009-10-29 08:12:44 +00004702 // FIXME: maybe don't rebuild if all the template arguments are the same.
4703
4704 QualType Result =
4705 getDerived().RebuildTemplateSpecializationType(Template,
4706 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004707 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004708
4709 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004710 // Specializations of template template parameters are represented as
4711 // TemplateSpecializationTypes, and substitution of type alias templates
4712 // within a dependent context can transform them into
4713 // DependentTemplateSpecializationTypes.
4714 if (isa<DependentTemplateSpecializationType>(Result)) {
4715 DependentTemplateSpecializationTypeLoc NewTL
4716 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004717 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004718 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004719 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004720 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004721 NewTL.setLAngleLoc(TL.getLAngleLoc());
4722 NewTL.setRAngleLoc(TL.getRAngleLoc());
4723 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4724 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4725 return Result;
4726 }
4727
John McCall833ca992009-10-29 08:12:44 +00004728 TemplateSpecializationTypeLoc NewTL
4729 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004730 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004731 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4732 NewTL.setLAngleLoc(TL.getLAngleLoc());
4733 NewTL.setRAngleLoc(TL.getRAngleLoc());
4734 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4735 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004736 }
Mike Stump1eb44332009-09-09 15:08:12 +00004737
John McCall833ca992009-10-29 08:12:44 +00004738 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004739}
Mike Stump1eb44332009-09-09 15:08:12 +00004740
Douglas Gregora88f09f2011-02-28 17:23:35 +00004741template <typename Derived>
4742QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4743 TypeLocBuilder &TLB,
4744 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004745 TemplateName Template,
4746 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004747 TemplateArgumentListInfo NewTemplateArgs;
4748 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4749 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4750 typedef TemplateArgumentLocContainerIterator<
4751 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004752 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004753 ArgIterator(TL, TL.getNumArgs()),
4754 NewTemplateArgs))
4755 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004756
Douglas Gregora88f09f2011-02-28 17:23:35 +00004757 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004758
Douglas Gregora88f09f2011-02-28 17:23:35 +00004759 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4760 QualType Result
4761 = getSema().Context.getDependentTemplateSpecializationType(
4762 TL.getTypePtr()->getKeyword(),
4763 DTN->getQualifier(),
4764 DTN->getIdentifier(),
4765 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004766
Douglas Gregora88f09f2011-02-28 17:23:35 +00004767 DependentTemplateSpecializationTypeLoc NewTL
4768 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004769 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004770 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004771 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004772 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004773 NewTL.setLAngleLoc(TL.getLAngleLoc());
4774 NewTL.setRAngleLoc(TL.getRAngleLoc());
4775 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4776 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4777 return Result;
4778 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004779
4780 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004781 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004782 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004783 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004784
Douglas Gregora88f09f2011-02-28 17:23:35 +00004785 if (!Result.isNull()) {
4786 /// FIXME: Wrap this in an elaborated-type-specifier?
4787 TemplateSpecializationTypeLoc NewTL
4788 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004789 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004790 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004791 NewTL.setLAngleLoc(TL.getLAngleLoc());
4792 NewTL.setRAngleLoc(TL.getRAngleLoc());
4793 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4794 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4795 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004796
Douglas Gregora88f09f2011-02-28 17:23:35 +00004797 return Result;
4798}
4799
Mike Stump1eb44332009-09-09 15:08:12 +00004800template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004801QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004802TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004803 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004804 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004805
Douglas Gregor9e876872011-03-01 18:12:44 +00004806 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004807 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004808 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004809 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004810 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4811 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004812 return QualType();
4813 }
Mike Stump1eb44332009-09-09 15:08:12 +00004814
John McCall43fed0d2010-11-12 08:19:04 +00004815 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4816 if (NamedT.isNull())
4817 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004818
Richard Smith3e4c6c42011-05-05 21:57:07 +00004819 // C++0x [dcl.type.elab]p2:
4820 // If the identifier resolves to a typedef-name or the simple-template-id
4821 // resolves to an alias template specialization, the
4822 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004823 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4824 if (const TemplateSpecializationType *TST =
4825 NamedT->getAs<TemplateSpecializationType>()) {
4826 TemplateName Template = TST->getTemplateName();
4827 if (TypeAliasTemplateDecl *TAT =
4828 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4829 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4830 diag::err_tag_reference_non_tag) << 4;
4831 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4832 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004833 }
4834 }
4835
John McCalla2becad2009-10-21 00:40:46 +00004836 QualType Result = TL.getType();
4837 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004838 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004839 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004840 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004841 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004842 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004843 if (Result.isNull())
4844 return QualType();
4845 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004846
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004847 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004848 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004849 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004850 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004851}
Mike Stump1eb44332009-09-09 15:08:12 +00004852
4853template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004854QualType TreeTransform<Derived>::TransformAttributedType(
4855 TypeLocBuilder &TLB,
4856 AttributedTypeLoc TL) {
4857 const AttributedType *oldType = TL.getTypePtr();
4858 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4859 if (modifiedType.isNull())
4860 return QualType();
4861
4862 QualType result = TL.getType();
4863
4864 // FIXME: dependent operand expressions?
4865 if (getDerived().AlwaysRebuild() ||
4866 modifiedType != oldType->getModifiedType()) {
4867 // TODO: this is really lame; we should really be rebuilding the
4868 // equivalent type from first principles.
4869 QualType equivalentType
4870 = getDerived().TransformType(oldType->getEquivalentType());
4871 if (equivalentType.isNull())
4872 return QualType();
4873 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4874 modifiedType,
4875 equivalentType);
4876 }
4877
4878 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4879 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4880 if (TL.hasAttrOperand())
4881 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4882 if (TL.hasAttrExprOperand())
4883 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4884 else if (TL.hasAttrEnumOperand())
4885 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4886
4887 return result;
4888}
4889
4890template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004891QualType
4892TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4893 ParenTypeLoc TL) {
4894 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4895 if (Inner.isNull())
4896 return QualType();
4897
4898 QualType Result = TL.getType();
4899 if (getDerived().AlwaysRebuild() ||
4900 Inner != TL.getInnerLoc().getType()) {
4901 Result = getDerived().RebuildParenType(Inner);
4902 if (Result.isNull())
4903 return QualType();
4904 }
4905
4906 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4907 NewTL.setLParenLoc(TL.getLParenLoc());
4908 NewTL.setRParenLoc(TL.getRParenLoc());
4909 return Result;
4910}
4911
4912template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004913QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004914 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004915 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004916
Douglas Gregor2494dd02011-03-01 01:34:45 +00004917 NestedNameSpecifierLoc QualifierLoc
4918 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4919 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004920 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004921
John McCall33500952010-06-11 00:33:02 +00004922 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004923 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004924 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004925 QualifierLoc,
4926 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004927 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004928 if (Result.isNull())
4929 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004930
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004931 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4932 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004933 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4934
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004935 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004936 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004937 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004938 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004939 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004940 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004941 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004942 NewTL.setNameLoc(TL.getNameLoc());
4943 }
John McCalla2becad2009-10-21 00:40:46 +00004944 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004945}
Mike Stump1eb44332009-09-09 15:08:12 +00004946
Douglas Gregor577f75a2009-08-04 16:50:30 +00004947template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004948QualType TreeTransform<Derived>::
4949 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004950 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004951 NestedNameSpecifierLoc QualifierLoc;
4952 if (TL.getQualifierLoc()) {
4953 QualifierLoc
4954 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4955 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004956 return QualType();
4957 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004958
John McCall43fed0d2010-11-12 08:19:04 +00004959 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004960 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004961}
4962
4963template<typename Derived>
4964QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004965TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4966 DependentTemplateSpecializationTypeLoc TL,
4967 NestedNameSpecifierLoc QualifierLoc) {
4968 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004969
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004970 TemplateArgumentListInfo NewTemplateArgs;
4971 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4972 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004973
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004974 typedef TemplateArgumentLocContainerIterator<
4975 DependentTemplateSpecializationTypeLoc> ArgIterator;
4976 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4977 ArgIterator(TL, TL.getNumArgs()),
4978 NewTemplateArgs))
4979 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004980
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004981 QualType Result
4982 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4983 QualifierLoc,
4984 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004985 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004986 NewTemplateArgs);
4987 if (Result.isNull())
4988 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004989
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004990 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4991 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004992
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004993 // Copy information relevant to the template specialization.
4994 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004995 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004996 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004997 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004998 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4999 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005000 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005001 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005002
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005003 // Copy information relevant to the elaborated type.
5004 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005005 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005006 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005007 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5008 DependentTemplateSpecializationTypeLoc SpecTL
5009 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005010 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005011 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005012 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005013 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005014 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5015 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005016 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005017 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005018 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005019 TemplateSpecializationTypeLoc SpecTL
5020 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005021 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005022 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005023 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5024 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005025 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005026 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005027 }
5028 return Result;
5029}
5030
5031template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005032QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5033 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005034 QualType Pattern
5035 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005036 if (Pattern.isNull())
5037 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005038
5039 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005040 if (getDerived().AlwaysRebuild() ||
5041 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005042 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005043 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005044 TL.getEllipsisLoc(),
5045 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005046 if (Result.isNull())
5047 return QualType();
5048 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005049
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005050 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5051 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5052 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005053}
5054
5055template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005056QualType
5057TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005058 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005059 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005060 TLB.pushFullCopy(TL);
5061 return TL.getType();
5062}
5063
5064template<typename Derived>
5065QualType
5066TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005067 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005068 // ObjCObjectType is never dependent.
5069 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005070 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005071}
Mike Stump1eb44332009-09-09 15:08:12 +00005072
5073template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005074QualType
5075TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005076 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005077 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005078 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005079 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005080}
5081
Douglas Gregor577f75a2009-08-04 16:50:30 +00005082//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005083// Statement transformation
5084//===----------------------------------------------------------------------===//
5085template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005086StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005087TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005088 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005089}
5090
5091template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005092StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005093TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5094 return getDerived().TransformCompoundStmt(S, false);
5095}
5096
5097template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005098StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005099TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005100 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005101 Sema::CompoundScopeRAII CompoundScope(getSema());
5102
John McCall7114cba2010-08-27 19:56:05 +00005103 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005104 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005105 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00005106 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5107 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005108 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005109 if (Result.isInvalid()) {
5110 // Immediately fail if this was a DeclStmt, since it's very
5111 // likely that this will cause problems for future statements.
5112 if (isa<DeclStmt>(*B))
5113 return StmtError();
5114
5115 // Otherwise, just keep processing substatements and fail later.
5116 SubStmtInvalid = true;
5117 continue;
5118 }
Mike Stump1eb44332009-09-09 15:08:12 +00005119
Douglas Gregor43959a92009-08-20 07:17:43 +00005120 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5121 Statements.push_back(Result.takeAs<Stmt>());
5122 }
Mike Stump1eb44332009-09-09 15:08:12 +00005123
John McCall7114cba2010-08-27 19:56:05 +00005124 if (SubStmtInvalid)
5125 return StmtError();
5126
Douglas Gregor43959a92009-08-20 07:17:43 +00005127 if (!getDerived().AlwaysRebuild() &&
5128 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005129 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005130
5131 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
5132 move_arg(Statements),
5133 S->getRBracLoc(),
5134 IsStmtExpr);
5135}
Mike Stump1eb44332009-09-09 15:08:12 +00005136
Douglas Gregor43959a92009-08-20 07:17:43 +00005137template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005138StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005139TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005140 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005141 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005142 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5143 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005144
Eli Friedman264c1f82009-11-19 03:14:00 +00005145 // Transform the left-hand case value.
5146 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005147 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005148 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005149 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005150
Eli Friedman264c1f82009-11-19 03:14:00 +00005151 // Transform the right-hand case value (for the GNU case-range extension).
5152 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005153 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005154 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005155 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005156 }
Mike Stump1eb44332009-09-09 15:08:12 +00005157
Douglas Gregor43959a92009-08-20 07:17:43 +00005158 // Build the case statement.
5159 // Case statements are always rebuilt so that they will attached to their
5160 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005161 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005162 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005163 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005164 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005165 S->getColonLoc());
5166 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005167 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005168
Douglas Gregor43959a92009-08-20 07:17:43 +00005169 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005170 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005171 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005172 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005173
Douglas Gregor43959a92009-08-20 07:17:43 +00005174 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005175 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005176}
5177
5178template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005179StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005180TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005181 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005182 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005183 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005184 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005185
Douglas Gregor43959a92009-08-20 07:17:43 +00005186 // Default statements are always rebuilt
5187 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005188 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005189}
Mike Stump1eb44332009-09-09 15:08:12 +00005190
Douglas Gregor43959a92009-08-20 07:17:43 +00005191template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005192StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005193TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005194 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005195 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005196 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005197
Chris Lattner57ad3782011-02-17 20:34:02 +00005198 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5199 S->getDecl());
5200 if (!LD)
5201 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005202
5203
Douglas Gregor43959a92009-08-20 07:17:43 +00005204 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005205 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005206 cast<LabelDecl>(LD), SourceLocation(),
5207 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005208}
Mike Stump1eb44332009-09-09 15:08:12 +00005209
Douglas Gregor43959a92009-08-20 07:17:43 +00005210template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005211StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005212TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5213 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5214 if (SubStmt.isInvalid())
5215 return StmtError();
5216
5217 // TODO: transform attributes
5218 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5219 return S;
5220
5221 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5222 S->getAttrs(),
5223 SubStmt.get());
5224}
5225
5226template<typename Derived>
5227StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005228TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005229 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005230 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005231 VarDecl *ConditionVar = 0;
5232 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005233 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005234 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005235 getDerived().TransformDefinition(
5236 S->getConditionVariable()->getLocation(),
5237 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005238 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005239 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005240 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005241 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005242
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005243 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005244 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005245
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005246 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005247 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005248 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005249 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005250 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005251 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005252
John McCall9ae2f072010-08-23 23:25:46 +00005253 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005254 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005255 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005256
John McCall9ae2f072010-08-23 23:25:46 +00005257 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5258 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005259 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005260
Douglas Gregor43959a92009-08-20 07:17:43 +00005261 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005262 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005263 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005264 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005265
Douglas Gregor43959a92009-08-20 07:17:43 +00005266 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005267 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005268 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005269 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005270
Douglas Gregor43959a92009-08-20 07:17:43 +00005271 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005272 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005273 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005274 Then.get() == S->getThen() &&
5275 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005276 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005277
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005278 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005279 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005280 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005281}
5282
5283template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005284StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005285TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005286 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005287 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005288 VarDecl *ConditionVar = 0;
5289 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005290 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005291 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005292 getDerived().TransformDefinition(
5293 S->getConditionVariable()->getLocation(),
5294 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005295 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005296 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005297 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005298 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005299
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005300 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005301 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005302 }
Mike Stump1eb44332009-09-09 15:08:12 +00005303
Douglas Gregor43959a92009-08-20 07:17:43 +00005304 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005305 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005306 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005307 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005308 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005309 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005310
Douglas Gregor43959a92009-08-20 07:17:43 +00005311 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005312 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005313 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005314 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005315
Douglas Gregor43959a92009-08-20 07:17:43 +00005316 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005317 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5318 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005319}
Mike Stump1eb44332009-09-09 15:08:12 +00005320
Douglas Gregor43959a92009-08-20 07:17:43 +00005321template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005322StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005323TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005324 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005325 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005326 VarDecl *ConditionVar = 0;
5327 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005328 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005329 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005330 getDerived().TransformDefinition(
5331 S->getConditionVariable()->getLocation(),
5332 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005333 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005334 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005335 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005336 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005337
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005338 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005339 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005340
5341 if (S->getCond()) {
5342 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005343 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005344 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005345 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005346 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005347 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005348 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005349 }
Mike Stump1eb44332009-09-09 15:08:12 +00005350
John McCall9ae2f072010-08-23 23:25:46 +00005351 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5352 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005353 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005354
Douglas Gregor43959a92009-08-20 07:17:43 +00005355 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005356 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005357 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005358 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005359
Douglas Gregor43959a92009-08-20 07:17:43 +00005360 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005361 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005362 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005363 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005364 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005365
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005366 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005367 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005368}
Mike Stump1eb44332009-09-09 15:08:12 +00005369
Douglas Gregor43959a92009-08-20 07:17:43 +00005370template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005371StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005372TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005373 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005374 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005375 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005376 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005377
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005378 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005379 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005380 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005381 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005382
Douglas Gregor43959a92009-08-20 07:17:43 +00005383 if (!getDerived().AlwaysRebuild() &&
5384 Cond.get() == S->getCond() &&
5385 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005386 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005387
John McCall9ae2f072010-08-23 23:25:46 +00005388 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5389 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005390 S->getRParenLoc());
5391}
Mike Stump1eb44332009-09-09 15:08:12 +00005392
Douglas Gregor43959a92009-08-20 07:17:43 +00005393template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005394StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005395TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005396 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005397 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005398 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005399 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005400
Douglas Gregor43959a92009-08-20 07:17:43 +00005401 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005402 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005403 VarDecl *ConditionVar = 0;
5404 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005405 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005406 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005407 getDerived().TransformDefinition(
5408 S->getConditionVariable()->getLocation(),
5409 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005410 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005411 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005412 } else {
5413 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005414
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005415 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005416 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005417
5418 if (S->getCond()) {
5419 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005420 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005421 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005422 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005423 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005424
John McCall9ae2f072010-08-23 23:25:46 +00005425 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005426 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005427 }
Mike Stump1eb44332009-09-09 15:08:12 +00005428
Chad Rosier4a9d7952012-08-08 18:46:20 +00005429 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005430 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005431 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005432
Douglas Gregor43959a92009-08-20 07:17:43 +00005433 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005434 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005435 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005436 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005437
John McCall9ae2f072010-08-23 23:25:46 +00005438 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5439 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005440 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005441
Douglas Gregor43959a92009-08-20 07:17:43 +00005442 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005443 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005444 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005445 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005446
Douglas Gregor43959a92009-08-20 07:17:43 +00005447 if (!getDerived().AlwaysRebuild() &&
5448 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005449 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005450 Inc.get() == S->getInc() &&
5451 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005452 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005453
Douglas Gregor43959a92009-08-20 07:17:43 +00005454 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005455 Init.get(), FullCond, ConditionVar,
5456 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005457}
5458
5459template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005460StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005461TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005462 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5463 S->getLabel());
5464 if (!LD)
5465 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005466
Douglas Gregor43959a92009-08-20 07:17:43 +00005467 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005468 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005469 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005470}
5471
5472template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005473StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005474TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005475 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005476 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005477 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005478 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005479
Douglas Gregor43959a92009-08-20 07:17:43 +00005480 if (!getDerived().AlwaysRebuild() &&
5481 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005482 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005483
5484 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005485 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005486}
5487
5488template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005489StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005490TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005491 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005492}
Mike Stump1eb44332009-09-09 15:08:12 +00005493
Douglas Gregor43959a92009-08-20 07:17:43 +00005494template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005495StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005496TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005497 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005498}
Mike Stump1eb44332009-09-09 15:08:12 +00005499
Douglas Gregor43959a92009-08-20 07:17:43 +00005500template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005501StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005502TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005503 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005504 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005505 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005506
Mike Stump1eb44332009-09-09 15:08:12 +00005507 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005508 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005509 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005510}
Mike Stump1eb44332009-09-09 15:08:12 +00005511
Douglas Gregor43959a92009-08-20 07:17:43 +00005512template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005513StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005514TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005515 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005516 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005517 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5518 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005519 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5520 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005521 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005522 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005523
Douglas Gregor43959a92009-08-20 07:17:43 +00005524 if (Transformed != *D)
5525 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005526
Douglas Gregor43959a92009-08-20 07:17:43 +00005527 Decls.push_back(Transformed);
5528 }
Mike Stump1eb44332009-09-09 15:08:12 +00005529
Douglas Gregor43959a92009-08-20 07:17:43 +00005530 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005531 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005532
5533 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005534 S->getStartLoc(), S->getEndLoc());
5535}
Mike Stump1eb44332009-09-09 15:08:12 +00005536
Douglas Gregor43959a92009-08-20 07:17:43 +00005537template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005538StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005539TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005540
John McCallca0408f2010-08-23 06:44:23 +00005541 ASTOwningVector<Expr*> Constraints(getSema());
5542 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005543 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005544
John McCall60d7b3a2010-08-24 06:29:42 +00005545 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005546 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005547
5548 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005549
Anders Carlsson703e3942010-01-24 05:50:09 +00005550 // Go through the outputs.
5551 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005552 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005553
Anders Carlsson703e3942010-01-24 05:50:09 +00005554 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005555 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005556
Anders Carlsson703e3942010-01-24 05:50:09 +00005557 // Transform the output expr.
5558 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005559 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005560 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005561 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005562
Anders Carlsson703e3942010-01-24 05:50:09 +00005563 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005564
John McCall9ae2f072010-08-23 23:25:46 +00005565 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005566 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005567
Anders Carlsson703e3942010-01-24 05:50:09 +00005568 // Go through the inputs.
5569 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005570 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005571
Anders Carlsson703e3942010-01-24 05:50:09 +00005572 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005573 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005574
Anders Carlsson703e3942010-01-24 05:50:09 +00005575 // Transform the input expr.
5576 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005577 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005578 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005579 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005580
Anders Carlsson703e3942010-01-24 05:50:09 +00005581 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005582
John McCall9ae2f072010-08-23 23:25:46 +00005583 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005584 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005585
Anders Carlsson703e3942010-01-24 05:50:09 +00005586 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005587 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005588
5589 // Go through the clobbers.
5590 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005591 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005592
5593 // No need to transform the asm string literal.
5594 AsmString = SemaRef.Owned(S->getAsmString());
5595
5596 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5597 S->isSimple(),
5598 S->isVolatile(),
5599 S->getNumOutputs(),
5600 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005601 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005602 move_arg(Constraints),
5603 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005604 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005605 move_arg(Clobbers),
5606 S->getRParenLoc(),
5607 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005608}
5609
Chad Rosier8cd64b42012-06-11 20:47:18 +00005610template<typename Derived>
5611StmtResult
5612TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005613 ArrayRef<Token> AsmToks =
5614 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005615 ArrayRef<unsigned> LineEnds =
5616 llvm::makeArrayRef(S->getLineEnds(), S->getNumLineEnds());
5617
Chad Rosier8cd64b42012-06-11 20:47:18 +00005618 // No need to transform the asm string literal.
Chad Rosier62f22b82012-08-08 19:48:07 +00005619 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), AsmToks, LineEnds,
Chad Rosier8cd64b42012-06-11 20:47:18 +00005620 S->getEndLoc());
5621}
Douglas Gregor43959a92009-08-20 07:17:43 +00005622
5623template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005624StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005625TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005626 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005627 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005628 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005629 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005630
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005631 // Transform the @catch statements (if present).
5632 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005633 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005634 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005635 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005636 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005637 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005638 if (Catch.get() != S->getCatchStmt(I))
5639 AnyCatchChanged = true;
5640 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005641 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005642
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005643 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005644 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005645 if (S->getFinallyStmt()) {
5646 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5647 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005648 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005649 }
5650
5651 // If nothing changed, just retain this statement.
5652 if (!getDerived().AlwaysRebuild() &&
5653 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005654 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005655 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005656 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005657
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005658 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005659 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5660 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005661}
Mike Stump1eb44332009-09-09 15:08:12 +00005662
Douglas Gregor43959a92009-08-20 07:17:43 +00005663template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005664StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005665TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005666 // Transform the @catch parameter, if there is one.
5667 VarDecl *Var = 0;
5668 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5669 TypeSourceInfo *TSInfo = 0;
5670 if (FromVar->getTypeSourceInfo()) {
5671 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5672 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005673 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005674 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005675
Douglas Gregorbe270a02010-04-26 17:57:08 +00005676 QualType T;
5677 if (TSInfo)
5678 T = TSInfo->getType();
5679 else {
5680 T = getDerived().TransformType(FromVar->getType());
5681 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005682 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005683 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005684
Douglas Gregorbe270a02010-04-26 17:57:08 +00005685 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5686 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005687 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005688 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005689
John McCall60d7b3a2010-08-24 06:29:42 +00005690 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005691 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005692 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005693
5694 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005695 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005696 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005697}
Mike Stump1eb44332009-09-09 15:08:12 +00005698
Douglas Gregor43959a92009-08-20 07:17:43 +00005699template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005700StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005701TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005702 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005703 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005704 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005705 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005706
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005707 // If nothing changed, just retain this statement.
5708 if (!getDerived().AlwaysRebuild() &&
5709 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005710 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005711
5712 // Build a new statement.
5713 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005714 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005715}
Mike Stump1eb44332009-09-09 15:08:12 +00005716
Douglas Gregor43959a92009-08-20 07:17:43 +00005717template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005718StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005719TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005720 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005721 if (S->getThrowExpr()) {
5722 Operand = getDerived().TransformExpr(S->getThrowExpr());
5723 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005724 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005725 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005726
Douglas Gregord1377b22010-04-22 21:44:01 +00005727 if (!getDerived().AlwaysRebuild() &&
5728 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005729 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005730
John McCall9ae2f072010-08-23 23:25:46 +00005731 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005732}
Mike Stump1eb44332009-09-09 15:08:12 +00005733
Douglas Gregor43959a92009-08-20 07:17:43 +00005734template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005735StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005736TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005737 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005738 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005739 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005740 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005741 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005742 Object =
5743 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5744 Object.get());
5745 if (Object.isInvalid())
5746 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005747
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005748 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005749 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005750 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005751 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005752
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005753 // If nothing change, just retain the current statement.
5754 if (!getDerived().AlwaysRebuild() &&
5755 Object.get() == S->getSynchExpr() &&
5756 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005757 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005758
5759 // Build a new statement.
5760 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005761 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005762}
5763
5764template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005765StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005766TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5767 ObjCAutoreleasePoolStmt *S) {
5768 // Transform the body.
5769 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5770 if (Body.isInvalid())
5771 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005772
John McCallf85e1932011-06-15 23:02:42 +00005773 // If nothing changed, just retain this statement.
5774 if (!getDerived().AlwaysRebuild() &&
5775 Body.get() == S->getSubStmt())
5776 return SemaRef.Owned(S);
5777
5778 // Build a new statement.
5779 return getDerived().RebuildObjCAutoreleasePoolStmt(
5780 S->getAtLoc(), Body.get());
5781}
5782
5783template<typename Derived>
5784StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005785TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005786 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005787 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005788 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005789 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005790 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005791
Douglas Gregorc3203e72010-04-22 23:10:45 +00005792 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005793 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005794 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005795 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005796
Douglas Gregorc3203e72010-04-22 23:10:45 +00005797 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005798 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005799 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005800 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005801
Douglas Gregorc3203e72010-04-22 23:10:45 +00005802 // If nothing changed, just retain this statement.
5803 if (!getDerived().AlwaysRebuild() &&
5804 Element.get() == S->getElement() &&
5805 Collection.get() == S->getCollection() &&
5806 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005807 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005808
Douglas Gregorc3203e72010-04-22 23:10:45 +00005809 // Build a new statement.
5810 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5811 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005812 Element.get(),
5813 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005814 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005815 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005816}
5817
5818
5819template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005820StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005821TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5822 // Transform the exception declaration, if any.
5823 VarDecl *Var = 0;
5824 if (S->getExceptionDecl()) {
5825 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005826 TypeSourceInfo *T = getDerived().TransformType(
5827 ExceptionDecl->getTypeSourceInfo());
5828 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005829 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005830
Douglas Gregor83cb9422010-09-09 17:09:21 +00005831 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005832 ExceptionDecl->getInnerLocStart(),
5833 ExceptionDecl->getLocation(),
5834 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005835 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005836 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005837 }
Mike Stump1eb44332009-09-09 15:08:12 +00005838
Douglas Gregor43959a92009-08-20 07:17:43 +00005839 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005840 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005841 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005842 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005843
Douglas Gregor43959a92009-08-20 07:17:43 +00005844 if (!getDerived().AlwaysRebuild() &&
5845 !Var &&
5846 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005847 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005848
5849 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5850 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005851 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005852}
Mike Stump1eb44332009-09-09 15:08:12 +00005853
Douglas Gregor43959a92009-08-20 07:17:43 +00005854template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005855StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005856TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5857 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005858 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005859 = getDerived().TransformCompoundStmt(S->getTryBlock());
5860 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005861 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005862
Douglas Gregor43959a92009-08-20 07:17:43 +00005863 // Transform the handlers.
5864 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005865 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005866 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005867 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005868 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5869 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005870 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005871
Douglas Gregor43959a92009-08-20 07:17:43 +00005872 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5873 Handlers.push_back(Handler.takeAs<Stmt>());
5874 }
Mike Stump1eb44332009-09-09 15:08:12 +00005875
Douglas Gregor43959a92009-08-20 07:17:43 +00005876 if (!getDerived().AlwaysRebuild() &&
5877 TryBlock.get() == S->getTryBlock() &&
5878 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005879 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005880
John McCall9ae2f072010-08-23 23:25:46 +00005881 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005882 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005883}
Mike Stump1eb44332009-09-09 15:08:12 +00005884
Richard Smithad762fc2011-04-14 22:09:26 +00005885template<typename Derived>
5886StmtResult
5887TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5888 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5889 if (Range.isInvalid())
5890 return StmtError();
5891
5892 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5893 if (BeginEnd.isInvalid())
5894 return StmtError();
5895
5896 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5897 if (Cond.isInvalid())
5898 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005899 if (Cond.get())
5900 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5901 if (Cond.isInvalid())
5902 return StmtError();
5903 if (Cond.get())
5904 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005905
5906 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5907 if (Inc.isInvalid())
5908 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005909 if (Inc.get())
5910 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005911
5912 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5913 if (LoopVar.isInvalid())
5914 return StmtError();
5915
5916 StmtResult NewStmt = S;
5917 if (getDerived().AlwaysRebuild() ||
5918 Range.get() != S->getRangeStmt() ||
5919 BeginEnd.get() != S->getBeginEndStmt() ||
5920 Cond.get() != S->getCond() ||
5921 Inc.get() != S->getInc() ||
5922 LoopVar.get() != S->getLoopVarStmt())
5923 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5924 S->getColonLoc(), Range.get(),
5925 BeginEnd.get(), Cond.get(),
5926 Inc.get(), LoopVar.get(),
5927 S->getRParenLoc());
5928
5929 StmtResult Body = getDerived().TransformStmt(S->getBody());
5930 if (Body.isInvalid())
5931 return StmtError();
5932
5933 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5934 // it now so we have a new statement to attach the body to.
5935 if (Body.get() != S->getBody() && NewStmt.get() == S)
5936 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5937 S->getColonLoc(), Range.get(),
5938 BeginEnd.get(), Cond.get(),
5939 Inc.get(), LoopVar.get(),
5940 S->getRParenLoc());
5941
5942 if (NewStmt.get() == S)
5943 return SemaRef.Owned(S);
5944
5945 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5946}
5947
John Wiegley28bbe4b2011-04-28 01:08:34 +00005948template<typename Derived>
5949StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005950TreeTransform<Derived>::TransformMSDependentExistsStmt(
5951 MSDependentExistsStmt *S) {
5952 // Transform the nested-name-specifier, if any.
5953 NestedNameSpecifierLoc QualifierLoc;
5954 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005955 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00005956 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5957 if (!QualifierLoc)
5958 return StmtError();
5959 }
5960
5961 // Transform the declaration name.
5962 DeclarationNameInfo NameInfo = S->getNameInfo();
5963 if (NameInfo.getName()) {
5964 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5965 if (!NameInfo.getName())
5966 return StmtError();
5967 }
5968
5969 // Check whether anything changed.
5970 if (!getDerived().AlwaysRebuild() &&
5971 QualifierLoc == S->getQualifierLoc() &&
5972 NameInfo.getName() == S->getNameInfo().getName())
5973 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005974
Douglas Gregorba0513d2011-10-25 01:33:02 +00005975 // Determine whether this name exists, if we can.
5976 CXXScopeSpec SS;
5977 SS.Adopt(QualifierLoc);
5978 bool Dependent = false;
5979 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5980 case Sema::IER_Exists:
5981 if (S->isIfExists())
5982 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005983
Douglas Gregorba0513d2011-10-25 01:33:02 +00005984 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5985
5986 case Sema::IER_DoesNotExist:
5987 if (S->isIfNotExists())
5988 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005989
Douglas Gregorba0513d2011-10-25 01:33:02 +00005990 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005991
Douglas Gregorba0513d2011-10-25 01:33:02 +00005992 case Sema::IER_Dependent:
5993 Dependent = true;
5994 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005995
Douglas Gregor65019ac2011-10-25 03:44:56 +00005996 case Sema::IER_Error:
5997 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005998 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005999
Douglas Gregorba0513d2011-10-25 01:33:02 +00006000 // We need to continue with the instantiation, so do so now.
6001 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6002 if (SubStmt.isInvalid())
6003 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006004
Douglas Gregorba0513d2011-10-25 01:33:02 +00006005 // If we have resolved the name, just transform to the substatement.
6006 if (!Dependent)
6007 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006008
Douglas Gregorba0513d2011-10-25 01:33:02 +00006009 // The name is still dependent, so build a dependent expression again.
6010 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6011 S->isIfExists(),
6012 QualifierLoc,
6013 NameInfo,
6014 SubStmt.get());
6015}
6016
6017template<typename Derived>
6018StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006019TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6020 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6021 if(TryBlock.isInvalid()) return StmtError();
6022
6023 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6024 if(!getDerived().AlwaysRebuild() &&
6025 TryBlock.get() == S->getTryBlock() &&
6026 Handler.get() == S->getHandler())
6027 return SemaRef.Owned(S);
6028
6029 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6030 S->getTryLoc(),
6031 TryBlock.take(),
6032 Handler.take());
6033}
6034
6035template<typename Derived>
6036StmtResult
6037TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6038 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6039 if(Block.isInvalid()) return StmtError();
6040
6041 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6042 Block.take());
6043}
6044
6045template<typename Derived>
6046StmtResult
6047TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6048 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6049 if(FilterExpr.isInvalid()) return StmtError();
6050
6051 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6052 if(Block.isInvalid()) return StmtError();
6053
6054 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6055 FilterExpr.take(),
6056 Block.take());
6057}
6058
6059template<typename Derived>
6060StmtResult
6061TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6062 if(isa<SEHFinallyStmt>(Handler))
6063 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6064 else
6065 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6066}
6067
Douglas Gregor43959a92009-08-20 07:17:43 +00006068//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006069// Expression transformation
6070//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006071template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006072ExprResult
John McCall454feb92009-12-08 09:21:05 +00006073TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006074 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006075}
Mike Stump1eb44332009-09-09 15:08:12 +00006076
6077template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006078ExprResult
John McCall454feb92009-12-08 09:21:05 +00006079TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006080 NestedNameSpecifierLoc QualifierLoc;
6081 if (E->getQualifierLoc()) {
6082 QualifierLoc
6083 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6084 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006085 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006086 }
John McCalldbd872f2009-12-08 09:08:17 +00006087
6088 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006089 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6090 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006091 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006092 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006093
John McCallec8045d2010-08-17 21:27:17 +00006094 DeclarationNameInfo NameInfo = E->getNameInfo();
6095 if (NameInfo.getName()) {
6096 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6097 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006098 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006099 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006100
6101 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006102 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006103 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006104 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006105 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006106
6107 // Mark it referenced in the new context regardless.
6108 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006109 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006110
John McCall3fa5cae2010-10-26 07:05:15 +00006111 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006112 }
John McCalldbd872f2009-12-08 09:08:17 +00006113
6114 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006115 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006116 TemplateArgs = &TransArgs;
6117 TransArgs.setLAngleLoc(E->getLAngleLoc());
6118 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006119 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6120 E->getNumTemplateArgs(),
6121 TransArgs))
6122 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006123 }
6124
Chad Rosier4a9d7952012-08-08 18:46:20 +00006125 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006126 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006127}
Mike Stump1eb44332009-09-09 15:08:12 +00006128
Douglas Gregorb98b1992009-08-11 05:31:07 +00006129template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006130ExprResult
John McCall454feb92009-12-08 09:21:05 +00006131TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006132 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006133}
Mike Stump1eb44332009-09-09 15:08:12 +00006134
Douglas Gregorb98b1992009-08-11 05:31:07 +00006135template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006136ExprResult
John McCall454feb92009-12-08 09:21:05 +00006137TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006138 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006139}
Mike Stump1eb44332009-09-09 15:08:12 +00006140
Douglas Gregorb98b1992009-08-11 05:31:07 +00006141template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006142ExprResult
John McCall454feb92009-12-08 09:21:05 +00006143TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006144 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006145}
Mike Stump1eb44332009-09-09 15:08:12 +00006146
Douglas Gregorb98b1992009-08-11 05:31:07 +00006147template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006148ExprResult
John McCall454feb92009-12-08 09:21:05 +00006149TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006150 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006151}
Mike Stump1eb44332009-09-09 15:08:12 +00006152
Douglas Gregorb98b1992009-08-11 05:31:07 +00006153template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006154ExprResult
John McCall454feb92009-12-08 09:21:05 +00006155TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006156 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006157}
6158
6159template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006160ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006161TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6162 return SemaRef.MaybeBindToTemporary(E);
6163}
6164
6165template<typename Derived>
6166ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006167TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6168 ExprResult ControllingExpr =
6169 getDerived().TransformExpr(E->getControllingExpr());
6170 if (ControllingExpr.isInvalid())
6171 return ExprError();
6172
Chris Lattner686775d2011-07-20 06:58:45 +00006173 SmallVector<Expr *, 4> AssocExprs;
6174 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006175 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6176 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6177 if (TS) {
6178 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6179 if (!AssocType)
6180 return ExprError();
6181 AssocTypes.push_back(AssocType);
6182 } else {
6183 AssocTypes.push_back(0);
6184 }
6185
6186 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6187 if (AssocExpr.isInvalid())
6188 return ExprError();
6189 AssocExprs.push_back(AssocExpr.release());
6190 }
6191
6192 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6193 E->getDefaultLoc(),
6194 E->getRParenLoc(),
6195 ControllingExpr.release(),
6196 AssocTypes.data(),
6197 AssocExprs.data(),
6198 E->getNumAssocs());
6199}
6200
6201template<typename Derived>
6202ExprResult
John McCall454feb92009-12-08 09:21:05 +00006203TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006204 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006205 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006206 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006207
Douglas Gregorb98b1992009-08-11 05:31:07 +00006208 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006209 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006210
John McCall9ae2f072010-08-23 23:25:46 +00006211 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006212 E->getRParen());
6213}
6214
Mike Stump1eb44332009-09-09 15:08:12 +00006215template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006216ExprResult
John McCall454feb92009-12-08 09:21:05 +00006217TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006218 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006219 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006220 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006221
Douglas Gregorb98b1992009-08-11 05:31:07 +00006222 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006223 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006224
Douglas Gregorb98b1992009-08-11 05:31:07 +00006225 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6226 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006227 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006228}
Mike Stump1eb44332009-09-09 15:08:12 +00006229
Douglas Gregorb98b1992009-08-11 05:31:07 +00006230template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006231ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006232TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6233 // Transform the type.
6234 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6235 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006236 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006237
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006238 // Transform all of the components into components similar to what the
6239 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006240 // FIXME: It would be slightly more efficient in the non-dependent case to
6241 // just map FieldDecls, rather than requiring the rebuilder to look for
6242 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006243 // template code that we don't care.
6244 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006245 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006246 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006247 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006248 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6249 const Node &ON = E->getComponent(I);
6250 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006251 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006252 Comp.LocStart = ON.getSourceRange().getBegin();
6253 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006254 switch (ON.getKind()) {
6255 case Node::Array: {
6256 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006257 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006258 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006259 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006260
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006261 ExprChanged = ExprChanged || Index.get() != FromIndex;
6262 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006263 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006264 break;
6265 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006266
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006267 case Node::Field:
6268 case Node::Identifier:
6269 Comp.isBrackets = false;
6270 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006271 if (!Comp.U.IdentInfo)
6272 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006273
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006274 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006275
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006276 case Node::Base:
6277 // Will be recomputed during the rebuild.
6278 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006279 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006280
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006281 Components.push_back(Comp);
6282 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006283
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006284 // If nothing changed, retain the existing expression.
6285 if (!getDerived().AlwaysRebuild() &&
6286 Type == E->getTypeSourceInfo() &&
6287 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006288 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006289
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006290 // Build a new offsetof expression.
6291 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6292 Components.data(), Components.size(),
6293 E->getRParenLoc());
6294}
6295
6296template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006297ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006298TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6299 assert(getDerived().AlreadyTransformed(E->getType()) &&
6300 "opaque value expression requires transformation");
6301 return SemaRef.Owned(E);
6302}
6303
6304template<typename Derived>
6305ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006306TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006307 // Rebuild the syntactic form. The original syntactic form has
6308 // opaque-value expressions in it, so strip those away and rebuild
6309 // the result. This is a really awful way of doing this, but the
6310 // better solution (rebuilding the semantic expressions and
6311 // rebinding OVEs as necessary) doesn't work; we'd need
6312 // TreeTransform to not strip away implicit conversions.
6313 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6314 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006315 if (result.isInvalid()) return ExprError();
6316
6317 // If that gives us a pseudo-object result back, the pseudo-object
6318 // expression must have been an lvalue-to-rvalue conversion which we
6319 // should reapply.
6320 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6321 result = SemaRef.checkPseudoObjectRValue(result.take());
6322
6323 return result;
6324}
6325
6326template<typename Derived>
6327ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006328TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6329 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006330 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006331 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006332
John McCalla93c9342009-12-07 02:54:59 +00006333 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006334 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006335 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006336
John McCall5ab75172009-11-04 07:28:41 +00006337 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006338 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006339
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006340 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6341 E->getKind(),
6342 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006343 }
Mike Stump1eb44332009-09-09 15:08:12 +00006344
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006345 // C++0x [expr.sizeof]p1:
6346 // The operand is either an expression, which is an unevaluated operand
6347 // [...]
6348 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006349
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006350 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6351 if (SubExpr.isInvalid())
6352 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006353
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006354 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6355 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006356
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006357 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6358 E->getOperatorLoc(),
6359 E->getKind(),
6360 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006361}
Mike Stump1eb44332009-09-09 15:08:12 +00006362
Douglas Gregorb98b1992009-08-11 05:31:07 +00006363template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006364ExprResult
John McCall454feb92009-12-08 09:21:05 +00006365TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006366 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006367 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006368 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006369
John McCall60d7b3a2010-08-24 06:29:42 +00006370 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006371 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006372 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006373
6374
Douglas Gregorb98b1992009-08-11 05:31:07 +00006375 if (!getDerived().AlwaysRebuild() &&
6376 LHS.get() == E->getLHS() &&
6377 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006378 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006379
John McCall9ae2f072010-08-23 23:25:46 +00006380 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006381 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006382 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006383 E->getRBracketLoc());
6384}
Mike Stump1eb44332009-09-09 15:08:12 +00006385
6386template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006387ExprResult
John McCall454feb92009-12-08 09:21:05 +00006388TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006389 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006390 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006391 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006392 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006393
6394 // Transform arguments.
6395 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006396 ASTOwningVector<Expr*> Args(SemaRef);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006397 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006398 &ArgChanged))
6399 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006400
Douglas Gregorb98b1992009-08-11 05:31:07 +00006401 if (!getDerived().AlwaysRebuild() &&
6402 Callee.get() == E->getCallee() &&
6403 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006404 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump1eb44332009-09-09 15:08:12 +00006405
Douglas Gregorb98b1992009-08-11 05:31:07 +00006406 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006407 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006408 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006409 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006410 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006411 E->getRParenLoc());
6412}
Mike Stump1eb44332009-09-09 15:08:12 +00006413
6414template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006415ExprResult
John McCall454feb92009-12-08 09:21:05 +00006416TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006417 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006418 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006419 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006420
Douglas Gregor40d96a62011-02-28 21:54:11 +00006421 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006422 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006423 QualifierLoc
6424 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006425
Douglas Gregor40d96a62011-02-28 21:54:11 +00006426 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006427 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006428 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006429 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006430
Eli Friedmanf595cc42009-12-04 06:40:45 +00006431 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006432 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6433 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006434 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006435 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006436
John McCall6bb80172010-03-30 21:47:33 +00006437 NamedDecl *FoundDecl = E->getFoundDecl();
6438 if (FoundDecl == E->getMemberDecl()) {
6439 FoundDecl = Member;
6440 } else {
6441 FoundDecl = cast_or_null<NamedDecl>(
6442 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6443 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006444 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006445 }
6446
Douglas Gregorb98b1992009-08-11 05:31:07 +00006447 if (!getDerived().AlwaysRebuild() &&
6448 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006449 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006450 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006451 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006452 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006453
Anders Carlsson1f240322009-12-22 05:24:09 +00006454 // Mark it referenced in the new context regardless.
6455 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006456 SemaRef.MarkMemberReferenced(E);
6457
John McCall3fa5cae2010-10-26 07:05:15 +00006458 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006459 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006460
John McCalld5532b62009-11-23 01:53:49 +00006461 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006462 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006463 TransArgs.setLAngleLoc(E->getLAngleLoc());
6464 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006465 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6466 E->getNumTemplateArgs(),
6467 TransArgs))
6468 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006469 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006470
Douglas Gregorb98b1992009-08-11 05:31:07 +00006471 // FIXME: Bogus source location for the operator
6472 SourceLocation FakeOperatorLoc
6473 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6474
John McCallc2233c52010-01-15 08:34:02 +00006475 // FIXME: to do this check properly, we will need to preserve the
6476 // first-qualifier-in-scope here, just in case we had a dependent
6477 // base (and therefore couldn't do the check) and a
6478 // nested-name-qualifier (and therefore could do the lookup).
6479 NamedDecl *FirstQualifierInScope = 0;
6480
John McCall9ae2f072010-08-23 23:25:46 +00006481 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006482 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006483 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006484 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006485 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006486 Member,
John McCall6bb80172010-03-30 21:47:33 +00006487 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006488 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006489 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006490 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006491}
Mike Stump1eb44332009-09-09 15:08:12 +00006492
Douglas Gregorb98b1992009-08-11 05:31:07 +00006493template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006494ExprResult
John McCall454feb92009-12-08 09:21:05 +00006495TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006496 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006497 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006498 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006499
John McCall60d7b3a2010-08-24 06:29:42 +00006500 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006501 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006502 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006503
Douglas Gregorb98b1992009-08-11 05:31:07 +00006504 if (!getDerived().AlwaysRebuild() &&
6505 LHS.get() == E->getLHS() &&
6506 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006507 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006508
Douglas Gregorb98b1992009-08-11 05:31:07 +00006509 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006510 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006511}
6512
Mike Stump1eb44332009-09-09 15:08:12 +00006513template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006514ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006515TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006516 CompoundAssignOperator *E) {
6517 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006518}
Mike Stump1eb44332009-09-09 15:08:12 +00006519
Douglas Gregorb98b1992009-08-11 05:31:07 +00006520template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006521ExprResult TreeTransform<Derived>::
6522TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6523 // Just rebuild the common and RHS expressions and see whether we
6524 // get any changes.
6525
6526 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6527 if (commonExpr.isInvalid())
6528 return ExprError();
6529
6530 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6531 if (rhs.isInvalid())
6532 return ExprError();
6533
6534 if (!getDerived().AlwaysRebuild() &&
6535 commonExpr.get() == e->getCommon() &&
6536 rhs.get() == e->getFalseExpr())
6537 return SemaRef.Owned(e);
6538
6539 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6540 e->getQuestionLoc(),
6541 0,
6542 e->getColonLoc(),
6543 rhs.get());
6544}
6545
6546template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006547ExprResult
John McCall454feb92009-12-08 09:21:05 +00006548TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006549 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006550 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006551 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006552
John McCall60d7b3a2010-08-24 06:29:42 +00006553 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006554 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006555 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006556
John McCall60d7b3a2010-08-24 06:29:42 +00006557 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006558 if (RHS.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() &&
6562 Cond.get() == E->getCond() &&
6563 LHS.get() == E->getLHS() &&
6564 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006565 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006566
John McCall9ae2f072010-08-23 23:25:46 +00006567 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006568 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006569 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006570 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006571 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006572}
Mike Stump1eb44332009-09-09 15:08:12 +00006573
6574template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006575ExprResult
John McCall454feb92009-12-08 09:21:05 +00006576TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006577 // Implicit casts are eliminated during transformation, since they
6578 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006579 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006580}
Mike Stump1eb44332009-09-09 15:08:12 +00006581
Douglas Gregorb98b1992009-08-11 05:31:07 +00006582template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006583ExprResult
John McCall454feb92009-12-08 09:21:05 +00006584TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006585 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6586 if (!Type)
6587 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006588
John McCall60d7b3a2010-08-24 06:29:42 +00006589 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006590 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006591 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006592 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006593
Douglas Gregorb98b1992009-08-11 05:31:07 +00006594 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006595 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006596 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006597 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006598
John McCall9d125032010-01-15 18:39:57 +00006599 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006600 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006601 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006602 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006603}
Mike Stump1eb44332009-09-09 15:08:12 +00006604
Douglas Gregorb98b1992009-08-11 05:31:07 +00006605template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006606ExprResult
John McCall454feb92009-12-08 09:21:05 +00006607TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006608 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6609 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6610 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006611 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006612
John McCall60d7b3a2010-08-24 06:29:42 +00006613 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006614 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006615 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006616
Douglas Gregorb98b1992009-08-11 05:31:07 +00006617 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006618 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006619 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006620 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006621
John McCall1d7d8d62010-01-19 22:33:45 +00006622 // Note: the expression type doesn't necessarily match the
6623 // type-as-written, but that's okay, because it should always be
6624 // derivable from the initializer.
6625
John McCall42f56b52010-01-18 19:35:47 +00006626 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006627 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006628 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006629}
Mike Stump1eb44332009-09-09 15:08:12 +00006630
Douglas Gregorb98b1992009-08-11 05:31:07 +00006631template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006632ExprResult
John McCall454feb92009-12-08 09:21:05 +00006633TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006634 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006636 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006637
Douglas Gregorb98b1992009-08-11 05:31:07 +00006638 if (!getDerived().AlwaysRebuild() &&
6639 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006640 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006641
Douglas Gregorb98b1992009-08-11 05:31:07 +00006642 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006643 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006644 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006645 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006646 E->getAccessorLoc(),
6647 E->getAccessor());
6648}
Mike Stump1eb44332009-09-09 15:08:12 +00006649
Douglas Gregorb98b1992009-08-11 05:31:07 +00006650template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006651ExprResult
John McCall454feb92009-12-08 09:21:05 +00006652TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006653 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006654
John McCallca0408f2010-08-23 06:44:23 +00006655 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006656 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006657 Inits, &InitChanged))
6658 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006659
Douglas Gregorb98b1992009-08-11 05:31:07 +00006660 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006661 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006662
Douglas Gregorb98b1992009-08-11 05:31:07 +00006663 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006664 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006665}
Mike Stump1eb44332009-09-09 15:08:12 +00006666
Douglas Gregorb98b1992009-08-11 05:31:07 +00006667template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006668ExprResult
John McCall454feb92009-12-08 09:21:05 +00006669TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006670 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006671
Douglas Gregor43959a92009-08-20 07:17:43 +00006672 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006673 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006674 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006675 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006676
Douglas Gregor43959a92009-08-20 07:17:43 +00006677 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006678 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006679 bool ExprChanged = false;
6680 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6681 DEnd = E->designators_end();
6682 D != DEnd; ++D) {
6683 if (D->isFieldDesignator()) {
6684 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6685 D->getDotLoc(),
6686 D->getFieldLoc()));
6687 continue;
6688 }
Mike Stump1eb44332009-09-09 15:08:12 +00006689
Douglas Gregorb98b1992009-08-11 05:31:07 +00006690 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006691 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006692 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006693 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006694
6695 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006696 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006697
Douglas Gregorb98b1992009-08-11 05:31:07 +00006698 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6699 ArrayExprs.push_back(Index.release());
6700 continue;
6701 }
Mike Stump1eb44332009-09-09 15:08:12 +00006702
Douglas Gregorb98b1992009-08-11 05:31:07 +00006703 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006704 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006705 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6706 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006707 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006708
John McCall60d7b3a2010-08-24 06:29:42 +00006709 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006710 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006711 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006712
6713 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006714 End.get(),
6715 D->getLBracketLoc(),
6716 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006717
Douglas Gregorb98b1992009-08-11 05:31:07 +00006718 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6719 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006720
Douglas Gregorb98b1992009-08-11 05:31:07 +00006721 ArrayExprs.push_back(Start.release());
6722 ArrayExprs.push_back(End.release());
6723 }
Mike Stump1eb44332009-09-09 15:08:12 +00006724
Douglas Gregorb98b1992009-08-11 05:31:07 +00006725 if (!getDerived().AlwaysRebuild() &&
6726 Init.get() == E->getInit() &&
6727 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006728 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006729
Douglas Gregorb98b1992009-08-11 05:31:07 +00006730 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6731 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006732 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006733}
Mike Stump1eb44332009-09-09 15:08:12 +00006734
Douglas Gregorb98b1992009-08-11 05:31:07 +00006735template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006736ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006737TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006738 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006739 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006740
Douglas Gregor5557b252009-10-28 00:29:27 +00006741 // FIXME: Will we ever have proper type location here? Will we actually
6742 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006743 QualType T = getDerived().TransformType(E->getType());
6744 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006745 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006746
Douglas Gregorb98b1992009-08-11 05:31:07 +00006747 if (!getDerived().AlwaysRebuild() &&
6748 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006749 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006750
Douglas Gregorb98b1992009-08-11 05:31:07 +00006751 return getDerived().RebuildImplicitValueInitExpr(T);
6752}
Mike Stump1eb44332009-09-09 15:08:12 +00006753
Douglas Gregorb98b1992009-08-11 05:31:07 +00006754template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006755ExprResult
John McCall454feb92009-12-08 09:21:05 +00006756TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006757 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6758 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006759 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006760
John McCall60d7b3a2010-08-24 06:29:42 +00006761 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006762 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006763 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006764
Douglas Gregorb98b1992009-08-11 05:31:07 +00006765 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006766 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006767 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006768 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006769
John McCall9ae2f072010-08-23 23:25:46 +00006770 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006771 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006772}
6773
6774template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006775ExprResult
John McCall454feb92009-12-08 09:21:05 +00006776TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006777 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006778 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006779 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6780 &ArgumentChanged))
6781 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006782
Douglas Gregorb98b1992009-08-11 05:31:07 +00006783 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6784 move_arg(Inits),
6785 E->getRParenLoc());
6786}
Mike Stump1eb44332009-09-09 15:08:12 +00006787
Douglas Gregorb98b1992009-08-11 05:31:07 +00006788/// \brief Transform an address-of-label expression.
6789///
6790/// By default, the transformation of an address-of-label expression always
6791/// rebuilds the expression, so that the label identifier can be resolved to
6792/// the corresponding label statement by semantic analysis.
6793template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006794ExprResult
John McCall454feb92009-12-08 09:21:05 +00006795TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006796 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6797 E->getLabel());
6798 if (!LD)
6799 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006800
Douglas Gregorb98b1992009-08-11 05:31:07 +00006801 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006802 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006803}
Mike Stump1eb44332009-09-09 15:08:12 +00006804
6805template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006806ExprResult
John McCall454feb92009-12-08 09:21:05 +00006807TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006808 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006809 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006810 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006811 if (SubStmt.isInvalid()) {
6812 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006813 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006814 }
Mike Stump1eb44332009-09-09 15:08:12 +00006815
Douglas Gregorb98b1992009-08-11 05:31:07 +00006816 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006817 SubStmt.get() == E->getSubStmt()) {
6818 // Calling this an 'error' is unintuitive, but it does the right thing.
6819 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006820 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006821 }
Mike Stump1eb44332009-09-09 15:08:12 +00006822
6823 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006824 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006825 E->getRParenLoc());
6826}
Mike Stump1eb44332009-09-09 15:08:12 +00006827
Douglas Gregorb98b1992009-08-11 05:31:07 +00006828template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006829ExprResult
John McCall454feb92009-12-08 09:21:05 +00006830TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006831 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006832 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006833 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006834
John McCall60d7b3a2010-08-24 06:29:42 +00006835 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006836 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006837 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006838
John McCall60d7b3a2010-08-24 06:29:42 +00006839 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006840 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006841 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006842
Douglas Gregorb98b1992009-08-11 05:31:07 +00006843 if (!getDerived().AlwaysRebuild() &&
6844 Cond.get() == E->getCond() &&
6845 LHS.get() == E->getLHS() &&
6846 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006847 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006848
Douglas Gregorb98b1992009-08-11 05:31:07 +00006849 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006850 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006851 E->getRParenLoc());
6852}
Mike Stump1eb44332009-09-09 15:08:12 +00006853
Douglas Gregorb98b1992009-08-11 05:31:07 +00006854template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006855ExprResult
John McCall454feb92009-12-08 09:21:05 +00006856TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006857 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006858}
6859
6860template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006861ExprResult
John McCall454feb92009-12-08 09:21:05 +00006862TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006863 switch (E->getOperator()) {
6864 case OO_New:
6865 case OO_Delete:
6866 case OO_Array_New:
6867 case OO_Array_Delete:
6868 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006869
Douglas Gregor668d6d92009-12-13 20:44:55 +00006870 case OO_Call: {
6871 // This is a call to an object's operator().
6872 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6873
6874 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006875 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006876 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006877 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006878
6879 // FIXME: Poor location information
6880 SourceLocation FakeLParenLoc
6881 = SemaRef.PP.getLocForEndOfToken(
6882 static_cast<Expr *>(Object.get())->getLocEnd());
6883
6884 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006885 ASTOwningVector<Expr*> Args(SemaRef);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006886 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006887 Args))
6888 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006889
John McCall9ae2f072010-08-23 23:25:46 +00006890 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006891 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006892 E->getLocEnd());
6893 }
6894
6895#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6896 case OO_##Name:
6897#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6898#include "clang/Basic/OperatorKinds.def"
6899 case OO_Subscript:
6900 // Handled below.
6901 break;
6902
6903 case OO_Conditional:
6904 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006905
6906 case OO_None:
6907 case NUM_OVERLOADED_OPERATORS:
6908 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006909 }
6910
John McCall60d7b3a2010-08-24 06:29:42 +00006911 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006912 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006913 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006914
John McCall60d7b3a2010-08-24 06:29:42 +00006915 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006916 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006917 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006918
John McCall60d7b3a2010-08-24 06:29:42 +00006919 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006920 if (E->getNumArgs() == 2) {
6921 Second = getDerived().TransformExpr(E->getArg(1));
6922 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006923 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006924 }
Mike Stump1eb44332009-09-09 15:08:12 +00006925
Douglas Gregorb98b1992009-08-11 05:31:07 +00006926 if (!getDerived().AlwaysRebuild() &&
6927 Callee.get() == E->getCallee() &&
6928 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006929 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006930 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006931
Douglas Gregorb98b1992009-08-11 05:31:07 +00006932 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6933 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006934 Callee.get(),
6935 First.get(),
6936 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006937}
Mike Stump1eb44332009-09-09 15:08:12 +00006938
Douglas Gregorb98b1992009-08-11 05:31:07 +00006939template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006940ExprResult
John McCall454feb92009-12-08 09:21:05 +00006941TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6942 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006943}
Mike Stump1eb44332009-09-09 15:08:12 +00006944
Douglas Gregorb98b1992009-08-11 05:31:07 +00006945template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006946ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006947TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6948 // Transform the callee.
6949 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6950 if (Callee.isInvalid())
6951 return ExprError();
6952
6953 // Transform exec config.
6954 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6955 if (EC.isInvalid())
6956 return ExprError();
6957
6958 // Transform arguments.
6959 bool ArgChanged = false;
6960 ASTOwningVector<Expr*> Args(SemaRef);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006961 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006962 &ArgChanged))
6963 return ExprError();
6964
6965 if (!getDerived().AlwaysRebuild() &&
6966 Callee.get() == E->getCallee() &&
6967 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006968 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006969
6970 // FIXME: Wrong source location information for the '('.
6971 SourceLocation FakeLParenLoc
6972 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6973 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6974 move_arg(Args),
6975 E->getRParenLoc(), EC.get());
6976}
6977
6978template<typename Derived>
6979ExprResult
John McCall454feb92009-12-08 09:21:05 +00006980TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006981 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6982 if (!Type)
6983 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006984
John McCall60d7b3a2010-08-24 06:29:42 +00006985 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006986 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006987 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006988 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006989
Douglas Gregorb98b1992009-08-11 05:31:07 +00006990 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006991 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006992 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006993 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006994
Douglas Gregorb98b1992009-08-11 05:31:07 +00006995 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006996 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006997 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6998 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6999 SourceLocation FakeRParenLoc
7000 = SemaRef.PP.getLocForEndOfToken(
7001 E->getSubExpr()->getSourceRange().getEnd());
7002 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007003 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007004 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007005 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007006 FakeRAngleLoc,
7007 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007008 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007009 FakeRParenLoc);
7010}
Mike Stump1eb44332009-09-09 15:08:12 +00007011
Douglas Gregorb98b1992009-08-11 05:31:07 +00007012template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007013ExprResult
John McCall454feb92009-12-08 09:21:05 +00007014TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7015 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007016}
Mike Stump1eb44332009-09-09 15:08:12 +00007017
7018template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007019ExprResult
John McCall454feb92009-12-08 09:21:05 +00007020TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7021 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007022}
7023
Douglas Gregorb98b1992009-08-11 05:31:07 +00007024template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007025ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007026TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007027 CXXReinterpretCastExpr *E) {
7028 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007029}
Mike Stump1eb44332009-09-09 15:08:12 +00007030
Douglas Gregorb98b1992009-08-11 05:31:07 +00007031template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007032ExprResult
John McCall454feb92009-12-08 09:21:05 +00007033TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7034 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007035}
Mike Stump1eb44332009-09-09 15:08:12 +00007036
Douglas Gregorb98b1992009-08-11 05:31:07 +00007037template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007038ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007039TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007040 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007041 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7042 if (!Type)
7043 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007044
John McCall60d7b3a2010-08-24 06:29:42 +00007045 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007046 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007047 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007048 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007049
Douglas Gregorb98b1992009-08-11 05:31:07 +00007050 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007051 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007052 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007053 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007054
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007055 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007056 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007057 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007058 E->getRParenLoc());
7059}
Mike Stump1eb44332009-09-09 15:08:12 +00007060
Douglas Gregorb98b1992009-08-11 05:31:07 +00007061template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007062ExprResult
John McCall454feb92009-12-08 09:21:05 +00007063TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007064 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007065 TypeSourceInfo *TInfo
7066 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7067 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007068 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007069
Douglas Gregorb98b1992009-08-11 05:31:07 +00007070 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007071 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007072 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007073
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007074 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7075 E->getLocStart(),
7076 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007077 E->getLocEnd());
7078 }
Mike Stump1eb44332009-09-09 15:08:12 +00007079
Eli Friedmanef331b72012-01-20 01:26:23 +00007080 // We don't know whether the subexpression is potentially evaluated until
7081 // after we perform semantic analysis. We speculatively assume it is
7082 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007083 // potentially evaluated.
Eli Friedmanef331b72012-01-20 01:26:23 +00007084 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00007085
John McCall60d7b3a2010-08-24 06:29:42 +00007086 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007087 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007088 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007089
Douglas Gregorb98b1992009-08-11 05:31:07 +00007090 if (!getDerived().AlwaysRebuild() &&
7091 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007092 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007093
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007094 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7095 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007096 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007097 E->getLocEnd());
7098}
7099
7100template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007101ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007102TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7103 if (E->isTypeOperand()) {
7104 TypeSourceInfo *TInfo
7105 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7106 if (!TInfo)
7107 return ExprError();
7108
7109 if (!getDerived().AlwaysRebuild() &&
7110 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007111 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007112
Douglas Gregor3c52a212011-03-06 17:40:41 +00007113 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007114 E->getLocStart(),
7115 TInfo,
7116 E->getLocEnd());
7117 }
7118
Francois Pichet01b7c302010-09-08 12:20:18 +00007119 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7120
7121 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7122 if (SubExpr.isInvalid())
7123 return ExprError();
7124
7125 if (!getDerived().AlwaysRebuild() &&
7126 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007127 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007128
7129 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7130 E->getLocStart(),
7131 SubExpr.get(),
7132 E->getLocEnd());
7133}
7134
7135template<typename Derived>
7136ExprResult
John McCall454feb92009-12-08 09:21:05 +00007137TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007138 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007139}
Mike Stump1eb44332009-09-09 15:08:12 +00007140
Douglas Gregorb98b1992009-08-11 05:31:07 +00007141template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007142ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007143TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007144 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007145 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007146}
Mike Stump1eb44332009-09-09 15:08:12 +00007147
Douglas Gregorb98b1992009-08-11 05:31:07 +00007148template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007149ExprResult
John McCall454feb92009-12-08 09:21:05 +00007150TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007151 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007152 QualType T;
7153 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7154 T = MD->getThisType(getSema().Context);
7155 else
7156 T = getSema().Context.getPointerType(
7157 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007158
Douglas Gregorec79d872012-02-24 17:41:38 +00007159 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7160 // Make sure that we capture 'this'.
7161 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007162 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007163 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007164
Douglas Gregor828a1972010-01-07 23:12:05 +00007165 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007166}
Mike Stump1eb44332009-09-09 15:08:12 +00007167
Douglas Gregorb98b1992009-08-11 05:31:07 +00007168template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007169ExprResult
John McCall454feb92009-12-08 09:21:05 +00007170TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007171 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007172 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007173 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007174
Douglas Gregorb98b1992009-08-11 05:31:07 +00007175 if (!getDerived().AlwaysRebuild() &&
7176 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007177 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007178
Douglas Gregorbca01b42011-07-06 22:04:06 +00007179 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7180 E->isThrownVariableInScope());
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>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007186 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007187 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7188 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007189 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007190 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007191
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007192 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007193 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007194 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007195
Douglas Gregor036aed12009-12-23 23:03:06 +00007196 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007197}
Mike Stump1eb44332009-09-09 15:08:12 +00007198
Douglas Gregorb98b1992009-08-11 05:31:07 +00007199template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007200ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007201TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7202 CXXScalarValueInitExpr *E) {
7203 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7204 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007205 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007206
Douglas Gregorb98b1992009-08-11 05:31:07 +00007207 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007208 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007209 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007210
Chad Rosier4a9d7952012-08-08 18:46:20 +00007211 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007212 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007213 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007214}
Mike Stump1eb44332009-09-09 15:08:12 +00007215
Douglas Gregorb98b1992009-08-11 05:31:07 +00007216template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007217ExprResult
John McCall454feb92009-12-08 09:21:05 +00007218TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007219 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007220 TypeSourceInfo *AllocTypeInfo
7221 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7222 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007223 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007224
Douglas Gregorb98b1992009-08-11 05:31:07 +00007225 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007226 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007227 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007228 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007229
Douglas Gregorb98b1992009-08-11 05:31:07 +00007230 // Transform the placement arguments (if any).
7231 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007232 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007233 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007234 E->getNumPlacementArgs(), true,
7235 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007236 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007237
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007238 // Transform the initializer (if any).
7239 Expr *OldInit = E->getInitializer();
7240 ExprResult NewInit;
7241 if (OldInit)
7242 NewInit = getDerived().TransformExpr(OldInit);
7243 if (NewInit.isInvalid())
7244 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007245
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007246 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007247 FunctionDecl *OperatorNew = 0;
7248 if (E->getOperatorNew()) {
7249 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007250 getDerived().TransformDecl(E->getLocStart(),
7251 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007252 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007253 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007254 }
7255
7256 FunctionDecl *OperatorDelete = 0;
7257 if (E->getOperatorDelete()) {
7258 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007259 getDerived().TransformDecl(E->getLocStart(),
7260 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007261 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007262 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007263 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007264
Douglas Gregorb98b1992009-08-11 05:31:07 +00007265 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007266 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007267 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007268 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007269 OperatorNew == E->getOperatorNew() &&
7270 OperatorDelete == E->getOperatorDelete() &&
7271 !ArgumentChanged) {
7272 // Mark any declarations we need as referenced.
7273 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007274 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007275 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007276 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007277 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007278
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007279 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007280 QualType ElementType
7281 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7282 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7283 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7284 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007285 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007286 }
7287 }
7288 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007289
John McCall3fa5cae2010-10-26 07:05:15 +00007290 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007291 }
Mike Stump1eb44332009-09-09 15:08:12 +00007292
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007293 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007294 if (!ArraySize.get()) {
7295 // If no array size was specified, but the new expression was
7296 // instantiated with an array type (e.g., "new T" where T is
7297 // instantiated with "int[4]"), extract the outer bound from the
7298 // array type as our array size. We do this with constant and
7299 // dependently-sized array types.
7300 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7301 if (!ArrayT) {
7302 // Do nothing
7303 } else if (const ConstantArrayType *ConsArrayT
7304 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007305 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007306 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007307 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007308 SemaRef.Context.getSizeType(),
7309 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007310 AllocType = ConsArrayT->getElementType();
7311 } else if (const DependentSizedArrayType *DepArrayT
7312 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7313 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007314 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007315 AllocType = DepArrayT->getElementType();
7316 }
7317 }
7318 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007319
Douglas Gregorb98b1992009-08-11 05:31:07 +00007320 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7321 E->isGlobalNew(),
7322 /*FIXME:*/E->getLocStart(),
7323 move_arg(PlacementArgs),
7324 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007325 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007326 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007327 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007328 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007329 E->getDirectInitRange(),
7330 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007331}
Mike Stump1eb44332009-09-09 15:08:12 +00007332
Douglas Gregorb98b1992009-08-11 05:31:07 +00007333template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007334ExprResult
John McCall454feb92009-12-08 09:21:05 +00007335TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007336 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007337 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007338 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007339
Douglas Gregor1af74512010-02-26 00:38:10 +00007340 // Transform the delete operator, if known.
7341 FunctionDecl *OperatorDelete = 0;
7342 if (E->getOperatorDelete()) {
7343 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007344 getDerived().TransformDecl(E->getLocStart(),
7345 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007346 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007347 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007348 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007349
Douglas Gregorb98b1992009-08-11 05:31:07 +00007350 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007351 Operand.get() == E->getArgument() &&
7352 OperatorDelete == E->getOperatorDelete()) {
7353 // Mark any declarations we need as referenced.
7354 // FIXME: instantiation-specific.
7355 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007356 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007357
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007358 if (!E->getArgument()->isTypeDependent()) {
7359 QualType Destroyed = SemaRef.Context.getBaseElementType(
7360 E->getDestroyedType());
7361 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7362 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007363 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007364 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007365 }
7366 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007367
John McCall3fa5cae2010-10-26 07:05:15 +00007368 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007369 }
Mike Stump1eb44332009-09-09 15:08:12 +00007370
Douglas Gregorb98b1992009-08-11 05:31:07 +00007371 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7372 E->isGlobalDelete(),
7373 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007374 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007375}
Mike Stump1eb44332009-09-09 15:08:12 +00007376
Douglas Gregorb98b1992009-08-11 05:31:07 +00007377template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007378ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007379TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007380 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007381 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007382 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007383 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007384
John McCallb3d87482010-08-24 05:47:05 +00007385 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007386 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007387 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007388 E->getOperatorLoc(),
7389 E->isArrow()? tok::arrow : tok::period,
7390 ObjectTypePtr,
7391 MayBePseudoDestructor);
7392 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007393 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007394
John McCallb3d87482010-08-24 05:47:05 +00007395 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007396 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7397 if (QualifierLoc) {
7398 QualifierLoc
7399 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7400 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007401 return ExprError();
7402 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007403 CXXScopeSpec SS;
7404 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007405
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007406 PseudoDestructorTypeStorage Destroyed;
7407 if (E->getDestroyedTypeInfo()) {
7408 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007409 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007410 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007411 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007412 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007413 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007414 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007415 // We aren't likely to be able to resolve the identifier down to a type
7416 // now anyway, so just retain the identifier.
7417 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7418 E->getDestroyedTypeLoc());
7419 } else {
7420 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007421 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007422 *E->getDestroyedTypeIdentifier(),
7423 E->getDestroyedTypeLoc(),
7424 /*Scope=*/0,
7425 SS, ObjectTypePtr,
7426 false);
7427 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007428 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007429
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007430 Destroyed
7431 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7432 E->getDestroyedTypeLoc());
7433 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007434
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007435 TypeSourceInfo *ScopeTypeInfo = 0;
7436 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007437 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007438 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007439 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007440 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007441
John McCall9ae2f072010-08-23 23:25:46 +00007442 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007443 E->getOperatorLoc(),
7444 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007445 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007446 ScopeTypeInfo,
7447 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007448 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007449 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007450}
Mike Stump1eb44332009-09-09 15:08:12 +00007451
Douglas Gregora71d8192009-09-04 17:36:40 +00007452template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007453ExprResult
John McCallba135432009-11-21 08:51:07 +00007454TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007455 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007456 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7457 Sema::LookupOrdinaryName);
7458
7459 // Transform all the decls.
7460 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7461 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007462 NamedDecl *InstD = static_cast<NamedDecl*>(
7463 getDerived().TransformDecl(Old->getNameLoc(),
7464 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007465 if (!InstD) {
7466 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7467 // This can happen because of dependent hiding.
7468 if (isa<UsingShadowDecl>(*I))
7469 continue;
7470 else
John McCallf312b1e2010-08-26 23:41:50 +00007471 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007472 }
John McCallf7a1a742009-11-24 19:00:30 +00007473
7474 // Expand using declarations.
7475 if (isa<UsingDecl>(InstD)) {
7476 UsingDecl *UD = cast<UsingDecl>(InstD);
7477 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7478 E = UD->shadow_end(); I != E; ++I)
7479 R.addDecl(*I);
7480 continue;
7481 }
7482
7483 R.addDecl(InstD);
7484 }
7485
7486 // Resolve a kind, but don't do any further analysis. If it's
7487 // ambiguous, the callee needs to deal with it.
7488 R.resolveKind();
7489
7490 // Rebuild the nested-name qualifier, if present.
7491 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007492 if (Old->getQualifierLoc()) {
7493 NestedNameSpecifierLoc QualifierLoc
7494 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7495 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007496 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007497
Douglas Gregor4c9be892011-02-28 20:01:57 +00007498 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007499 }
7500
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007501 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007502 CXXRecordDecl *NamingClass
7503 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7504 Old->getNameLoc(),
7505 Old->getNamingClass()));
7506 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007507 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007508
Douglas Gregor66c45152010-04-27 16:10:10 +00007509 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007510 }
7511
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007512 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7513
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007514 // If we have neither explicit template arguments, nor the template keyword,
7515 // it's a normal declaration name.
7516 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007517 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7518
7519 // If we have template arguments, rebuild them, then rebuild the
7520 // templateid expression.
7521 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007522 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7523 Old->getNumTemplateArgs(),
7524 TransArgs))
7525 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007526
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007527 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007528 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007529}
Mike Stump1eb44332009-09-09 15:08:12 +00007530
Douglas Gregorb98b1992009-08-11 05:31:07 +00007531template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007532ExprResult
John McCall454feb92009-12-08 09:21:05 +00007533TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007534 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7535 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007536 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007537
Douglas Gregorb98b1992009-08-11 05:31:07 +00007538 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007539 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007540 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007541
Mike Stump1eb44332009-09-09 15:08:12 +00007542 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007543 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007544 T,
7545 E->getLocEnd());
7546}
Mike Stump1eb44332009-09-09 15:08:12 +00007547
Douglas Gregorb98b1992009-08-11 05:31:07 +00007548template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007549ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007550TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7551 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7552 if (!LhsT)
7553 return ExprError();
7554
7555 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7556 if (!RhsT)
7557 return ExprError();
7558
7559 if (!getDerived().AlwaysRebuild() &&
7560 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7561 return SemaRef.Owned(E);
7562
7563 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7564 E->getLocStart(),
7565 LhsT, RhsT,
7566 E->getLocEnd());
7567}
7568
7569template<typename Derived>
7570ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007571TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7572 bool ArgChanged = false;
7573 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7574 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7575 TypeSourceInfo *From = E->getArg(I);
7576 TypeLoc FromTL = From->getTypeLoc();
7577 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7578 TypeLocBuilder TLB;
7579 TLB.reserve(FromTL.getFullDataSize());
7580 QualType To = getDerived().TransformType(TLB, FromTL);
7581 if (To.isNull())
7582 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007583
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007584 if (To == From->getType())
7585 Args.push_back(From);
7586 else {
7587 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7588 ArgChanged = true;
7589 }
7590 continue;
7591 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007592
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007593 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007594
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007595 // We have a pack expansion. Instantiate it.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007596 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007597 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7598 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7599 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007600
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007601 // Determine whether the set of unexpanded parameter packs can and should
7602 // be expanded.
7603 bool Expand = true;
7604 bool RetainExpansion = false;
7605 llvm::Optional<unsigned> OrigNumExpansions
7606 = ExpansionTL.getTypePtr()->getNumExpansions();
7607 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7608 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7609 PatternTL.getSourceRange(),
7610 Unexpanded,
7611 Expand, RetainExpansion,
7612 NumExpansions))
7613 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007614
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007615 if (!Expand) {
7616 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007617 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007618 // expansion.
7619 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007620
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007621 TypeLocBuilder TLB;
7622 TLB.reserve(From->getTypeLoc().getFullDataSize());
7623
7624 QualType To = getDerived().TransformType(TLB, PatternTL);
7625 if (To.isNull())
7626 return ExprError();
7627
Chad Rosier4a9d7952012-08-08 18:46:20 +00007628 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007629 PatternTL.getSourceRange(),
7630 ExpansionTL.getEllipsisLoc(),
7631 NumExpansions);
7632 if (To.isNull())
7633 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007634
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007635 PackExpansionTypeLoc ToExpansionTL
7636 = TLB.push<PackExpansionTypeLoc>(To);
7637 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7638 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7639 continue;
7640 }
7641
7642 // Expand the pack expansion by substituting for each argument in the
7643 // pack(s).
7644 for (unsigned I = 0; I != *NumExpansions; ++I) {
7645 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7646 TypeLocBuilder TLB;
7647 TLB.reserve(PatternTL.getFullDataSize());
7648 QualType To = getDerived().TransformType(TLB, PatternTL);
7649 if (To.isNull())
7650 return ExprError();
7651
7652 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7653 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007654
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007655 if (!RetainExpansion)
7656 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007657
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007658 // If we're supposed to retain a pack expansion, do so by temporarily
7659 // forgetting the partially-substituted parameter pack.
7660 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7661
7662 TypeLocBuilder TLB;
7663 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007664
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007665 QualType To = getDerived().TransformType(TLB, PatternTL);
7666 if (To.isNull())
7667 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007668
7669 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007670 PatternTL.getSourceRange(),
7671 ExpansionTL.getEllipsisLoc(),
7672 NumExpansions);
7673 if (To.isNull())
7674 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007675
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007676 PackExpansionTypeLoc ToExpansionTL
7677 = TLB.push<PackExpansionTypeLoc>(To);
7678 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7679 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7680 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007681
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007682 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7683 return SemaRef.Owned(E);
7684
7685 return getDerived().RebuildTypeTrait(E->getTrait(),
7686 E->getLocStart(),
7687 Args,
7688 E->getLocEnd());
7689}
7690
7691template<typename Derived>
7692ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007693TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7694 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7695 if (!T)
7696 return ExprError();
7697
7698 if (!getDerived().AlwaysRebuild() &&
7699 T == E->getQueriedTypeSourceInfo())
7700 return SemaRef.Owned(E);
7701
7702 ExprResult SubExpr;
7703 {
7704 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7705 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7706 if (SubExpr.isInvalid())
7707 return ExprError();
7708
7709 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7710 return SemaRef.Owned(E);
7711 }
7712
7713 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7714 E->getLocStart(),
7715 T,
7716 SubExpr.get(),
7717 E->getLocEnd());
7718}
7719
7720template<typename Derived>
7721ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007722TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7723 ExprResult SubExpr;
7724 {
7725 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7726 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7727 if (SubExpr.isInvalid())
7728 return ExprError();
7729
7730 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7731 return SemaRef.Owned(E);
7732 }
7733
7734 return getDerived().RebuildExpressionTrait(
7735 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7736}
7737
7738template<typename Derived>
7739ExprResult
John McCall865d4472009-11-19 22:55:06 +00007740TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007741 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007742 NestedNameSpecifierLoc QualifierLoc
7743 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7744 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007745 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007746 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007747
John McCall43fed0d2010-11-12 08:19:04 +00007748 // TODO: If this is a conversion-function-id, verify that the
7749 // destination type name (if present) resolves the same way after
7750 // instantiation as it did in the local scope.
7751
Abramo Bagnara25777432010-08-11 22:01:17 +00007752 DeclarationNameInfo NameInfo
7753 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7754 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007755 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007756
John McCallf7a1a742009-11-24 19:00:30 +00007757 if (!E->hasExplicitTemplateArgs()) {
7758 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007759 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007760 // Note: it is sufficient to compare the Name component of NameInfo:
7761 // if name has not changed, DNLoc has not changed either.
7762 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007763 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007764
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007765 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007766 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007767 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007768 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007769 }
John McCalld5532b62009-11-23 01:53:49 +00007770
7771 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007772 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7773 E->getNumTemplateArgs(),
7774 TransArgs))
7775 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007776
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007777 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007778 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007779 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007780 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007781}
7782
7783template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007784ExprResult
John McCall454feb92009-12-08 09:21:05 +00007785TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007786 // CXXConstructExprs are always implicit, so when we have a
7787 // 1-argument construction we just transform that argument.
7788 if (E->getNumArgs() == 1 ||
7789 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7790 return getDerived().TransformExpr(E->getArg(0));
7791
Douglas Gregorb98b1992009-08-11 05:31:07 +00007792 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7793
7794 QualType T = getDerived().TransformType(E->getType());
7795 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007796 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007797
7798 CXXConstructorDecl *Constructor
7799 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007800 getDerived().TransformDecl(E->getLocStart(),
7801 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007802 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007803 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007804
Douglas Gregorb98b1992009-08-11 05:31:07 +00007805 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007806 ASTOwningVector<Expr*> Args(SemaRef);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007807 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007808 &ArgumentChanged))
7809 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007810
Douglas Gregorb98b1992009-08-11 05:31:07 +00007811 if (!getDerived().AlwaysRebuild() &&
7812 T == E->getType() &&
7813 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007814 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007815 // Mark the constructor as referenced.
7816 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007817 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007818 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007819 }
Mike Stump1eb44332009-09-09 15:08:12 +00007820
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007821 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7822 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007823 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007824 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007825 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007826 E->getConstructionKind(),
7827 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007828}
Mike Stump1eb44332009-09-09 15:08:12 +00007829
Douglas Gregorb98b1992009-08-11 05:31:07 +00007830/// \brief Transform a C++ temporary-binding expression.
7831///
Douglas Gregor51326552009-12-24 18:51:59 +00007832/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7833/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007834template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007835ExprResult
John McCall454feb92009-12-08 09:21:05 +00007836TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007837 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007838}
Mike Stump1eb44332009-09-09 15:08:12 +00007839
John McCall4765fa02010-12-06 08:20:24 +00007840/// \brief Transform a C++ expression that contains cleanups that should
7841/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007842///
John McCall4765fa02010-12-06 08:20:24 +00007843/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007844/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007845template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007846ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007847TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007848 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007849}
Mike Stump1eb44332009-09-09 15:08:12 +00007850
Douglas Gregorb98b1992009-08-11 05:31:07 +00007851template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007852ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007853TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007854 CXXTemporaryObjectExpr *E) {
7855 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7856 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007857 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007858
Douglas Gregorb98b1992009-08-11 05:31:07 +00007859 CXXConstructorDecl *Constructor
7860 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00007861 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007862 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007863 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007864 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007865
Douglas Gregorb98b1992009-08-11 05:31:07 +00007866 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007867 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007868 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007869 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007870 &ArgumentChanged))
7871 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007872
Douglas Gregorb98b1992009-08-11 05:31:07 +00007873 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007874 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007875 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007876 !ArgumentChanged) {
7877 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007878 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007879 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007880 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007881
Douglas Gregorab6677e2010-09-08 00:15:04 +00007882 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7883 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007884 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007885 E->getLocEnd());
7886}
Mike Stump1eb44332009-09-09 15:08:12 +00007887
Douglas Gregorb98b1992009-08-11 05:31:07 +00007888template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007889ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007890TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007891 // Create the local class that will describe the lambda.
7892 CXXRecordDecl *Class
Douglas Gregorf54486a2012-04-04 17:40:10 +00007893 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7894 /*KnownDependent=*/false);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007895 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007896
Douglas Gregordfca6f52012-02-13 22:00:16 +00007897 // Transform the type of the lambda parameters and start the definition of
7898 // the lambda itself.
7899 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00007900 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00007901 if (!MethodTy)
7902 return ExprError();
7903
Douglas Gregorc6889e72012-02-14 22:28:59 +00007904 // Transform lambda parameters.
Douglas Gregorc6889e72012-02-14 22:28:59 +00007905 llvm::SmallVector<QualType, 4> ParamTypes;
7906 llvm::SmallVector<ParmVarDecl *, 4> Params;
7907 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7908 E->getCallOperator()->param_begin(),
7909 E->getCallOperator()->param_size(),
7910 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00007911 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00007912
Douglas Gregordfca6f52012-02-13 22:00:16 +00007913 // Build the call operator.
7914 CXXMethodDecl *CallOperator
7915 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007916 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007917 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007918 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007919 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00007920
Richard Smith612409e2012-07-25 03:56:55 +00007921 return getDerived().TransformLambdaScope(E, CallOperator);
7922}
7923
7924template<typename Derived>
7925ExprResult
7926TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
7927 CXXMethodDecl *CallOperator) {
Douglas Gregord5387e82012-02-14 00:00:48 +00007928 // Introduce the context of the call operator.
7929 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7930
Douglas Gregordfca6f52012-02-13 22:00:16 +00007931 // Enter the scope of the lambda.
7932 sema::LambdaScopeInfo *LSI
7933 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7934 E->getCaptureDefault(),
7935 E->hasExplicitParameters(),
7936 E->hasExplicitResultType(),
7937 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007938
Douglas Gregordfca6f52012-02-13 22:00:16 +00007939 // Transform captures.
Richard Smith612409e2012-07-25 03:56:55 +00007940 bool Invalid = false;
Douglas Gregordfca6f52012-02-13 22:00:16 +00007941 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007942 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007943 CEnd = E->capture_end();
7944 C != CEnd; ++C) {
7945 // When we hit the first implicit capture, tell Sema that we've finished
7946 // the list of explicit captures.
7947 if (!FinishedExplicitCaptures && C->isImplicit()) {
7948 getSema().finishLambdaExplicitCaptures(LSI);
7949 FinishedExplicitCaptures = true;
7950 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007951
Douglas Gregordfca6f52012-02-13 22:00:16 +00007952 // Capturing 'this' is trivial.
7953 if (C->capturesThis()) {
7954 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7955 continue;
7956 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007957
Douglas Gregora7365242012-02-14 19:27:52 +00007958 // Determine the capture kind for Sema.
7959 Sema::TryCaptureKind Kind
7960 = C->isImplicit()? Sema::TryCapture_Implicit
7961 : C->getCaptureKind() == LCK_ByCopy
7962 ? Sema::TryCapture_ExplicitByVal
7963 : Sema::TryCapture_ExplicitByRef;
7964 SourceLocation EllipsisLoc;
7965 if (C->isPackExpansion()) {
7966 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7967 bool ShouldExpand = false;
7968 bool RetainExpansion = false;
7969 llvm::Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007970 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7971 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00007972 Unexpanded,
7973 ShouldExpand, RetainExpansion,
7974 NumExpansions))
7975 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007976
Douglas Gregora7365242012-02-14 19:27:52 +00007977 if (ShouldExpand) {
7978 // The transform has determined that we should perform an expansion;
7979 // transform and capture each of the arguments.
7980 // expansion of the pattern. Do so.
7981 VarDecl *Pack = C->getCapturedVar();
7982 for (unsigned I = 0; I != *NumExpansions; ++I) {
7983 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7984 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00007985 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00007986 Pack));
7987 if (!CapturedVar) {
7988 Invalid = true;
7989 continue;
7990 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007991
Douglas Gregora7365242012-02-14 19:27:52 +00007992 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007993 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
7994 }
Douglas Gregora7365242012-02-14 19:27:52 +00007995 continue;
7996 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007997
Douglas Gregora7365242012-02-14 19:27:52 +00007998 EllipsisLoc = C->getEllipsisLoc();
7999 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008000
Douglas Gregordfca6f52012-02-13 22:00:16 +00008001 // Transform the captured variable.
8002 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008003 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008004 C->getCapturedVar()));
8005 if (!CapturedVar) {
8006 Invalid = true;
8007 continue;
8008 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008009
Douglas Gregordfca6f52012-02-13 22:00:16 +00008010 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008011 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008012 }
8013 if (!FinishedExplicitCaptures)
8014 getSema().finishLambdaExplicitCaptures(LSI);
8015
Douglas Gregordfca6f52012-02-13 22:00:16 +00008016
8017 // Enter a new evaluation context to insulate the lambda from any
8018 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008019 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008020
8021 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008022 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008023 /*IsInstantiation=*/true);
8024 return ExprError();
8025 }
8026
8027 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008028 StmtResult Body = getDerived().TransformStmt(E->getBody());
8029 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008030 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008031 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008032 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008033 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008034
Chad Rosier4a9d7952012-08-08 18:46:20 +00008035 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008036 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008037}
8038
8039template<typename Derived>
8040ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008041TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008042 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008043 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8044 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008045 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008046
Douglas Gregorb98b1992009-08-11 05:31:07 +00008047 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008048 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008049 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008050 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008051 &ArgumentChanged))
8052 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008053
Douglas Gregorb98b1992009-08-11 05:31:07 +00008054 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008055 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008056 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008057 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008058
Douglas Gregorb98b1992009-08-11 05:31:07 +00008059 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008060 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008061 E->getLParenLoc(),
8062 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00008063 E->getRParenLoc());
8064}
Mike Stump1eb44332009-09-09 15:08:12 +00008065
Douglas Gregorb98b1992009-08-11 05:31:07 +00008066template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008067ExprResult
John McCall865d4472009-11-19 22:55:06 +00008068TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008069 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008070 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008071 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008072 Expr *OldBase;
8073 QualType BaseType;
8074 QualType ObjectType;
8075 if (!E->isImplicitAccess()) {
8076 OldBase = E->getBase();
8077 Base = getDerived().TransformExpr(OldBase);
8078 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008079 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008080
John McCallaa81e162009-12-01 22:10:20 +00008081 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008082 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008083 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008084 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008085 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008086 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008087 ObjectTy,
8088 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008089 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008090 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008091
John McCallb3d87482010-08-24 05:47:05 +00008092 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008093 BaseType = ((Expr*) Base.get())->getType();
8094 } else {
8095 OldBase = 0;
8096 BaseType = getDerived().TransformType(E->getBaseType());
8097 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8098 }
Mike Stump1eb44332009-09-09 15:08:12 +00008099
Douglas Gregor6cd21982009-10-20 05:58:46 +00008100 // Transform the first part of the nested-name-specifier that qualifies
8101 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008102 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008103 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008104 E->getFirstQualifierFoundInScope(),
8105 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008106
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008107 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008108 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008109 QualifierLoc
8110 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8111 ObjectType,
8112 FirstQualifierInScope);
8113 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008114 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008115 }
Mike Stump1eb44332009-09-09 15:08:12 +00008116
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008117 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8118
John McCall43fed0d2010-11-12 08:19:04 +00008119 // TODO: If this is a conversion-function-id, verify that the
8120 // destination type name (if present) resolves the same way after
8121 // instantiation as it did in the local scope.
8122
Abramo Bagnara25777432010-08-11 22:01:17 +00008123 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008124 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008125 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008126 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008127
John McCallaa81e162009-12-01 22:10:20 +00008128 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008129 // This is a reference to a member without an explicitly-specified
8130 // template argument list. Optimize for this common case.
8131 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008132 Base.get() == OldBase &&
8133 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008134 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008135 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008136 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008137 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008138
John McCall9ae2f072010-08-23 23:25:46 +00008139 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008140 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008141 E->isArrow(),
8142 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008143 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008144 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008145 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008146 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008147 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008148 }
8149
John McCalld5532b62009-11-23 01:53:49 +00008150 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008151 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8152 E->getNumTemplateArgs(),
8153 TransArgs))
8154 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008155
John McCall9ae2f072010-08-23 23:25:46 +00008156 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008157 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008158 E->isArrow(),
8159 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008160 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008161 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008162 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008163 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008164 &TransArgs);
8165}
8166
8167template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008168ExprResult
John McCall454feb92009-12-08 09:21:05 +00008169TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008170 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008171 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008172 QualType BaseType;
8173 if (!Old->isImplicitAccess()) {
8174 Base = getDerived().TransformExpr(Old->getBase());
8175 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008176 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008177 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8178 Old->isArrow());
8179 if (Base.isInvalid())
8180 return ExprError();
8181 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008182 } else {
8183 BaseType = getDerived().TransformType(Old->getBaseType());
8184 }
John McCall129e2df2009-11-30 22:42:35 +00008185
Douglas Gregor4c9be892011-02-28 20:01:57 +00008186 NestedNameSpecifierLoc QualifierLoc;
8187 if (Old->getQualifierLoc()) {
8188 QualifierLoc
8189 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8190 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008191 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008192 }
8193
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008194 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8195
Abramo Bagnara25777432010-08-11 22:01:17 +00008196 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008197 Sema::LookupOrdinaryName);
8198
8199 // Transform all the decls.
8200 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8201 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008202 NamedDecl *InstD = static_cast<NamedDecl*>(
8203 getDerived().TransformDecl(Old->getMemberLoc(),
8204 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008205 if (!InstD) {
8206 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8207 // This can happen because of dependent hiding.
8208 if (isa<UsingShadowDecl>(*I))
8209 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008210 else {
8211 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008212 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008213 }
John McCall9f54ad42009-12-10 09:41:52 +00008214 }
John McCall129e2df2009-11-30 22:42:35 +00008215
8216 // Expand using declarations.
8217 if (isa<UsingDecl>(InstD)) {
8218 UsingDecl *UD = cast<UsingDecl>(InstD);
8219 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8220 E = UD->shadow_end(); I != E; ++I)
8221 R.addDecl(*I);
8222 continue;
8223 }
8224
8225 R.addDecl(InstD);
8226 }
8227
8228 R.resolveKind();
8229
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008230 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008231 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008232 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008233 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008234 Old->getMemberLoc(),
8235 Old->getNamingClass()));
8236 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008237 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008238
Douglas Gregor66c45152010-04-27 16:10:10 +00008239 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008240 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008241
John McCall129e2df2009-11-30 22:42:35 +00008242 TemplateArgumentListInfo TransArgs;
8243 if (Old->hasExplicitTemplateArgs()) {
8244 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8245 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008246 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8247 Old->getNumTemplateArgs(),
8248 TransArgs))
8249 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008250 }
John McCallc2233c52010-01-15 08:34:02 +00008251
8252 // FIXME: to do this check properly, we will need to preserve the
8253 // first-qualifier-in-scope here, just in case we had a dependent
8254 // base (and therefore couldn't do the check) and a
8255 // nested-name-qualifier (and therefore could do the lookup).
8256 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008257
John McCall9ae2f072010-08-23 23:25:46 +00008258 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008259 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008260 Old->getOperatorLoc(),
8261 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008262 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008263 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008264 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008265 R,
8266 (Old->hasExplicitTemplateArgs()
8267 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008268}
8269
8270template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008271ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008272TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008273 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008274 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8275 if (SubExpr.isInvalid())
8276 return ExprError();
8277
8278 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008279 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008280
8281 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8282}
8283
8284template<typename Derived>
8285ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008286TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008287 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8288 if (Pattern.isInvalid())
8289 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008290
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008291 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8292 return SemaRef.Owned(E);
8293
Douglas Gregor67fd1252011-01-14 21:20:45 +00008294 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8295 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008296}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008297
8298template<typename Derived>
8299ExprResult
8300TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8301 // If E is not value-dependent, then nothing will change when we transform it.
8302 // Note: This is an instantiation-centric view.
8303 if (!E->isValueDependent())
8304 return SemaRef.Owned(E);
8305
8306 // Note: None of the implementations of TryExpandParameterPacks can ever
8307 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008308 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008309 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8310 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008311 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008312 llvm::Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008313 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008314 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008315 ShouldExpand, RetainExpansion,
8316 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008317 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008318
Douglas Gregor089e8932011-10-10 18:59:29 +00008319 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008320 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008321
Douglas Gregor089e8932011-10-10 18:59:29 +00008322 NamedDecl *Pack = E->getPack();
8323 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008324 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008325 Pack));
8326 if (!Pack)
8327 return ExprError();
8328 }
8329
Chad Rosier4a9d7952012-08-08 18:46:20 +00008330
Douglas Gregoree8aff02011-01-04 17:33:58 +00008331 // We now know the length of the parameter pack, so build a new expression
8332 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008333 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8334 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008335 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008336}
8337
Douglas Gregorbe230c32011-01-03 17:17:50 +00008338template<typename Derived>
8339ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008340TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8341 SubstNonTypeTemplateParmPackExpr *E) {
8342 // Default behavior is to do nothing with this transformation.
8343 return SemaRef.Owned(E);
8344}
8345
8346template<typename Derived>
8347ExprResult
John McCall91a57552011-07-15 05:09:51 +00008348TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8349 SubstNonTypeTemplateParmExpr *E) {
8350 // Default behavior is to do nothing with this transformation.
8351 return SemaRef.Owned(E);
8352}
8353
8354template<typename Derived>
8355ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008356TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8357 MaterializeTemporaryExpr *E) {
8358 return getDerived().TransformExpr(E->GetTemporaryExpr());
8359}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008360
Douglas Gregor03e80032011-06-21 17:03:29 +00008361template<typename Derived>
8362ExprResult
John McCall454feb92009-12-08 09:21:05 +00008363TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008364 return SemaRef.MaybeBindToTemporary(E);
8365}
8366
8367template<typename Derived>
8368ExprResult
8369TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008370 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008371}
8372
8373template<typename Derived>
8374ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008375TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8376 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8377 if (SubExpr.isInvalid())
8378 return ExprError();
8379
8380 if (!getDerived().AlwaysRebuild() &&
8381 SubExpr.get() == E->getSubExpr())
8382 return SemaRef.Owned(E);
8383
8384 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008385}
8386
8387template<typename Derived>
8388ExprResult
8389TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8390 // Transform each of the elements.
8391 llvm::SmallVector<Expr *, 8> Elements;
8392 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008393 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008394 /*IsCall=*/false, Elements, &ArgChanged))
8395 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008396
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008397 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8398 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008399
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008400 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8401 Elements.data(),
8402 Elements.size());
8403}
8404
8405template<typename Derived>
8406ExprResult
8407TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008408 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008409 // Transform each of the elements.
8410 llvm::SmallVector<ObjCDictionaryElement, 8> Elements;
8411 bool ArgChanged = false;
8412 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8413 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008414
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008415 if (OrigElement.isPackExpansion()) {
8416 // This key/value element is a pack expansion.
8417 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8418 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8419 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8420 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8421
8422 // Determine whether the set of unexpanded parameter packs can
8423 // and should be expanded.
8424 bool Expand = true;
8425 bool RetainExpansion = false;
8426 llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8427 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
8428 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8429 OrigElement.Value->getLocEnd());
8430 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8431 PatternRange,
8432 Unexpanded,
8433 Expand, RetainExpansion,
8434 NumExpansions))
8435 return ExprError();
8436
8437 if (!Expand) {
8438 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008439 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008440 // expansion.
8441 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8442 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8443 if (Key.isInvalid())
8444 return ExprError();
8445
8446 if (Key.get() != OrigElement.Key)
8447 ArgChanged = true;
8448
8449 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8450 if (Value.isInvalid())
8451 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008452
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008453 if (Value.get() != OrigElement.Value)
8454 ArgChanged = true;
8455
Chad Rosier4a9d7952012-08-08 18:46:20 +00008456 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008457 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8458 };
8459 Elements.push_back(Expansion);
8460 continue;
8461 }
8462
8463 // Record right away that the argument was changed. This needs
8464 // to happen even if the array expands to nothing.
8465 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008466
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008467 // The transform has determined that we should perform an elementwise
8468 // expansion of the pattern. Do so.
8469 for (unsigned I = 0; I != *NumExpansions; ++I) {
8470 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8471 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8472 if (Key.isInvalid())
8473 return ExprError();
8474
8475 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8476 if (Value.isInvalid())
8477 return ExprError();
8478
Chad Rosier4a9d7952012-08-08 18:46:20 +00008479 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008480 Key.get(), Value.get(), SourceLocation(), NumExpansions
8481 };
8482
8483 // If any unexpanded parameter packs remain, we still have a
8484 // pack expansion.
8485 if (Key.get()->containsUnexpandedParameterPack() ||
8486 Value.get()->containsUnexpandedParameterPack())
8487 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008488
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008489 Elements.push_back(Element);
8490 }
8491
8492 // We've finished with this pack expansion.
8493 continue;
8494 }
8495
8496 // Transform and check key.
8497 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8498 if (Key.isInvalid())
8499 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008500
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008501 if (Key.get() != OrigElement.Key)
8502 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008503
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008504 // Transform and check value.
8505 ExprResult Value
8506 = getDerived().TransformExpr(OrigElement.Value);
8507 if (Value.isInvalid())
8508 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008509
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008510 if (Value.get() != OrigElement.Value)
8511 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008512
8513 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008514 Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8515 };
8516 Elements.push_back(Element);
8517 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008518
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008519 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8520 return SemaRef.MaybeBindToTemporary(E);
8521
8522 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8523 Elements.data(),
8524 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008525}
8526
Mike Stump1eb44332009-09-09 15:08:12 +00008527template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008528ExprResult
John McCall454feb92009-12-08 09:21:05 +00008529TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008530 TypeSourceInfo *EncodedTypeInfo
8531 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8532 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008533 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008534
Douglas Gregorb98b1992009-08-11 05:31:07 +00008535 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008536 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008537 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008538
8539 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008540 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008541 E->getRParenLoc());
8542}
Mike Stump1eb44332009-09-09 15:08:12 +00008543
Douglas Gregorb98b1992009-08-11 05:31:07 +00008544template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008545ExprResult TreeTransform<Derived>::
8546TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8547 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8548 if (result.isInvalid()) return ExprError();
8549 Expr *subExpr = result.take();
8550
8551 if (!getDerived().AlwaysRebuild() &&
8552 subExpr == E->getSubExpr())
8553 return SemaRef.Owned(E);
8554
8555 return SemaRef.Owned(new(SemaRef.Context)
8556 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8557}
8558
8559template<typename Derived>
8560ExprResult TreeTransform<Derived>::
8561TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008562 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008563 = getDerived().TransformType(E->getTypeInfoAsWritten());
8564 if (!TSInfo)
8565 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008566
John McCallf85e1932011-06-15 23:02:42 +00008567 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008568 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008569 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008570
John McCallf85e1932011-06-15 23:02:42 +00008571 if (!getDerived().AlwaysRebuild() &&
8572 TSInfo == E->getTypeInfoAsWritten() &&
8573 Result.get() == E->getSubExpr())
8574 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008575
John McCallf85e1932011-06-15 23:02:42 +00008576 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008577 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008578 Result.get());
8579}
8580
8581template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008582ExprResult
John McCall454feb92009-12-08 09:21:05 +00008583TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008584 // Transform arguments.
8585 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008586 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008587 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008588 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008589 &ArgChanged))
8590 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008591
Douglas Gregor92e986e2010-04-22 16:44:27 +00008592 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8593 // Class message: transform the receiver type.
8594 TypeSourceInfo *ReceiverTypeInfo
8595 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8596 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008597 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008598
Douglas Gregor92e986e2010-04-22 16:44:27 +00008599 // If nothing changed, just retain the existing message send.
8600 if (!getDerived().AlwaysRebuild() &&
8601 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008602 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008603
8604 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008605 SmallVector<SourceLocation, 16> SelLocs;
8606 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008607 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8608 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008609 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008610 E->getMethodDecl(),
8611 E->getLeftLoc(),
8612 move_arg(Args),
8613 E->getRightLoc());
8614 }
8615
8616 // Instance message: transform the receiver
8617 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8618 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008619 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008620 = getDerived().TransformExpr(E->getInstanceReceiver());
8621 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008622 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008623
8624 // If nothing changed, just retain the existing message send.
8625 if (!getDerived().AlwaysRebuild() &&
8626 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008627 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008628
Douglas Gregor92e986e2010-04-22 16:44:27 +00008629 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008630 SmallVector<SourceLocation, 16> SelLocs;
8631 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008632 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008633 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008634 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008635 E->getMethodDecl(),
8636 E->getLeftLoc(),
8637 move_arg(Args),
8638 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008639}
8640
Mike Stump1eb44332009-09-09 15:08:12 +00008641template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008642ExprResult
John McCall454feb92009-12-08 09:21:05 +00008643TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008644 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008645}
8646
Mike Stump1eb44332009-09-09 15:08:12 +00008647template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008648ExprResult
John McCall454feb92009-12-08 09:21:05 +00008649TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008650 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008651}
8652
Mike Stump1eb44332009-09-09 15:08:12 +00008653template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008654ExprResult
John McCall454feb92009-12-08 09:21:05 +00008655TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008656 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008657 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008658 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008659 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008660
8661 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008662
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008663 // If nothing changed, just retain the existing expression.
8664 if (!getDerived().AlwaysRebuild() &&
8665 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008666 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008667
John McCall9ae2f072010-08-23 23:25:46 +00008668 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008669 E->getLocation(),
8670 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008671}
8672
Mike Stump1eb44332009-09-09 15:08:12 +00008673template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008674ExprResult
John McCall454feb92009-12-08 09:21:05 +00008675TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008676 // 'super' and types never change. Property never changes. Just
8677 // retain the existing expression.
8678 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008679 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008680
Douglas Gregore3303542010-04-26 20:47:02 +00008681 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008682 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008683 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008684 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008685
Douglas Gregore3303542010-04-26 20:47:02 +00008686 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008687
Douglas Gregore3303542010-04-26 20:47:02 +00008688 // If nothing changed, just retain the existing expression.
8689 if (!getDerived().AlwaysRebuild() &&
8690 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008691 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008692
John McCall12f78a62010-12-02 01:19:52 +00008693 if (E->isExplicitProperty())
8694 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8695 E->getExplicitProperty(),
8696 E->getLocation());
8697
8698 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008699 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008700 E->getImplicitPropertyGetter(),
8701 E->getImplicitPropertySetter(),
8702 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008703}
8704
Mike Stump1eb44332009-09-09 15:08:12 +00008705template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008706ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008707TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8708 // Transform the base expression.
8709 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8710 if (Base.isInvalid())
8711 return ExprError();
8712
8713 // Transform the key expression.
8714 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8715 if (Key.isInvalid())
8716 return ExprError();
8717
8718 // If nothing changed, just retain the existing expression.
8719 if (!getDerived().AlwaysRebuild() &&
8720 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8721 return SemaRef.Owned(E);
8722
Chad Rosier4a9d7952012-08-08 18:46:20 +00008723 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008724 Base.get(), Key.get(),
8725 E->getAtIndexMethodDecl(),
8726 E->setAtIndexMethodDecl());
8727}
8728
8729template<typename Derived>
8730ExprResult
John McCall454feb92009-12-08 09:21:05 +00008731TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008732 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008733 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008734 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008735 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008736
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008737 // If nothing changed, just retain the existing expression.
8738 if (!getDerived().AlwaysRebuild() &&
8739 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008740 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008741
John McCall9ae2f072010-08-23 23:25:46 +00008742 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008743 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008744}
8745
Mike Stump1eb44332009-09-09 15:08:12 +00008746template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008747ExprResult
John McCall454feb92009-12-08 09:21:05 +00008748TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008749 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008750 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008751 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008752 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008753 SubExprs, &ArgumentChanged))
8754 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008755
Douglas Gregorb98b1992009-08-11 05:31:07 +00008756 if (!getDerived().AlwaysRebuild() &&
8757 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008758 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008759
Douglas Gregorb98b1992009-08-11 05:31:07 +00008760 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8761 move_arg(SubExprs),
8762 E->getRParenLoc());
8763}
8764
Mike Stump1eb44332009-09-09 15:08:12 +00008765template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008766ExprResult
John McCall454feb92009-12-08 09:21:05 +00008767TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008768 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008769
John McCallc6ac9c32011-02-04 18:33:18 +00008770 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8771 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8772
8773 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008774 blockScope->TheDecl->setBlockMissingReturnType(
8775 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008776
Chris Lattner686775d2011-07-20 06:58:45 +00008777 SmallVector<ParmVarDecl*, 4> params;
8778 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008779
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008780 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008781 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8782 oldBlock->param_begin(),
8783 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008784 0, paramTypes, &params)) {
8785 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008786 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008787 }
John McCallc6ac9c32011-02-04 18:33:18 +00008788
8789 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008790 QualType exprResultType =
8791 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008792
8793 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008794 if (exprResultType->isObjCObjectType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008795 getSema().Diag(E->getCaretLocation(),
8796 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008797 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008798 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008799 return ExprError();
8800 }
John McCall711c52b2011-01-05 12:14:39 +00008801
John McCallc6ac9c32011-02-04 18:33:18 +00008802 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008803 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008804 paramTypes.data(),
8805 paramTypes.size(),
8806 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008807 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008808 exprFunctionType->getExtInfo());
8809 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008810
8811 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008812 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008813 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008814
8815 if (!oldBlock->blockMissingReturnType()) {
8816 blockScope->HasImplicitReturnType = false;
8817 blockScope->ReturnType = exprResultType;
8818 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008819
John McCall711c52b2011-01-05 12:14:39 +00008820 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008821 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008822 if (body.isInvalid()) {
8823 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008824 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008825 }
John McCall711c52b2011-01-05 12:14:39 +00008826
John McCallc6ac9c32011-02-04 18:33:18 +00008827#ifndef NDEBUG
8828 // In builds with assertions, make sure that we captured everything we
8829 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008830 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8831 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8832 e = oldBlock->capture_end(); i != e; ++i) {
8833 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008834
Douglas Gregorfc921372011-05-20 15:32:55 +00008835 // Ignore parameter packs.
8836 if (isa<ParmVarDecl>(oldCapture) &&
8837 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8838 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008839
Douglas Gregorfc921372011-05-20 15:32:55 +00008840 VarDecl *newCapture =
8841 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8842 oldCapture));
8843 assert(blockScope->CaptureMap.count(newCapture));
8844 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008845 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008846 }
8847#endif
8848
8849 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8850 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008851}
8852
Mike Stump1eb44332009-09-09 15:08:12 +00008853template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008854ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008855TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008856 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008857}
Eli Friedman276b0612011-10-11 02:20:01 +00008858
8859template<typename Derived>
8860ExprResult
8861TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008862 QualType RetTy = getDerived().TransformType(E->getType());
8863 bool ArgumentChanged = false;
8864 ASTOwningVector<Expr*> SubExprs(SemaRef);
8865 SubExprs.reserve(E->getNumSubExprs());
8866 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8867 SubExprs, &ArgumentChanged))
8868 return ExprError();
8869
8870 if (!getDerived().AlwaysRebuild() &&
8871 !ArgumentChanged)
8872 return SemaRef.Owned(E);
8873
8874 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8875 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008876}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008877
Douglas Gregorb98b1992009-08-11 05:31:07 +00008878//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008879// Type reconstruction
8880//===----------------------------------------------------------------------===//
8881
Mike Stump1eb44332009-09-09 15:08:12 +00008882template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008883QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8884 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008885 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008886 getDerived().getBaseEntity());
8887}
8888
Mike Stump1eb44332009-09-09 15:08:12 +00008889template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008890QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8891 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008892 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008893 getDerived().getBaseEntity());
8894}
8895
Mike Stump1eb44332009-09-09 15:08:12 +00008896template<typename Derived>
8897QualType
John McCall85737a72009-10-30 00:06:24 +00008898TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8899 bool WrittenAsLValue,
8900 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008901 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008902 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008903}
8904
8905template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008906QualType
John McCall85737a72009-10-30 00:06:24 +00008907TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8908 QualType ClassType,
8909 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008910 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008911 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008912}
8913
8914template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008915QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008916TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8917 ArrayType::ArraySizeModifier SizeMod,
8918 const llvm::APInt *Size,
8919 Expr *SizeExpr,
8920 unsigned IndexTypeQuals,
8921 SourceRange BracketsRange) {
8922 if (SizeExpr || !Size)
8923 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8924 IndexTypeQuals, BracketsRange,
8925 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008926
8927 QualType Types[] = {
8928 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8929 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8930 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008931 };
8932 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8933 QualType SizeType;
8934 for (unsigned I = 0; I != NumTypes; ++I)
8935 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8936 SizeType = Types[I];
8937 break;
8938 }
Mike Stump1eb44332009-09-09 15:08:12 +00008939
Eli Friedman01f276d2012-01-25 23:20:27 +00008940 // Note that we can return a VariableArrayType here in the case where
8941 // the element type was a dependent VariableArrayType.
8942 IntegerLiteral *ArraySize
8943 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8944 /*FIXME*/BracketsRange.getBegin());
8945 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008946 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008947 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008948}
Mike Stump1eb44332009-09-09 15:08:12 +00008949
Douglas Gregor577f75a2009-08-04 16:50:30 +00008950template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008951QualType
8952TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008953 ArrayType::ArraySizeModifier SizeMod,
8954 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008955 unsigned IndexTypeQuals,
8956 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008957 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008958 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008959}
8960
8961template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008962QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008963TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008964 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008965 unsigned IndexTypeQuals,
8966 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008967 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008968 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008969}
Mike Stump1eb44332009-09-09 15:08:12 +00008970
Douglas Gregor577f75a2009-08-04 16:50:30 +00008971template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008972QualType
8973TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008974 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008975 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008976 unsigned IndexTypeQuals,
8977 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008978 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008979 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008980 IndexTypeQuals, BracketsRange);
8981}
8982
8983template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008984QualType
8985TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008986 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008987 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008988 unsigned IndexTypeQuals,
8989 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008990 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008991 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008992 IndexTypeQuals, BracketsRange);
8993}
8994
8995template<typename Derived>
8996QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008997 unsigned NumElements,
8998 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008999 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009000 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009001}
Mike Stump1eb44332009-09-09 15:08:12 +00009002
Douglas Gregor577f75a2009-08-04 16:50:30 +00009003template<typename Derived>
9004QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9005 unsigned NumElements,
9006 SourceLocation AttributeLoc) {
9007 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9008 NumElements, true);
9009 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009010 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9011 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009012 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
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>
Mike Stump1eb44332009-09-09 15:08:12 +00009016QualType
9017TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009018 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009019 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009020 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009021}
Mike Stump1eb44332009-09-09 15:08:12 +00009022
Douglas Gregor577f75a2009-08-04 16:50:30 +00009023template<typename Derived>
9024QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00009025 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009026 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00009027 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009028 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00009029 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00009030 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00009031 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00009032 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009033 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009034 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009035 getDerived().getBaseEntity(),
9036 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009037}
Mike Stump1eb44332009-09-09 15:08:12 +00009038
Douglas Gregor577f75a2009-08-04 16:50:30 +00009039template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009040QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9041 return SemaRef.Context.getFunctionNoProtoType(T);
9042}
9043
9044template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009045QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9046 assert(D && "no decl found");
9047 if (D->isInvalidDecl()) return QualType();
9048
Douglas Gregor92e986e2010-04-22 16:44:27 +00009049 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009050 TypeDecl *Ty;
9051 if (isa<UsingDecl>(D)) {
9052 UsingDecl *Using = cast<UsingDecl>(D);
9053 assert(Using->isTypeName() &&
9054 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9055
9056 // A valid resolved using typename decl points to exactly one type decl.
9057 assert(++Using->shadow_begin() == Using->shadow_end());
9058 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009059
John McCalled976492009-12-04 22:46:56 +00009060 } else {
9061 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9062 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9063 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9064 }
9065
9066 return SemaRef.Context.getTypeDeclType(Ty);
9067}
9068
9069template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009070QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9071 SourceLocation Loc) {
9072 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009073}
9074
9075template<typename Derived>
9076QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9077 return SemaRef.Context.getTypeOfType(Underlying);
9078}
9079
9080template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009081QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9082 SourceLocation Loc) {
9083 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009084}
9085
9086template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009087QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9088 UnaryTransformType::UTTKind UKind,
9089 SourceLocation Loc) {
9090 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9091}
9092
9093template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009094QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009095 TemplateName Template,
9096 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009097 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009098 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009099}
Mike Stump1eb44332009-09-09 15:08:12 +00009100
Douglas Gregordcee1a12009-08-06 05:28:30 +00009101template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009102QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9103 SourceLocation KWLoc) {
9104 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9105}
9106
9107template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009108TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009109TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009110 bool TemplateKW,
9111 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009112 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009113 Template);
9114}
9115
9116template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009117TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009118TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9119 const IdentifierInfo &Name,
9120 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009121 QualType ObjectType,
9122 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009123 UnqualifiedId TemplateName;
9124 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009125 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009126 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009127 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009128 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009129 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009130 /*EnteringContext=*/false,
9131 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009132 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009133}
Mike Stump1eb44332009-09-09 15:08:12 +00009134
Douglas Gregorb98b1992009-08-11 05:31:07 +00009135template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009136TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009137TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009138 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009139 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009140 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009141 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009142 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009143 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009144 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009145 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009146 Sema::TemplateTy Template;
9147 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009148 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009149 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009150 /*EnteringContext=*/false,
9151 Template);
9152 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009153}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009154
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009155template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009156ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009157TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9158 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009159 Expr *OrigCallee,
9160 Expr *First,
9161 Expr *Second) {
9162 Expr *Callee = OrigCallee->IgnoreParenCasts();
9163 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009164
Douglas Gregorb98b1992009-08-11 05:31:07 +00009165 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009166 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009167 if (!First->getType()->isOverloadableType() &&
9168 !Second->getType()->isOverloadableType())
9169 return getSema().CreateBuiltinArraySubscriptExpr(First,
9170 Callee->getLocStart(),
9171 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009172 } else if (Op == OO_Arrow) {
9173 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009174 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9175 } else if (Second == 0 || isPostIncDec) {
9176 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009177 // The argument is not of overloadable type, so try to create a
9178 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009179 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009180 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009181
John McCall9ae2f072010-08-23 23:25:46 +00009182 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009183 }
9184 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009185 if (!First->getType()->isOverloadableType() &&
9186 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009187 // Neither of the arguments is an overloadable type, so try to
9188 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009189 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009190 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009191 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009192 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009193 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009194
Douglas Gregorb98b1992009-08-11 05:31:07 +00009195 return move(Result);
9196 }
9197 }
Mike Stump1eb44332009-09-09 15:08:12 +00009198
9199 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009200 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009201 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009202
John McCall9ae2f072010-08-23 23:25:46 +00009203 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009204 assert(ULE->requiresADL());
9205
9206 // FIXME: Do we have to check
9207 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009208 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009209 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009210 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00009211 }
Mike Stump1eb44332009-09-09 15:08:12 +00009212
Douglas Gregorb98b1992009-08-11 05:31:07 +00009213 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009214 Expr *Args[2] = { First, Second };
9215 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009216
Douglas Gregorb98b1992009-08-11 05:31:07 +00009217 // Create the overloaded operator invocation for unary operators.
9218 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009219 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009220 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009221 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009222 }
Mike Stump1eb44332009-09-09 15:08:12 +00009223
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009224 if (Op == OO_Subscript) {
9225 SourceLocation LBrace;
9226 SourceLocation RBrace;
9227
9228 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9229 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9230 LBrace = SourceLocation::getFromRawEncoding(
9231 NameLoc.CXXOperatorName.BeginOpNameLoc);
9232 RBrace = SourceLocation::getFromRawEncoding(
9233 NameLoc.CXXOperatorName.EndOpNameLoc);
9234 } else {
9235 LBrace = Callee->getLocStart();
9236 RBrace = OpLoc;
9237 }
9238
9239 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9240 First, Second);
9241 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009242
Douglas Gregorb98b1992009-08-11 05:31:07 +00009243 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009244 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009245 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009246 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9247 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009248 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009249
Mike Stump1eb44332009-09-09 15:08:12 +00009250 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009251}
Mike Stump1eb44332009-09-09 15:08:12 +00009252
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009253template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009254ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009255TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009256 SourceLocation OperatorLoc,
9257 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009258 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009259 TypeSourceInfo *ScopeType,
9260 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009261 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009262 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009263 QualType BaseType = Base->getType();
9264 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009265 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009266 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009267 !BaseType->getAs<PointerType>()->getPointeeType()
9268 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009269 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009270 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009271 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009272 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009273 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009274 /*FIXME?*/true);
9275 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009276
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009277 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009278 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9279 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9280 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9281 NameInfo.setNamedTypeInfo(DestroyedType);
9282
Richard Smith6314db92012-05-15 06:15:11 +00009283 // The scope type is now known to be a valid nested name specifier
9284 // component. Tack it on to the end of the nested name specifier.
9285 if (ScopeType)
9286 SS.Extend(SemaRef.Context, SourceLocation(),
9287 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009288
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009289 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009290 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009291 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009292 SS, TemplateKWLoc,
9293 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009294 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009295 /*TemplateArgs*/ 0);
9296}
9297
Douglas Gregor577f75a2009-08-04 16:50:30 +00009298} // end namespace clang
9299
9300#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H