blob: 0516768ac499210c4f4aa363dd7bba9159195655 [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 Rosier8cd64b42012-06-11 20:47:18 +00001189 SourceLocation EndLoc) {
Chad Rosier92570bd2012-08-14 23:14:45 +00001190 return getSema().ActOnMSAsmStmt(AsmLoc, AsmToks, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001191 }
1192
James Dennett699c9042012-06-15 07:13:21 +00001193 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001194 ///
1195 /// By default, performs semantic analysis to build the new statement.
1196 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001197 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001198 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001199 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001200 Stmt *Finally) {
1201 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1202 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001203 }
1204
Douglas Gregorbe270a02010-04-26 17:57:08 +00001205 /// \brief Rebuild an Objective-C exception declaration.
1206 ///
1207 /// By default, performs semantic analysis to build the new declaration.
1208 /// Subclasses may override this routine to provide different behavior.
1209 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1210 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001211 return getSema().BuildObjCExceptionDecl(TInfo, T,
1212 ExceptionDecl->getInnerLocStart(),
1213 ExceptionDecl->getLocation(),
1214 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001215 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001216
James Dennett699c9042012-06-15 07:13:21 +00001217 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001218 ///
1219 /// By default, performs semantic analysis to build the new statement.
1220 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001221 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001222 SourceLocation RParenLoc,
1223 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001224 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001225 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001226 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001227 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001228
James Dennett699c9042012-06-15 07:13:21 +00001229 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001230 ///
1231 /// By default, performs semantic analysis to build the new statement.
1232 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001233 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001234 Stmt *Body) {
1235 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001236 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001237
James Dennett699c9042012-06-15 07:13:21 +00001238 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001239 ///
1240 /// By default, performs semantic analysis to build the new statement.
1241 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001242 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001243 Expr *Operand) {
1244 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001245 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001246
James Dennett699c9042012-06-15 07:13:21 +00001247 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001248 ///
1249 /// By default, performs semantic analysis to build the new statement.
1250 /// Subclasses may override this routine to provide different behavior.
1251 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1252 Expr *object) {
1253 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1254 }
1255
James Dennett699c9042012-06-15 07:13:21 +00001256 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001257 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001258 /// By default, performs semantic analysis to build the new statement.
1259 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001260 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001261 Expr *Object, Stmt *Body) {
1262 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001263 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001264
James Dennett699c9042012-06-15 07:13:21 +00001265 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001266 ///
1267 /// By default, performs semantic analysis to build the new statement.
1268 /// Subclasses may override this routine to provide different behavior.
1269 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1270 Stmt *Body) {
1271 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1272 }
John McCall990567c2011-07-27 01:07:15 +00001273
Douglas Gregorc3203e72010-04-22 23:10:45 +00001274 /// \brief Build a new Objective-C fast enumeration statement.
1275 ///
1276 /// By default, performs semantic analysis to build the new statement.
1277 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001278 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001279 SourceLocation LParenLoc,
1280 Stmt *Element,
1281 Expr *Collection,
1282 SourceLocation RParenLoc,
1283 Stmt *Body) {
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001284 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
1285 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001286 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001287 RParenLoc);
1288 if (ForEachStmt.isInvalid())
1289 return StmtError();
1290
1291 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001292 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001293
Douglas Gregor43959a92009-08-20 07:17:43 +00001294 /// \brief Build a new C++ exception declaration.
1295 ///
1296 /// By default, performs semantic analysis to build the new decaration.
1297 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001298 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001299 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001300 SourceLocation StartLoc,
1301 SourceLocation IdLoc,
1302 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001303 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1304 StartLoc, IdLoc, Id);
1305 if (Var)
1306 getSema().CurContext->addDecl(Var);
1307 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001308 }
1309
1310 /// \brief Build a new C++ catch statement.
1311 ///
1312 /// By default, performs semantic analysis to build the new statement.
1313 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001314 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001315 VarDecl *ExceptionDecl,
1316 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001317 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1318 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001319 }
Mike Stump1eb44332009-09-09 15:08:12 +00001320
Douglas Gregor43959a92009-08-20 07:17:43 +00001321 /// \brief Build a new C++ try statement.
1322 ///
1323 /// By default, performs semantic analysis to build the new statement.
1324 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001325 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001326 Stmt *TryBlock,
1327 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001328 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001329 }
Mike Stump1eb44332009-09-09 15:08:12 +00001330
Richard Smithad762fc2011-04-14 22:09:26 +00001331 /// \brief Build a new C++0x range-based for statement.
1332 ///
1333 /// By default, performs semantic analysis to build the new statement.
1334 /// Subclasses may override this routine to provide different behavior.
1335 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1336 SourceLocation ColonLoc,
1337 Stmt *Range, Stmt *BeginEnd,
1338 Expr *Cond, Expr *Inc,
1339 Stmt *LoopVar,
1340 SourceLocation RParenLoc) {
1341 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1342 Cond, Inc, LoopVar, RParenLoc);
1343 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001344
1345 /// \brief Build a new C++0x range-based for statement.
1346 ///
1347 /// By default, performs semantic analysis to build the new statement.
1348 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001349 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001350 bool IsIfExists,
1351 NestedNameSpecifierLoc QualifierLoc,
1352 DeclarationNameInfo NameInfo,
1353 Stmt *Nested) {
1354 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1355 QualifierLoc, NameInfo, Nested);
1356 }
1357
Richard Smithad762fc2011-04-14 22:09:26 +00001358 /// \brief Attach body to a C++0x range-based for statement.
1359 ///
1360 /// By default, performs semantic analysis to finish the new statement.
1361 /// Subclasses may override this routine to provide different behavior.
1362 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1363 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1364 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001365
John Wiegley28bbe4b2011-04-28 01:08:34 +00001366 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1367 SourceLocation TryLoc,
1368 Stmt *TryBlock,
1369 Stmt *Handler) {
1370 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1371 }
1372
1373 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1374 Expr *FilterExpr,
1375 Stmt *Block) {
1376 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1377 }
1378
1379 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1380 Stmt *Block) {
1381 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1382 }
1383
Douglas Gregorb98b1992009-08-11 05:31:07 +00001384 /// \brief Build a new expression that references a declaration.
1385 ///
1386 /// By default, performs semantic analysis to build the new expression.
1387 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001388 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001389 LookupResult &R,
1390 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001391 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1392 }
1393
1394
1395 /// \brief Build a new expression that references a declaration.
1396 ///
1397 /// By default, performs semantic analysis to build the new expression.
1398 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001399 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001400 ValueDecl *VD,
1401 const DeclarationNameInfo &NameInfo,
1402 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001403 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001404 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001405
1406 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001407
1408 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001409 }
Mike Stump1eb44332009-09-09 15:08:12 +00001410
Douglas Gregorb98b1992009-08-11 05:31:07 +00001411 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001412 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001413 /// By default, performs semantic analysis to build the new expression.
1414 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001415 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001416 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001417 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001418 }
1419
Douglas Gregora71d8192009-09-04 17:36:40 +00001420 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001421 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001422 /// By default, performs semantic analysis to build the new expression.
1423 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001424 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001425 SourceLocation OperatorLoc,
1426 bool isArrow,
1427 CXXScopeSpec &SS,
1428 TypeSourceInfo *ScopeType,
1429 SourceLocation CCLoc,
1430 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001431 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001432
Douglas Gregorb98b1992009-08-11 05:31:07 +00001433 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001434 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001435 /// By default, performs semantic analysis to build the new expression.
1436 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001437 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001438 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001439 Expr *SubExpr) {
1440 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001441 }
Mike Stump1eb44332009-09-09 15:08:12 +00001442
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001443 /// \brief Build a new builtin offsetof expression.
1444 ///
1445 /// By default, performs semantic analysis to build the new expression.
1446 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001447 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001448 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001449 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001450 unsigned NumComponents,
1451 SourceLocation RParenLoc) {
1452 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1453 NumComponents, RParenLoc);
1454 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001455
1456 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001457 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001458 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001459 /// By default, performs semantic analysis to build the new expression.
1460 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001461 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1462 SourceLocation OpLoc,
1463 UnaryExprOrTypeTrait ExprKind,
1464 SourceRange R) {
1465 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001466 }
1467
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001468 /// \brief Build a new sizeof, alignof or vec step expression with an
1469 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001470 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001471 /// By default, performs semantic analysis to build the new expression.
1472 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001473 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1474 UnaryExprOrTypeTrait ExprKind,
1475 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001476 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001477 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001478 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001479 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001480
Douglas Gregorb98b1992009-08-11 05:31:07 +00001481 return move(Result);
1482 }
Mike Stump1eb44332009-09-09 15:08:12 +00001483
Douglas Gregorb98b1992009-08-11 05:31:07 +00001484 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001485 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001486 /// By default, performs semantic analysis to build the new expression.
1487 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001488 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001489 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001490 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001491 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001492 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1493 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001494 RBracketLoc);
1495 }
1496
1497 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001498 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001499 /// By default, performs semantic analysis to build the new expression.
1500 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001501 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001502 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001503 SourceLocation RParenLoc,
1504 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001505 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001506 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001507 }
1508
1509 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001510 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001511 /// By default, performs semantic analysis to build the new expression.
1512 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001513 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001514 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001515 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001516 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001517 const DeclarationNameInfo &MemberNameInfo,
1518 ValueDecl *Member,
1519 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001520 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001521 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001522 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1523 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001524 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001525 // We have a reference to an unnamed field. This is always the
1526 // base of an anonymous struct/union member access, i.e. the
1527 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001528 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001529 assert(Member->getType()->isRecordType() &&
1530 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001531
Richard Smith9138b4e2011-10-26 19:06:56 +00001532 BaseResult =
1533 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001534 QualifierLoc.getNestedNameSpecifier(),
1535 FoundDecl, Member);
1536 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001537 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001538 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001539 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001540 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001541 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001542 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001543 cast<FieldDecl>(Member)->getType(),
1544 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001545 return getSema().Owned(ME);
1546 }
Mike Stump1eb44332009-09-09 15:08:12 +00001547
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001548 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001549 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001550
John Wiegley429bb272011-04-08 18:41:53 +00001551 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001552 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001553
John McCall6bb80172010-03-30 21:47:33 +00001554 // FIXME: this involves duplicating earlier analysis in a lot of
1555 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001556 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001557 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001558 R.resolveKind();
1559
John McCall9ae2f072010-08-23 23:25:46 +00001560 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001561 SS, TemplateKWLoc,
1562 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001563 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001564 }
Mike Stump1eb44332009-09-09 15:08:12 +00001565
Douglas Gregorb98b1992009-08-11 05:31:07 +00001566 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001567 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001568 /// By default, performs semantic analysis to build the new expression.
1569 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001570 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001571 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001572 Expr *LHS, Expr *RHS) {
1573 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001574 }
1575
1576 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001577 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001578 /// By default, performs semantic analysis to build the new expression.
1579 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001580 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001581 SourceLocation QuestionLoc,
1582 Expr *LHS,
1583 SourceLocation ColonLoc,
1584 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001585 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1586 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001587 }
1588
Douglas Gregorb98b1992009-08-11 05:31:07 +00001589 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001590 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001591 /// By default, performs semantic analysis to build the new expression.
1592 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001593 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001594 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001595 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001596 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001597 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001598 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001599 }
Mike Stump1eb44332009-09-09 15:08:12 +00001600
Douglas Gregorb98b1992009-08-11 05:31:07 +00001601 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001602 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001603 /// By default, performs semantic analysis to build the new expression.
1604 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001605 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001606 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001607 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001608 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001609 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001610 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001611 }
Mike Stump1eb44332009-09-09 15:08:12 +00001612
Douglas Gregorb98b1992009-08-11 05:31:07 +00001613 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001614 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001615 /// By default, performs semantic analysis to build the new expression.
1616 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001617 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001618 SourceLocation OpLoc,
1619 SourceLocation AccessorLoc,
1620 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001621
John McCall129e2df2009-11-30 22:42:35 +00001622 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001623 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001624 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001625 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001626 SS, SourceLocation(),
1627 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001628 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001629 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001630 }
Mike Stump1eb44332009-09-09 15:08:12 +00001631
Douglas Gregorb98b1992009-08-11 05:31:07 +00001632 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001633 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001634 /// By default, performs semantic analysis to build the new expression.
1635 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001636 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001637 MultiExprArg Inits,
1638 SourceLocation RBraceLoc,
1639 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001640 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001641 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1642 if (Result.isInvalid() || ResultTy->isDependentType())
1643 return move(Result);
Chad Rosier4a9d7952012-08-08 18:46:20 +00001644
Douglas Gregore48319a2009-11-09 17:16:50 +00001645 // Patch in the result type we were given, which may have been computed
1646 // when the initial InitListExpr was built.
1647 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1648 ILE->setType(ResultTy);
1649 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001650 }
Mike Stump1eb44332009-09-09 15:08:12 +00001651
Douglas Gregorb98b1992009-08-11 05:31:07 +00001652 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001653 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001654 /// By default, performs semantic analysis to build the new expression.
1655 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001656 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001657 MultiExprArg ArrayExprs,
1658 SourceLocation EqualOrColonLoc,
1659 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001660 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001661 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001662 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001663 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001664 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001665 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001666
Douglas Gregorb98b1992009-08-11 05:31:07 +00001667 ArrayExprs.release();
1668 return move(Result);
1669 }
Mike Stump1eb44332009-09-09 15:08:12 +00001670
Douglas Gregorb98b1992009-08-11 05:31:07 +00001671 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001672 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001673 /// By default, builds the implicit value initialization without performing
1674 /// any semantic analysis. Subclasses may override this routine to provide
1675 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001676 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001677 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1678 }
Mike Stump1eb44332009-09-09 15:08:12 +00001679
Douglas Gregorb98b1992009-08-11 05:31:07 +00001680 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001681 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001682 /// By default, performs semantic analysis to build the new expression.
1683 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001684 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001685 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001686 SourceLocation RParenLoc) {
1687 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001688 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001689 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001690 }
1691
1692 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001693 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001694 /// By default, performs semantic analysis to build the new expression.
1695 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001696 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001697 MultiExprArg SubExprs,
1698 SourceLocation RParenLoc) {
1699 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001700 }
Mike Stump1eb44332009-09-09 15:08:12 +00001701
Douglas Gregorb98b1992009-08-11 05:31:07 +00001702 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001703 ///
1704 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001705 /// rather than attempting to map the label statement itself.
1706 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001707 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001708 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001709 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 }
Mike Stump1eb44332009-09-09 15:08:12 +00001711
Douglas Gregorb98b1992009-08-11 05:31:07 +00001712 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001713 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001714 /// By default, performs semantic analysis to build the new expression.
1715 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001716 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001717 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001719 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001720 }
Mike Stump1eb44332009-09-09 15:08:12 +00001721
Douglas Gregorb98b1992009-08-11 05:31:07 +00001722 /// \brief Build a new __builtin_choose_expr expression.
1723 ///
1724 /// By default, performs semantic analysis to build the new expression.
1725 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001726 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001727 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001728 SourceLocation RParenLoc) {
1729 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001730 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001731 RParenLoc);
1732 }
Mike Stump1eb44332009-09-09 15:08:12 +00001733
Peter Collingbournef111d932011-04-15 00:35:48 +00001734 /// \brief Build a new generic selection expression.
1735 ///
1736 /// By default, performs semantic analysis to build the new expression.
1737 /// Subclasses may override this routine to provide different behavior.
1738 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1739 SourceLocation DefaultLoc,
1740 SourceLocation RParenLoc,
1741 Expr *ControllingExpr,
1742 TypeSourceInfo **Types,
1743 Expr **Exprs,
1744 unsigned NumAssocs) {
1745 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1746 ControllingExpr, Types, Exprs,
1747 NumAssocs);
1748 }
1749
Douglas Gregorb98b1992009-08-11 05:31:07 +00001750 /// \brief Build a new overloaded operator call expression.
1751 ///
1752 /// By default, performs semantic analysis to build the new expression.
1753 /// The semantic analysis provides the behavior of template instantiation,
1754 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001755 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001756 /// argument-dependent lookup, etc. Subclasses may override this routine to
1757 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001758 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001759 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001760 Expr *Callee,
1761 Expr *First,
1762 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001763
1764 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001765 /// reinterpret_cast.
1766 ///
1767 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001768 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001769 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001770 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001771 Stmt::StmtClass Class,
1772 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001773 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001774 SourceLocation RAngleLoc,
1775 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001776 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001777 SourceLocation RParenLoc) {
1778 switch (Class) {
1779 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001780 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001781 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001782 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001783
1784 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001785 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001786 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001787 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001788
Douglas Gregorb98b1992009-08-11 05:31:07 +00001789 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001790 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001791 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001792 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001793 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001794
Douglas Gregorb98b1992009-08-11 05:31:07 +00001795 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001796 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001797 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001798 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001799
Douglas Gregorb98b1992009-08-11 05:31:07 +00001800 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001801 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001802 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001803 }
Mike Stump1eb44332009-09-09 15:08:12 +00001804
Douglas Gregorb98b1992009-08-11 05:31:07 +00001805 /// \brief Build a new C++ static_cast expression.
1806 ///
1807 /// By default, performs semantic analysis to build the new expression.
1808 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001809 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001810 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001811 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001812 SourceLocation RAngleLoc,
1813 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001814 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001815 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001816 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001817 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001818 SourceRange(LAngleLoc, RAngleLoc),
1819 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001820 }
1821
1822 /// \brief Build a new C++ dynamic_cast expression.
1823 ///
1824 /// By default, performs semantic analysis to build the new expression.
1825 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001826 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001827 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001828 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001829 SourceLocation RAngleLoc,
1830 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001831 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001832 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001833 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001834 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001835 SourceRange(LAngleLoc, RAngleLoc),
1836 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001837 }
1838
1839 /// \brief Build a new C++ reinterpret_cast expression.
1840 ///
1841 /// By default, performs semantic analysis to build the new expression.
1842 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001843 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001844 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001845 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001846 SourceLocation RAngleLoc,
1847 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001848 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001849 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001850 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001851 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001852 SourceRange(LAngleLoc, RAngleLoc),
1853 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001854 }
1855
1856 /// \brief Build a new C++ const_cast expression.
1857 ///
1858 /// By default, performs semantic analysis to build the new expression.
1859 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001860 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001861 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001862 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001863 SourceLocation RAngleLoc,
1864 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001865 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001866 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001867 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001868 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001869 SourceRange(LAngleLoc, RAngleLoc),
1870 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001871 }
Mike Stump1eb44332009-09-09 15:08:12 +00001872
Douglas Gregorb98b1992009-08-11 05:31:07 +00001873 /// \brief Build a new C++ functional-style cast expression.
1874 ///
1875 /// By default, performs semantic analysis to build the new expression.
1876 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001877 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1878 SourceLocation LParenLoc,
1879 Expr *Sub,
1880 SourceLocation RParenLoc) {
1881 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001882 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001883 RParenLoc);
1884 }
Mike Stump1eb44332009-09-09 15:08:12 +00001885
Douglas Gregorb98b1992009-08-11 05:31:07 +00001886 /// \brief Build a new C++ typeid(type) expression.
1887 ///
1888 /// By default, performs semantic analysis to build the new expression.
1889 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001890 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001891 SourceLocation TypeidLoc,
1892 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001893 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001894 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001895 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001896 }
Mike Stump1eb44332009-09-09 15:08:12 +00001897
Francois Pichet01b7c302010-09-08 12:20:18 +00001898
Douglas Gregorb98b1992009-08-11 05:31:07 +00001899 /// \brief Build a new C++ typeid(expr) expression.
1900 ///
1901 /// By default, performs semantic analysis to build the new expression.
1902 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001903 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001904 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001905 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001906 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001907 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001908 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001909 }
1910
Francois Pichet01b7c302010-09-08 12:20:18 +00001911 /// \brief Build a new C++ __uuidof(type) expression.
1912 ///
1913 /// By default, performs semantic analysis to build the new expression.
1914 /// Subclasses may override this routine to provide different behavior.
1915 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1916 SourceLocation TypeidLoc,
1917 TypeSourceInfo *Operand,
1918 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001919 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00001920 RParenLoc);
1921 }
1922
1923 /// \brief Build a new C++ __uuidof(expr) expression.
1924 ///
1925 /// By default, performs semantic analysis to build the new expression.
1926 /// Subclasses may override this routine to provide different behavior.
1927 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1928 SourceLocation TypeidLoc,
1929 Expr *Operand,
1930 SourceLocation RParenLoc) {
1931 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1932 RParenLoc);
1933 }
1934
Douglas Gregorb98b1992009-08-11 05:31:07 +00001935 /// \brief Build a new C++ "this" expression.
1936 ///
1937 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001938 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001939 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001940 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001941 QualType ThisType,
1942 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001943 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001944 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001945 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1946 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001947 }
1948
1949 /// \brief Build a new C++ throw expression.
1950 ///
1951 /// By default, performs semantic analysis to build the new expression.
1952 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001953 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1954 bool IsThrownVariableInScope) {
1955 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001956 }
1957
1958 /// \brief Build a new C++ default-argument expression.
1959 ///
1960 /// By default, builds a new default-argument expression, which does not
1961 /// require any semantic analysis. Subclasses may override this routine to
1962 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001963 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001964 ParmVarDecl *Param) {
1965 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1966 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001967 }
1968
1969 /// \brief Build a new C++ zero-initialization expression.
1970 ///
1971 /// By default, performs semantic analysis to build the new expression.
1972 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001973 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1974 SourceLocation LParenLoc,
1975 SourceLocation RParenLoc) {
1976 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001977 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001978 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001979 }
Mike Stump1eb44332009-09-09 15:08:12 +00001980
Douglas Gregorb98b1992009-08-11 05:31:07 +00001981 /// \brief Build a new C++ "new" expression.
1982 ///
1983 /// By default, performs semantic analysis to build the new expression.
1984 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001985 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001986 bool UseGlobal,
1987 SourceLocation PlacementLParen,
1988 MultiExprArg PlacementArgs,
1989 SourceLocation PlacementRParen,
1990 SourceRange TypeIdParens,
1991 QualType AllocatedType,
1992 TypeSourceInfo *AllocatedTypeInfo,
1993 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001994 SourceRange DirectInitRange,
1995 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00001996 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001997 PlacementLParen,
1998 move(PlacementArgs),
1999 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002000 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002001 AllocatedType,
2002 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002003 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002004 DirectInitRange,
2005 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002006 }
Mike Stump1eb44332009-09-09 15:08:12 +00002007
Douglas Gregorb98b1992009-08-11 05:31:07 +00002008 /// \brief Build a new C++ "delete" expression.
2009 ///
2010 /// By default, performs semantic analysis to build the new expression.
2011 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002012 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002013 bool IsGlobalDelete,
2014 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002015 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002016 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002017 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002018 }
Mike Stump1eb44332009-09-09 15:08:12 +00002019
Douglas Gregorb98b1992009-08-11 05:31:07 +00002020 /// \brief Build a new unary type trait expression.
2021 ///
2022 /// By default, performs semantic analysis to build the new expression.
2023 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002024 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002025 SourceLocation StartLoc,
2026 TypeSourceInfo *T,
2027 SourceLocation RParenLoc) {
2028 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002029 }
2030
Francois Pichet6ad6f282010-12-07 00:08:36 +00002031 /// \brief Build a new binary type trait expression.
2032 ///
2033 /// By default, performs semantic analysis to build the new expression.
2034 /// Subclasses may override this routine to provide different behavior.
2035 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2036 SourceLocation StartLoc,
2037 TypeSourceInfo *LhsT,
2038 TypeSourceInfo *RhsT,
2039 SourceLocation RParenLoc) {
2040 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2041 }
2042
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002043 /// \brief Build a new type trait expression.
2044 ///
2045 /// By default, performs semantic analysis to build the new expression.
2046 /// Subclasses may override this routine to provide different behavior.
2047 ExprResult RebuildTypeTrait(TypeTrait Trait,
2048 SourceLocation StartLoc,
2049 ArrayRef<TypeSourceInfo *> Args,
2050 SourceLocation RParenLoc) {
2051 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2052 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002053
John Wiegley21ff2e52011-04-28 00:16:57 +00002054 /// \brief Build a new array type trait expression.
2055 ///
2056 /// By default, performs semantic analysis to build the new expression.
2057 /// Subclasses may override this routine to provide different behavior.
2058 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2059 SourceLocation StartLoc,
2060 TypeSourceInfo *TSInfo,
2061 Expr *DimExpr,
2062 SourceLocation RParenLoc) {
2063 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2064 }
2065
John Wiegley55262202011-04-25 06:54:41 +00002066 /// \brief Build a new expression trait expression.
2067 ///
2068 /// By default, performs semantic analysis to build the new expression.
2069 /// Subclasses may override this routine to provide different behavior.
2070 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2071 SourceLocation StartLoc,
2072 Expr *Queried,
2073 SourceLocation RParenLoc) {
2074 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2075 }
2076
Mike Stump1eb44332009-09-09 15:08:12 +00002077 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002078 /// expression.
2079 ///
2080 /// By default, performs semantic analysis to build the new expression.
2081 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002082 ExprResult RebuildDependentScopeDeclRefExpr(
2083 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002084 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002085 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002086 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002087 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002088 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002089
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002090 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002091 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002092 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002093
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002094 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002095 }
2096
2097 /// \brief Build a new template-id expression.
2098 ///
2099 /// By default, performs semantic analysis to build the new expression.
2100 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002101 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002102 SourceLocation TemplateKWLoc,
2103 LookupResult &R,
2104 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002105 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002106 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2107 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002108 }
2109
2110 /// \brief Build a new object-construction expression.
2111 ///
2112 /// By default, performs semantic analysis to build the new expression.
2113 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002114 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002115 SourceLocation Loc,
2116 CXXConstructorDecl *Constructor,
2117 bool IsElidable,
2118 MultiExprArg Args,
2119 bool HadMultipleCandidates,
2120 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002121 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002122 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00002123 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002124 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002125 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002126 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002127
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002128 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002129 move_arg(ConvertedArgs),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002130 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002131 RequiresZeroInit, ConstructKind,
2132 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002133 }
2134
2135 /// \brief Build a new object-construction expression.
2136 ///
2137 /// By default, performs semantic analysis to build the new expression.
2138 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002139 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2140 SourceLocation LParenLoc,
2141 MultiExprArg Args,
2142 SourceLocation RParenLoc) {
2143 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002144 LParenLoc,
2145 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002146 RParenLoc);
2147 }
2148
2149 /// \brief Build a new object-construction expression.
2150 ///
2151 /// By default, performs semantic analysis to build the new expression.
2152 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002153 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2154 SourceLocation LParenLoc,
2155 MultiExprArg Args,
2156 SourceLocation RParenLoc) {
2157 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002158 LParenLoc,
2159 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002160 RParenLoc);
2161 }
Mike Stump1eb44332009-09-09 15:08:12 +00002162
Douglas Gregorb98b1992009-08-11 05:31:07 +00002163 /// \brief Build a new member reference expression.
2164 ///
2165 /// By default, performs semantic analysis to build the new expression.
2166 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002167 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002168 QualType BaseType,
2169 bool IsArrow,
2170 SourceLocation OperatorLoc,
2171 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002172 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002173 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002174 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002175 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002176 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002177 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002178
John McCall9ae2f072010-08-23 23:25:46 +00002179 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002180 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002181 SS, TemplateKWLoc,
2182 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002183 MemberNameInfo,
2184 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002185 }
2186
John McCall129e2df2009-11-30 22:42:35 +00002187 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002188 ///
2189 /// By default, performs semantic analysis to build the new expression.
2190 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002191 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2192 SourceLocation OperatorLoc,
2193 bool IsArrow,
2194 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002195 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002196 NamedDecl *FirstQualifierInScope,
2197 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002198 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002199 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002200 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002201
John McCall9ae2f072010-08-23 23:25:46 +00002202 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002203 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002204 SS, TemplateKWLoc,
2205 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002206 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002207 }
Mike Stump1eb44332009-09-09 15:08:12 +00002208
Sebastian Redl2e156222010-09-10 20:55:43 +00002209 /// \brief Build a new noexcept expression.
2210 ///
2211 /// By default, performs semantic analysis to build the new expression.
2212 /// Subclasses may override this routine to provide different behavior.
2213 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2214 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2215 }
2216
Douglas Gregoree8aff02011-01-04 17:33:58 +00002217 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002218 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2219 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002220 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002221 llvm::Optional<unsigned> Length) {
2222 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002223 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2224 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002225 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002226
2227 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2228 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002229 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002230 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002231
Patrick Beardeb382ec2012-04-19 00:25:12 +00002232 /// \brief Build a new Objective-C boxed expression.
2233 ///
2234 /// By default, performs semantic analysis to build the new expression.
2235 /// Subclasses may override this routine to provide different behavior.
2236 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2237 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2238 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002239
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002240 /// \brief Build a new Objective-C array literal.
2241 ///
2242 /// By default, performs semantic analysis to build the new expression.
2243 /// Subclasses may override this routine to provide different behavior.
2244 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2245 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002246 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002247 MultiExprArg(Elements, NumElements));
2248 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002249
2250 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002251 Expr *Base, Expr *Key,
2252 ObjCMethodDecl *getterMethod,
2253 ObjCMethodDecl *setterMethod) {
2254 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2255 getterMethod, setterMethod);
2256 }
2257
2258 /// \brief Build a new Objective-C dictionary literal.
2259 ///
2260 /// By default, performs semantic analysis to build the new expression.
2261 /// Subclasses may override this routine to provide different behavior.
2262 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2263 ObjCDictionaryElement *Elements,
2264 unsigned NumElements) {
2265 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2266 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002267
James Dennett699c9042012-06-15 07:13:21 +00002268 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002269 ///
2270 /// By default, performs semantic analysis to build the new expression.
2271 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002272 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002273 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002274 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002275 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002276 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002277 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002278
Douglas Gregor92e986e2010-04-22 16:44:27 +00002279 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002280 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002281 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002282 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002283 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002284 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002285 MultiExprArg Args,
2286 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002287 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2288 ReceiverTypeInfo->getType(),
2289 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002290 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002291 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002292 }
2293
2294 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002295 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002296 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002297 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002298 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002299 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002300 MultiExprArg Args,
2301 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002302 return SemaRef.BuildInstanceMessage(Receiver,
2303 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002304 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002305 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002306 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002307 }
2308
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002309 /// \brief Build a new Objective-C ivar reference expression.
2310 ///
2311 /// By default, performs semantic analysis to build the new expression.
2312 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002313 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002314 SourceLocation IvarLoc,
2315 bool IsArrow, bool IsFreeIvar) {
2316 // FIXME: We lose track of the IsFreeIvar bit.
2317 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002318 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002319 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2320 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002321 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002322 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002323 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002324 false);
John Wiegley429bb272011-04-08 18:41:53 +00002325 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002326 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002327
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002328 if (Result.get())
2329 return move(Result);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002330
John Wiegley429bb272011-04-08 18:41:53 +00002331 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002332 /*FIXME:*/IvarLoc, IsArrow,
2333 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002334 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002335 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002336 /*TemplateArgs=*/0);
2337 }
Douglas Gregore3303542010-04-26 20:47:02 +00002338
2339 /// \brief Build a new Objective-C property reference expression.
2340 ///
2341 /// By default, performs semantic analysis to build the new expression.
2342 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002343 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002344 ObjCPropertyDecl *Property,
2345 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002346 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002347 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002348 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2349 Sema::LookupMemberName);
2350 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002351 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002352 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002353 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002354 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002355 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002356
Douglas Gregore3303542010-04-26 20:47:02 +00002357 if (Result.get())
2358 return move(Result);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002359
John Wiegley429bb272011-04-08 18:41:53 +00002360 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002361 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002362 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002363 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002364 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002365 /*TemplateArgs=*/0);
2366 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002367
John McCall12f78a62010-12-02 01:19:52 +00002368 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002369 ///
2370 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002371 /// Subclasses may override this routine to provide different behavior.
2372 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2373 ObjCMethodDecl *Getter,
2374 ObjCMethodDecl *Setter,
2375 SourceLocation PropertyLoc) {
2376 // Since these expressions can only be value-dependent, we do not
2377 // need to perform semantic analysis again.
2378 return Owned(
2379 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2380 VK_LValue, OK_ObjCProperty,
2381 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002382 }
2383
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002384 /// \brief Build a new Objective-C "isa" expression.
2385 ///
2386 /// By default, performs semantic analysis to build the new expression.
2387 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002388 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002389 bool IsArrow) {
2390 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002391 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002392 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2393 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002394 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002395 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002396 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002397 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002398 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002399
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002400 if (Result.get())
2401 return move(Result);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002402
John Wiegley429bb272011-04-08 18:41:53 +00002403 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002404 /*FIXME:*/IsaLoc, IsArrow,
2405 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002406 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002407 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002408 /*TemplateArgs=*/0);
2409 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002410
Douglas Gregorb98b1992009-08-11 05:31:07 +00002411 /// \brief Build a new shuffle vector expression.
2412 ///
2413 /// By default, performs semantic analysis to build the new expression.
2414 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002415 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002416 MultiExprArg SubExprs,
2417 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002418 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002419 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002420 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2421 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2422 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2423 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002424
Douglas Gregorb98b1992009-08-11 05:31:07 +00002425 // Build a reference to the __builtin_shufflevector builtin
2426 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002427 ExprResult Callee
John McCallf4b88a42012-03-10 09:33:50 +00002428 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, false,
2429 Builtin->getType(),
John Wiegley429bb272011-04-08 18:41:53 +00002430 VK_LValue, BuiltinLoc));
2431 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2432 if (Callee.isInvalid())
2433 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002434
2435 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002436 unsigned NumSubExprs = SubExprs.size();
2437 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002438 ExprResult TheCall = SemaRef.Owned(
2439 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002440 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002441 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002442 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002443 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002444
Douglas Gregorb98b1992009-08-11 05:31:07 +00002445 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002446 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002447 }
John McCall43fed0d2010-11-12 08:19:04 +00002448
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002449 /// \brief Build a new template argument pack expansion.
2450 ///
2451 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002452 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002453 /// different behavior.
2454 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002455 SourceLocation EllipsisLoc,
2456 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002457 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002458 case TemplateArgument::Expression: {
2459 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002460 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2461 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002462 if (Result.isInvalid())
2463 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002464
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002465 return TemplateArgumentLoc(Result.get(), Result.get());
2466 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002467
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002468 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002469 return TemplateArgumentLoc(TemplateArgument(
2470 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002471 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002472 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002473 Pattern.getTemplateNameLoc(),
2474 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002475
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002476 case TemplateArgument::Null:
2477 case TemplateArgument::Integral:
2478 case TemplateArgument::Declaration:
2479 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002480 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002481 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002482
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002483 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002484 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002485 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002486 EllipsisLoc,
2487 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002488 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2489 Expansion);
2490 break;
2491 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002492
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002493 return TemplateArgumentLoc();
2494 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002495
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002496 /// \brief Build a new expression pack expansion.
2497 ///
2498 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002499 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002500 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002501 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2502 llvm::Optional<unsigned> NumExpansions) {
2503 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002504 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002505
2506 /// \brief Build a new atomic operation expression.
2507 ///
2508 /// By default, performs semantic analysis to build the new expression.
2509 /// Subclasses may override this routine to provide different behavior.
2510 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2511 MultiExprArg SubExprs,
2512 QualType RetTy,
2513 AtomicExpr::AtomicOp Op,
2514 SourceLocation RParenLoc) {
2515 // Just create the expression; there is not any interesting semantic
2516 // analysis here because we can't actually build an AtomicExpr until
2517 // we are sure it is semantically sound.
2518 unsigned NumSubExprs = SubExprs.size();
2519 Expr **Subs = (Expr **)SubExprs.release();
2520 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2521 NumSubExprs, RetTy, Op,
2522 RParenLoc);
2523 }
2524
John McCall43fed0d2010-11-12 08:19:04 +00002525private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002526 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2527 QualType ObjectType,
2528 NamedDecl *FirstQualifierInScope,
2529 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002530
2531 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2532 QualType ObjectType,
2533 NamedDecl *FirstQualifierInScope,
2534 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002535};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002536
Douglas Gregor43959a92009-08-20 07:17:43 +00002537template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002538StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002539 if (!S)
2540 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002541
Douglas Gregor43959a92009-08-20 07:17:43 +00002542 switch (S->getStmtClass()) {
2543 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002544
Douglas Gregor43959a92009-08-20 07:17:43 +00002545 // Transform individual statement nodes
2546#define STMT(Node, Parent) \
2547 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002548#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002549#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002550#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002551
Douglas Gregor43959a92009-08-20 07:17:43 +00002552 // Transform expressions by calling TransformExpr.
2553#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002554#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002555#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002556#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002557 {
John McCall60d7b3a2010-08-24 06:29:42 +00002558 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002559 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002560 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002561
John McCall9ae2f072010-08-23 23:25:46 +00002562 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002563 }
Mike Stump1eb44332009-09-09 15:08:12 +00002564 }
2565
John McCall3fa5cae2010-10-26 07:05:15 +00002566 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002567}
Mike Stump1eb44332009-09-09 15:08:12 +00002568
2569
Douglas Gregor670444e2009-08-04 22:27:00 +00002570template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002571ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002572 if (!E)
2573 return SemaRef.Owned(E);
2574
2575 switch (E->getStmtClass()) {
2576 case Stmt::NoStmtClass: break;
2577#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002578#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002579#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002580 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002581#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002582 }
2583
John McCall3fa5cae2010-10-26 07:05:15 +00002584 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002585}
2586
2587template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002588bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2589 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002590 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002591 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002592 bool *ArgChanged) {
2593 for (unsigned I = 0; I != NumInputs; ++I) {
2594 // If requested, drop call arguments that need to be dropped.
2595 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2596 if (ArgChanged)
2597 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002598
Douglas Gregoraa165f82011-01-03 19:04:46 +00002599 break;
2600 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002601
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002602 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2603 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002604
Chris Lattner686775d2011-07-20 06:58:45 +00002605 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002606 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2607 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002608
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002609 // Determine whether the set of unexpanded parameter packs can and should
2610 // be expanded.
2611 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002612 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002613 llvm::Optional<unsigned> OrigNumExpansions
2614 = Expansion->getNumExpansions();
2615 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002616 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2617 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002618 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002619 Expand, RetainExpansion,
2620 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002621 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002622
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002623 if (!Expand) {
2624 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002625 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002626 // expansion.
2627 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2628 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2629 if (OutPattern.isInvalid())
2630 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002631
2632 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002633 Expansion->getEllipsisLoc(),
2634 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002635 if (Out.isInvalid())
2636 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002637
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002638 if (ArgChanged)
2639 *ArgChanged = true;
2640 Outputs.push_back(Out.get());
2641 continue;
2642 }
John McCallc8fc90a2011-07-06 07:30:07 +00002643
2644 // Record right away that the argument was changed. This needs
2645 // to happen even if the array expands to nothing.
2646 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002647
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002648 // The transform has determined that we should perform an elementwise
2649 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002650 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002651 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2652 ExprResult Out = getDerived().TransformExpr(Pattern);
2653 if (Out.isInvalid())
2654 return true;
2655
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002656 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002657 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2658 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002659 if (Out.isInvalid())
2660 return true;
2661 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002662
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002663 Outputs.push_back(Out.get());
2664 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002665
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002666 continue;
2667 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002668
Douglas Gregoraa165f82011-01-03 19:04:46 +00002669 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2670 if (Result.isInvalid())
2671 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002672
Douglas Gregoraa165f82011-01-03 19:04:46 +00002673 if (Result.get() != Inputs[I] && ArgChanged)
2674 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002675
2676 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002677 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002678
Douglas Gregoraa165f82011-01-03 19:04:46 +00002679 return false;
2680}
2681
2682template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002683NestedNameSpecifierLoc
2684TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2685 NestedNameSpecifierLoc NNS,
2686 QualType ObjectType,
2687 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002688 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002689 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002690 Qualifier = Qualifier.getPrefix())
2691 Qualifiers.push_back(Qualifier);
2692
2693 CXXScopeSpec SS;
2694 while (!Qualifiers.empty()) {
2695 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2696 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002697
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002698 switch (QNNS->getKind()) {
2699 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002700 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002701 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002702 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002703 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002704 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002705 FirstQualifierInScope, false))
2706 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002707
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002708 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002709
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002710 case NestedNameSpecifier::Namespace: {
2711 NamespaceDecl *NS
2712 = cast_or_null<NamespaceDecl>(
2713 getDerived().TransformDecl(
2714 Q.getLocalBeginLoc(),
2715 QNNS->getAsNamespace()));
2716 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2717 break;
2718 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002719
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002720 case NestedNameSpecifier::NamespaceAlias: {
2721 NamespaceAliasDecl *Alias
2722 = cast_or_null<NamespaceAliasDecl>(
2723 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2724 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002725 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002726 Q.getLocalEndLoc());
2727 break;
2728 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002729
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002730 case NestedNameSpecifier::Global:
2731 // There is no meaningful transformation that one could perform on the
2732 // global scope.
2733 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2734 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002735
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002736 case NestedNameSpecifier::TypeSpecWithTemplate:
2737 case NestedNameSpecifier::TypeSpec: {
2738 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2739 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002740
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002741 if (!TL)
2742 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002743
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002744 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00002745 (SemaRef.getLangOpts().CPlusPlus0x &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002746 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002747 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002748 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002749 if (TL.getType()->isEnumeralType())
2750 SemaRef.Diag(TL.getBeginLoc(),
2751 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002752 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2753 Q.getLocalEndLoc());
2754 break;
2755 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002756 // If the nested-name-specifier is an invalid type def, don't emit an
2757 // error because a previous error should have already been emitted.
2758 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2759 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002760 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002761 << TL.getType() << SS.getRange();
2762 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002763 return NestedNameSpecifierLoc();
2764 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002765 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002766
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002767 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002768 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002769 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002770 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002771
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002772 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002773 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002774 !getDerived().AlwaysRebuild())
2775 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002776
2777 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002778 // nested-name-specifier, do so.
2779 if (SS.location_size() == NNS.getDataLength() &&
2780 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2781 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2782
2783 // Allocate new nested-name-specifier location information.
2784 return SS.getWithLocInContext(SemaRef.Context);
2785}
2786
2787template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002788DeclarationNameInfo
2789TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002790::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002791 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002792 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002793 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002794
2795 switch (Name.getNameKind()) {
2796 case DeclarationName::Identifier:
2797 case DeclarationName::ObjCZeroArgSelector:
2798 case DeclarationName::ObjCOneArgSelector:
2799 case DeclarationName::ObjCMultiArgSelector:
2800 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002801 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002802 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002803 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002804
Douglas Gregor81499bb2009-09-03 22:13:48 +00002805 case DeclarationName::CXXConstructorName:
2806 case DeclarationName::CXXDestructorName:
2807 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002808 TypeSourceInfo *NewTInfo;
2809 CanQualType NewCanTy;
2810 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002811 NewTInfo = getDerived().TransformType(OldTInfo);
2812 if (!NewTInfo)
2813 return DeclarationNameInfo();
2814 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002815 }
2816 else {
2817 NewTInfo = 0;
2818 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002819 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002820 if (NewT.isNull())
2821 return DeclarationNameInfo();
2822 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2823 }
Mike Stump1eb44332009-09-09 15:08:12 +00002824
Abramo Bagnara25777432010-08-11 22:01:17 +00002825 DeclarationName NewName
2826 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2827 NewCanTy);
2828 DeclarationNameInfo NewNameInfo(NameInfo);
2829 NewNameInfo.setName(NewName);
2830 NewNameInfo.setNamedTypeInfo(NewTInfo);
2831 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002832 }
Mike Stump1eb44332009-09-09 15:08:12 +00002833 }
2834
David Blaikieb219cfc2011-09-23 05:06:16 +00002835 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002836}
2837
2838template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002839TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002840TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2841 TemplateName Name,
2842 SourceLocation NameLoc,
2843 QualType ObjectType,
2844 NamedDecl *FirstQualifierInScope) {
2845 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2846 TemplateDecl *Template = QTN->getTemplateDecl();
2847 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002848
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002849 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002850 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002851 Template));
2852 if (!TransTemplate)
2853 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002854
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002855 if (!getDerived().AlwaysRebuild() &&
2856 SS.getScopeRep() == QTN->getQualifier() &&
2857 TransTemplate == Template)
2858 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002859
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002860 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2861 TransTemplate);
2862 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002863
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002864 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2865 if (SS.getScopeRep()) {
2866 // These apply to the scope specifier, not the template.
2867 ObjectType = QualType();
2868 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002869 }
2870
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002871 if (!getDerived().AlwaysRebuild() &&
2872 SS.getScopeRep() == DTN->getQualifier() &&
2873 ObjectType.isNull())
2874 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002875
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002876 if (DTN->isIdentifier()) {
2877 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002878 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002879 NameLoc,
2880 ObjectType,
2881 FirstQualifierInScope);
2882 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002883
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002884 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2885 ObjectType);
2886 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002887
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002888 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2889 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002890 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002891 Template));
2892 if (!TransTemplate)
2893 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002894
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002895 if (!getDerived().AlwaysRebuild() &&
2896 TransTemplate == Template)
2897 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002898
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002899 return TemplateName(TransTemplate);
2900 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002901
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002902 if (SubstTemplateTemplateParmPackStorage *SubstPack
2903 = Name.getAsSubstTemplateTemplateParmPack()) {
2904 TemplateTemplateParmDecl *TransParam
2905 = cast_or_null<TemplateTemplateParmDecl>(
2906 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2907 if (!TransParam)
2908 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002909
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002910 if (!getDerived().AlwaysRebuild() &&
2911 TransParam == SubstPack->getParameterPack())
2912 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002913
2914 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002915 SubstPack->getArgumentPack());
2916 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002917
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002918 // These should be getting filtered out before they reach the AST.
2919 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002920}
2921
2922template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002923void TreeTransform<Derived>::InventTemplateArgumentLoc(
2924 const TemplateArgument &Arg,
2925 TemplateArgumentLoc &Output) {
2926 SourceLocation Loc = getDerived().getBaseLocation();
2927 switch (Arg.getKind()) {
2928 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002929 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002930 break;
2931
2932 case TemplateArgument::Type:
2933 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002934 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002935
John McCall833ca992009-10-29 08:12:44 +00002936 break;
2937
Douglas Gregor788cd062009-11-11 01:00:40 +00002938 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002939 case TemplateArgument::TemplateExpansion: {
2940 NestedNameSpecifierLocBuilder Builder;
2941 TemplateName Template = Arg.getAsTemplate();
2942 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2943 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2944 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2945 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002946
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002947 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002948 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002949 Builder.getWithLocInContext(SemaRef.Context),
2950 Loc);
2951 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00002952 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002953 Builder.getWithLocInContext(SemaRef.Context),
2954 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002955
Douglas Gregor788cd062009-11-11 01:00:40 +00002956 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002957 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002958
John McCall833ca992009-10-29 08:12:44 +00002959 case TemplateArgument::Expression:
2960 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2961 break;
2962
2963 case TemplateArgument::Declaration:
2964 case TemplateArgument::Integral:
2965 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002966 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002967 break;
2968 }
2969}
2970
2971template<typename Derived>
2972bool TreeTransform<Derived>::TransformTemplateArgument(
2973 const TemplateArgumentLoc &Input,
2974 TemplateArgumentLoc &Output) {
2975 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002976 switch (Arg.getKind()) {
2977 case TemplateArgument::Null:
2978 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002979 Output = Input;
2980 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002981
Douglas Gregor670444e2009-08-04 22:27:00 +00002982 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002983 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002984 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002985 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002986
2987 DI = getDerived().TransformType(DI);
2988 if (!DI) return true;
2989
2990 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2991 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002992 }
Mike Stump1eb44332009-09-09 15:08:12 +00002993
Douglas Gregor670444e2009-08-04 22:27:00 +00002994 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002995 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002996 DeclarationName Name;
2997 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2998 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002999 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003000 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00003001 if (!D) return true;
3002
John McCall828bff22009-10-29 18:45:58 +00003003 Expr *SourceExpr = Input.getSourceDeclExpression();
3004 if (SourceExpr) {
3005 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003006 Sema::ConstantEvaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00003007 ExprResult E = getDerived().TransformExpr(SourceExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003008 E = SemaRef.ActOnConstantExpression(E);
John McCall9ae2f072010-08-23 23:25:46 +00003009 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00003010 }
3011
3012 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00003013 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003014 }
Mike Stump1eb44332009-09-09 15:08:12 +00003015
Douglas Gregor788cd062009-11-11 01:00:40 +00003016 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003017 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3018 if (QualifierLoc) {
3019 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3020 if (!QualifierLoc)
3021 return true;
3022 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003023
Douglas Gregor1d752d72011-03-02 18:46:51 +00003024 CXXScopeSpec SS;
3025 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003026 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003027 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3028 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003029 if (Template.isNull())
3030 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003031
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003032 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003033 Input.getTemplateNameLoc());
3034 return false;
3035 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003036
3037 case TemplateArgument::TemplateExpansion:
3038 llvm_unreachable("Caller should expand pack expansions");
3039
Douglas Gregor670444e2009-08-04 22:27:00 +00003040 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003041 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003042 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003043 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003044
John McCall833ca992009-10-29 08:12:44 +00003045 Expr *InputExpr = Input.getSourceExpression();
3046 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3047
Chris Lattner223de242011-04-25 20:37:58 +00003048 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003049 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003050 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003051 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003052 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003053 }
Mike Stump1eb44332009-09-09 15:08:12 +00003054
Douglas Gregor670444e2009-08-04 22:27:00 +00003055 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00003056 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00003057 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00003058 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00003059 AEnd = Arg.pack_end();
3060 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00003061
John McCall833ca992009-10-29 08:12:44 +00003062 // FIXME: preserve source information here when we start
3063 // caring about parameter packs.
3064
John McCall828bff22009-10-29 18:45:58 +00003065 TemplateArgumentLoc InputArg;
3066 TemplateArgumentLoc OutputArg;
3067 getDerived().InventTemplateArgumentLoc(*A, InputArg);
3068 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00003069 return true;
3070
John McCall828bff22009-10-29 18:45:58 +00003071 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00003072 }
Douglas Gregor910f8002010-11-07 23:05:16 +00003073
3074 TemplateArgument *TransformedArgsPtr
3075 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
3076 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
3077 TransformedArgsPtr);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003078 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
3079 TransformedArgs.size()),
Douglas Gregor910f8002010-11-07 23:05:16 +00003080 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003081 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003082 }
3083 }
Mike Stump1eb44332009-09-09 15:08:12 +00003084
Douglas Gregor670444e2009-08-04 22:27:00 +00003085 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003086 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003087}
3088
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003089/// \brief Iterator adaptor that invents template argument location information
3090/// for each of the template arguments in its underlying iterator.
3091template<typename Derived, typename InputIterator>
3092class TemplateArgumentLocInventIterator {
3093 TreeTransform<Derived> &Self;
3094 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003095
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003096public:
3097 typedef TemplateArgumentLoc value_type;
3098 typedef TemplateArgumentLoc reference;
3099 typedef typename std::iterator_traits<InputIterator>::difference_type
3100 difference_type;
3101 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003102
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003103 class pointer {
3104 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003105
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003106 public:
3107 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003108
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003109 const TemplateArgumentLoc *operator->() const { return &Arg; }
3110 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003111
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003112 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003113
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003114 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3115 InputIterator Iter)
3116 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003117
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003118 TemplateArgumentLocInventIterator &operator++() {
3119 ++Iter;
3120 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003121 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003122
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003123 TemplateArgumentLocInventIterator operator++(int) {
3124 TemplateArgumentLocInventIterator Old(*this);
3125 ++(*this);
3126 return Old;
3127 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003128
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003129 reference operator*() const {
3130 TemplateArgumentLoc Result;
3131 Self.InventTemplateArgumentLoc(*Iter, Result);
3132 return Result;
3133 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003134
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003135 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003136
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003137 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3138 const TemplateArgumentLocInventIterator &Y) {
3139 return X.Iter == Y.Iter;
3140 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003141
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003142 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3143 const TemplateArgumentLocInventIterator &Y) {
3144 return X.Iter != Y.Iter;
3145 }
3146};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003147
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003148template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003149template<typename InputIterator>
3150bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3151 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003152 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003153 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003154 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003155 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003156
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003157 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3158 // Unpack argument packs, which we translate them into separate
3159 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003160 // FIXME: We could do much better if we could guarantee that the
3161 // TemplateArgumentLocInfo for the pack expansion would be usable for
3162 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003163 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003164 TemplateArgument::pack_iterator>
3165 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003166 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003167 In.getArgument().pack_begin()),
3168 PackLocIterator(*this,
3169 In.getArgument().pack_end()),
3170 Outputs))
3171 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003172
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003173 continue;
3174 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003175
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003176 if (In.getArgument().isPackExpansion()) {
3177 // We have a pack expansion, for which we will be substituting into
3178 // the pattern.
3179 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003180 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003181 TemplateArgumentLoc Pattern
Chad Rosier4a9d7952012-08-08 18:46:20 +00003182 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
Douglas Gregorcded4f62011-01-14 17:04:44 +00003183 getSema().Context);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003184
Chris Lattner686775d2011-07-20 06:58:45 +00003185 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003186 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3187 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003188
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003189 // Determine whether the set of unexpanded parameter packs can and should
3190 // be expanded.
3191 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003192 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003193 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003194 if (getDerived().TryExpandParameterPacks(Ellipsis,
3195 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003196 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003197 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003198 RetainExpansion,
3199 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003200 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003201
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003202 if (!Expand) {
3203 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003204 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003205 // expansion.
3206 TemplateArgumentLoc OutPattern;
3207 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3208 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3209 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003210
Douglas Gregorcded4f62011-01-14 17:04:44 +00003211 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3212 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003213 if (Out.getArgument().isNull())
3214 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003215
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003216 Outputs.addArgument(Out);
3217 continue;
3218 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003219
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003220 // The transform has determined that we should perform an elementwise
3221 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003222 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003223 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3224
3225 if (getDerived().TransformTemplateArgument(Pattern, Out))
3226 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003227
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003228 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003229 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3230 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003231 if (Out.getArgument().isNull())
3232 return true;
3233 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003234
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003235 Outputs.addArgument(Out);
3236 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003237
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003238 // If we're supposed to retain a pack expansion, do so by temporarily
3239 // forgetting the partially-substituted parameter pack.
3240 if (RetainExpansion) {
3241 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003242
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003243 if (getDerived().TransformTemplateArgument(Pattern, Out))
3244 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003245
Douglas Gregorcded4f62011-01-14 17:04:44 +00003246 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3247 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003248 if (Out.getArgument().isNull())
3249 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003250
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003251 Outputs.addArgument(Out);
3252 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003253
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003254 continue;
3255 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003256
3257 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003258 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003259 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003260
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003261 Outputs.addArgument(Out);
3262 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003263
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003264 return false;
3265
3266}
3267
Douglas Gregor577f75a2009-08-04 16:50:30 +00003268//===----------------------------------------------------------------------===//
3269// Type transformation
3270//===----------------------------------------------------------------------===//
3271
3272template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003273QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003274 if (getDerived().AlreadyTransformed(T))
3275 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003276
John McCalla2becad2009-10-21 00:40:46 +00003277 // Temporary workaround. All of these transformations should
3278 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003279 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3280 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003281
John McCall43fed0d2010-11-12 08:19:04 +00003282 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003283
John McCalla2becad2009-10-21 00:40:46 +00003284 if (!NewDI)
3285 return QualType();
3286
3287 return NewDI->getType();
3288}
3289
3290template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003291TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003292 // Refine the base location to the type's location.
3293 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3294 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003295 if (getDerived().AlreadyTransformed(DI->getType()))
3296 return DI;
3297
3298 TypeLocBuilder TLB;
3299
3300 TypeLoc TL = DI->getTypeLoc();
3301 TLB.reserve(TL.getFullDataSize());
3302
John McCall43fed0d2010-11-12 08:19:04 +00003303 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003304 if (Result.isNull())
3305 return 0;
3306
John McCalla93c9342009-12-07 02:54:59 +00003307 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003308}
3309
3310template<typename Derived>
3311QualType
John McCall43fed0d2010-11-12 08:19:04 +00003312TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003313 switch (T.getTypeLocClass()) {
3314#define ABSTRACT_TYPELOC(CLASS, PARENT)
3315#define TYPELOC(CLASS, PARENT) \
3316 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003317 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003318#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003319 }
Mike Stump1eb44332009-09-09 15:08:12 +00003320
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003321 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003322}
3323
3324/// FIXME: By default, this routine adds type qualifiers only to types
3325/// that can have qualifiers, and silently suppresses those qualifiers
3326/// that are not permitted (e.g., qualifiers on reference or function
3327/// types). This is the right thing for template instantiation, but
3328/// probably not for other clients.
3329template<typename Derived>
3330QualType
3331TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003332 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003333 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003334
John McCall43fed0d2010-11-12 08:19:04 +00003335 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003336 if (Result.isNull())
3337 return QualType();
3338
3339 // Silently suppress qualifiers if the result type can't be qualified.
3340 // FIXME: this is the right thing for template instantiation, but
3341 // probably not for other clients.
3342 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003343 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003344
John McCallf85e1932011-06-15 23:02:42 +00003345 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003346 // resulting type.
3347 if (Quals.hasObjCLifetime()) {
3348 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3349 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003350 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003351 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003352 // A lifetime qualifier applied to a substituted template parameter
3353 // overrides the lifetime qualifier from the template argument.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003354 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003355 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3356 QualType Replacement = SubstTypeParam->getReplacementType();
3357 Qualifiers Qs = Replacement.getQualifiers();
3358 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003359 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003360 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3361 Qs);
3362 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003363 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003364 Replacement);
3365 TLB.TypeWasModifiedSafely(Result);
3366 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003367 // Otherwise, complain about the addition of a qualifier to an
3368 // already-qualified type.
3369 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003370 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003371 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003372
Douglas Gregore559ca12011-06-17 22:11:49 +00003373 Quals.removeObjCLifetime();
3374 }
3375 }
3376 }
John McCall28654742010-06-05 06:41:15 +00003377 if (!Quals.empty()) {
3378 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3379 TLB.push<QualifiedTypeLoc>(Result);
3380 // No location information to preserve.
3381 }
John McCalla2becad2009-10-21 00:40:46 +00003382
3383 return Result;
3384}
3385
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003386template<typename Derived>
3387TypeLoc
3388TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3389 QualType ObjectType,
3390 NamedDecl *UnqualLookup,
3391 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003392 QualType T = TL.getType();
3393 if (getDerived().AlreadyTransformed(T))
3394 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003395
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003396 TypeLocBuilder TLB;
3397 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003398
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003399 if (isa<TemplateSpecializationType>(T)) {
3400 TemplateSpecializationTypeLoc SpecTL
3401 = cast<TemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003402
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003403 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003404 getDerived().TransformTemplateName(SS,
3405 SpecTL.getTypePtr()->getTemplateName(),
3406 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003407 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003408 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003409 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003410
3411 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003412 Template);
3413 } else if (isa<DependentTemplateSpecializationType>(T)) {
3414 DependentTemplateSpecializationTypeLoc SpecTL
3415 = cast<DependentTemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003416
Douglas Gregora88f09f2011-02-28 17:23:35 +00003417 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003418 = getDerived().RebuildTemplateName(SS,
3419 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003420 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003421 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003422 if (Template.isNull())
3423 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003424
3425 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003426 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003427 Template,
3428 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003429 } else {
3430 // Nothing special needs to be done for these.
3431 Result = getDerived().TransformType(TLB, TL);
3432 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003433
3434 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003435 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003436
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003437 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3438}
3439
Douglas Gregorb71d8212011-03-02 18:32:08 +00003440template<typename Derived>
3441TypeSourceInfo *
3442TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3443 QualType ObjectType,
3444 NamedDecl *UnqualLookup,
3445 CXXScopeSpec &SS) {
3446 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003447
Douglas Gregorb71d8212011-03-02 18:32:08 +00003448 QualType T = TSInfo->getType();
3449 if (getDerived().AlreadyTransformed(T))
3450 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003451
Douglas Gregorb71d8212011-03-02 18:32:08 +00003452 TypeLocBuilder TLB;
3453 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003454
Douglas Gregorb71d8212011-03-02 18:32:08 +00003455 TypeLoc TL = TSInfo->getTypeLoc();
3456 if (isa<TemplateSpecializationType>(T)) {
3457 TemplateSpecializationTypeLoc SpecTL
3458 = cast<TemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003459
Douglas Gregorb71d8212011-03-02 18:32:08 +00003460 TemplateName Template
3461 = getDerived().TransformTemplateName(SS,
3462 SpecTL.getTypePtr()->getTemplateName(),
3463 SpecTL.getTemplateNameLoc(),
3464 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003465 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003466 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003467
3468 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003469 Template);
3470 } else if (isa<DependentTemplateSpecializationType>(T)) {
3471 DependentTemplateSpecializationTypeLoc SpecTL
3472 = cast<DependentTemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003473
Douglas Gregorb71d8212011-03-02 18:32:08 +00003474 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003475 = getDerived().RebuildTemplateName(SS,
3476 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003477 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003478 ObjectType, UnqualLookup);
3479 if (Template.isNull())
3480 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003481
3482 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003483 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003484 Template,
3485 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003486 } else {
3487 // Nothing special needs to be done for these.
3488 Result = getDerived().TransformType(TLB, TL);
3489 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003490
3491 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003492 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003493
Douglas Gregorb71d8212011-03-02 18:32:08 +00003494 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3495}
3496
John McCalla2becad2009-10-21 00:40:46 +00003497template <class TyLoc> static inline
3498QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3499 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3500 NewT.setNameLoc(T.getNameLoc());
3501 return T.getType();
3502}
3503
John McCalla2becad2009-10-21 00:40:46 +00003504template<typename Derived>
3505QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003506 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003507 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3508 NewT.setBuiltinLoc(T.getBuiltinLoc());
3509 if (T.needsExtraLocalData())
3510 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3511 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003512}
Mike Stump1eb44332009-09-09 15:08:12 +00003513
Douglas Gregor577f75a2009-08-04 16:50:30 +00003514template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003515QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003516 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003517 // FIXME: recurse?
3518 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003519}
Mike Stump1eb44332009-09-09 15:08:12 +00003520
Douglas Gregor577f75a2009-08-04 16:50:30 +00003521template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003522QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003523 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003524 QualType PointeeType
3525 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003526 if (PointeeType.isNull())
3527 return QualType();
3528
3529 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003530 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003531 // A dependent pointer type 'T *' has is being transformed such
3532 // that an Objective-C class type is being replaced for 'T'. The
3533 // resulting pointer type is an ObjCObjectPointerType, not a
3534 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003535 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003536
John McCallc12c5bb2010-05-15 11:32:37 +00003537 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3538 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003539 return Result;
3540 }
John McCall43fed0d2010-11-12 08:19:04 +00003541
Douglas Gregor92e986e2010-04-22 16:44:27 +00003542 if (getDerived().AlwaysRebuild() ||
3543 PointeeType != TL.getPointeeLoc().getType()) {
3544 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3545 if (Result.isNull())
3546 return QualType();
3547 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003548
John McCallf85e1932011-06-15 23:02:42 +00003549 // Objective-C ARC can add lifetime qualifiers to the type that we're
3550 // pointing to.
3551 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003552
Douglas Gregor92e986e2010-04-22 16:44:27 +00003553 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3554 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003555 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003556}
Mike Stump1eb44332009-09-09 15:08:12 +00003557
3558template<typename Derived>
3559QualType
John McCalla2becad2009-10-21 00:40:46 +00003560TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003561 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003562 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003563 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3564 if (PointeeType.isNull())
3565 return QualType();
3566
3567 QualType Result = TL.getType();
3568 if (getDerived().AlwaysRebuild() ||
3569 PointeeType != TL.getPointeeLoc().getType()) {
3570 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003571 TL.getSigilLoc());
3572 if (Result.isNull())
3573 return QualType();
3574 }
3575
Douglas Gregor39968ad2010-04-22 16:50:51 +00003576 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003577 NewT.setSigilLoc(TL.getSigilLoc());
3578 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003579}
3580
John McCall85737a72009-10-30 00:06:24 +00003581/// Transforms a reference type. Note that somewhat paradoxically we
3582/// don't care whether the type itself is an l-value type or an r-value
3583/// type; we only care if the type was *written* as an l-value type
3584/// or an r-value type.
3585template<typename Derived>
3586QualType
3587TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003588 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003589 const ReferenceType *T = TL.getTypePtr();
3590
3591 // Note that this works with the pointee-as-written.
3592 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3593 if (PointeeType.isNull())
3594 return QualType();
3595
3596 QualType Result = TL.getType();
3597 if (getDerived().AlwaysRebuild() ||
3598 PointeeType != T->getPointeeTypeAsWritten()) {
3599 Result = getDerived().RebuildReferenceType(PointeeType,
3600 T->isSpelledAsLValue(),
3601 TL.getSigilLoc());
3602 if (Result.isNull())
3603 return QualType();
3604 }
3605
John McCallf85e1932011-06-15 23:02:42 +00003606 // Objective-C ARC can add lifetime qualifiers to the type that we're
3607 // referring to.
3608 TLB.TypeWasModifiedSafely(
3609 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3610
John McCall85737a72009-10-30 00:06:24 +00003611 // r-value references can be rebuilt as l-value references.
3612 ReferenceTypeLoc NewTL;
3613 if (isa<LValueReferenceType>(Result))
3614 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3615 else
3616 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3617 NewTL.setSigilLoc(TL.getSigilLoc());
3618
3619 return Result;
3620}
3621
Mike Stump1eb44332009-09-09 15:08:12 +00003622template<typename Derived>
3623QualType
John McCalla2becad2009-10-21 00:40:46 +00003624TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003625 LValueReferenceTypeLoc TL) {
3626 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003627}
3628
Mike Stump1eb44332009-09-09 15:08:12 +00003629template<typename Derived>
3630QualType
John McCalla2becad2009-10-21 00:40:46 +00003631TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003632 RValueReferenceTypeLoc TL) {
3633 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003634}
Mike Stump1eb44332009-09-09 15:08:12 +00003635
Douglas Gregor577f75a2009-08-04 16:50:30 +00003636template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003637QualType
John McCalla2becad2009-10-21 00:40:46 +00003638TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003639 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003640 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003641 if (PointeeType.isNull())
3642 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003643
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003644 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3645 TypeSourceInfo* NewClsTInfo = 0;
3646 if (OldClsTInfo) {
3647 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3648 if (!NewClsTInfo)
3649 return QualType();
3650 }
3651
3652 const MemberPointerType *T = TL.getTypePtr();
3653 QualType OldClsType = QualType(T->getClass(), 0);
3654 QualType NewClsType;
3655 if (NewClsTInfo)
3656 NewClsType = NewClsTInfo->getType();
3657 else {
3658 NewClsType = getDerived().TransformType(OldClsType);
3659 if (NewClsType.isNull())
3660 return QualType();
3661 }
Mike Stump1eb44332009-09-09 15:08:12 +00003662
John McCalla2becad2009-10-21 00:40:46 +00003663 QualType Result = TL.getType();
3664 if (getDerived().AlwaysRebuild() ||
3665 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003666 NewClsType != OldClsType) {
3667 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003668 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003669 if (Result.isNull())
3670 return QualType();
3671 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003672
John McCalla2becad2009-10-21 00:40:46 +00003673 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3674 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003675 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003676
3677 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003678}
3679
Mike Stump1eb44332009-09-09 15:08:12 +00003680template<typename Derived>
3681QualType
John McCalla2becad2009-10-21 00:40:46 +00003682TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003683 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003684 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003685 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003686 if (ElementType.isNull())
3687 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003688
John McCalla2becad2009-10-21 00:40:46 +00003689 QualType Result = TL.getType();
3690 if (getDerived().AlwaysRebuild() ||
3691 ElementType != T->getElementType()) {
3692 Result = getDerived().RebuildConstantArrayType(ElementType,
3693 T->getSizeModifier(),
3694 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003695 T->getIndexTypeCVRQualifiers(),
3696 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003697 if (Result.isNull())
3698 return QualType();
3699 }
Eli Friedman457a3772012-01-25 22:19:07 +00003700
3701 // We might have either a ConstantArrayType or a VariableArrayType now:
3702 // a ConstantArrayType is allowed to have an element type which is a
3703 // VariableArrayType if the type is dependent. Fortunately, all array
3704 // types have the same location layout.
3705 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003706 NewTL.setLBracketLoc(TL.getLBracketLoc());
3707 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003708
John McCalla2becad2009-10-21 00:40:46 +00003709 Expr *Size = TL.getSizeExpr();
3710 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003711 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3712 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003713 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003714 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003715 }
3716 NewTL.setSizeExpr(Size);
3717
3718 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003719}
Mike Stump1eb44332009-09-09 15:08:12 +00003720
Douglas Gregor577f75a2009-08-04 16:50:30 +00003721template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003722QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003723 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003724 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003725 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003726 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003727 if (ElementType.isNull())
3728 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003729
John McCalla2becad2009-10-21 00:40:46 +00003730 QualType Result = TL.getType();
3731 if (getDerived().AlwaysRebuild() ||
3732 ElementType != T->getElementType()) {
3733 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003734 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003735 T->getIndexTypeCVRQualifiers(),
3736 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003737 if (Result.isNull())
3738 return QualType();
3739 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003740
John McCalla2becad2009-10-21 00:40:46 +00003741 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3742 NewTL.setLBracketLoc(TL.getLBracketLoc());
3743 NewTL.setRBracketLoc(TL.getRBracketLoc());
3744 NewTL.setSizeExpr(0);
3745
3746 return Result;
3747}
3748
3749template<typename Derived>
3750QualType
3751TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003752 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003753 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003754 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3755 if (ElementType.isNull())
3756 return QualType();
3757
John McCall60d7b3a2010-08-24 06:29:42 +00003758 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003759 = getDerived().TransformExpr(T->getSizeExpr());
3760 if (SizeResult.isInvalid())
3761 return QualType();
3762
John McCall9ae2f072010-08-23 23:25:46 +00003763 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003764
3765 QualType Result = TL.getType();
3766 if (getDerived().AlwaysRebuild() ||
3767 ElementType != T->getElementType() ||
3768 Size != T->getSizeExpr()) {
3769 Result = getDerived().RebuildVariableArrayType(ElementType,
3770 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003771 Size,
John McCalla2becad2009-10-21 00:40:46 +00003772 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003773 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003774 if (Result.isNull())
3775 return QualType();
3776 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003777
John McCalla2becad2009-10-21 00:40:46 +00003778 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3779 NewTL.setLBracketLoc(TL.getLBracketLoc());
3780 NewTL.setRBracketLoc(TL.getRBracketLoc());
3781 NewTL.setSizeExpr(Size);
3782
3783 return Result;
3784}
3785
3786template<typename Derived>
3787QualType
3788TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003789 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003790 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003791 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3792 if (ElementType.isNull())
3793 return QualType();
3794
Richard Smithf6702a32011-12-20 02:08:33 +00003795 // Array bounds are constant expressions.
3796 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3797 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003798
John McCall3b657512011-01-19 10:06:00 +00003799 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3800 Expr *origSize = TL.getSizeExpr();
3801 if (!origSize) origSize = T->getSizeExpr();
3802
3803 ExprResult sizeResult
3804 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003805 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003806 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003807 return QualType();
3808
John McCall3b657512011-01-19 10:06:00 +00003809 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003810
3811 QualType Result = TL.getType();
3812 if (getDerived().AlwaysRebuild() ||
3813 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003814 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003815 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3816 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003817 size,
John McCalla2becad2009-10-21 00:40:46 +00003818 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003819 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003820 if (Result.isNull())
3821 return QualType();
3822 }
John McCalla2becad2009-10-21 00:40:46 +00003823
3824 // We might have any sort of array type now, but fortunately they
3825 // all have the same location layout.
3826 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3827 NewTL.setLBracketLoc(TL.getLBracketLoc());
3828 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003829 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003830
3831 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003832}
Mike Stump1eb44332009-09-09 15:08:12 +00003833
3834template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003835QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003836 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003837 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003838 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003839
3840 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003841 QualType ElementType = getDerived().TransformType(T->getElementType());
3842 if (ElementType.isNull())
3843 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003844
Richard Smithf6702a32011-12-20 02:08:33 +00003845 // Vector sizes are constant expressions.
3846 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3847 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003848
John McCall60d7b3a2010-08-24 06:29:42 +00003849 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003850 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003851 if (Size.isInvalid())
3852 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003853
John McCalla2becad2009-10-21 00:40:46 +00003854 QualType Result = TL.getType();
3855 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003856 ElementType != T->getElementType() ||
3857 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003858 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003859 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003860 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003861 if (Result.isNull())
3862 return QualType();
3863 }
John McCalla2becad2009-10-21 00:40:46 +00003864
3865 // Result might be dependent or not.
3866 if (isa<DependentSizedExtVectorType>(Result)) {
3867 DependentSizedExtVectorTypeLoc NewTL
3868 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3869 NewTL.setNameLoc(TL.getNameLoc());
3870 } else {
3871 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3872 NewTL.setNameLoc(TL.getNameLoc());
3873 }
3874
3875 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003876}
Mike Stump1eb44332009-09-09 15:08:12 +00003877
3878template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003879QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003880 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003881 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003882 QualType ElementType = getDerived().TransformType(T->getElementType());
3883 if (ElementType.isNull())
3884 return QualType();
3885
John McCalla2becad2009-10-21 00:40:46 +00003886 QualType Result = TL.getType();
3887 if (getDerived().AlwaysRebuild() ||
3888 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003889 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003890 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003891 if (Result.isNull())
3892 return QualType();
3893 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003894
John McCalla2becad2009-10-21 00:40:46 +00003895 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3896 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003897
John McCalla2becad2009-10-21 00:40:46 +00003898 return Result;
3899}
3900
3901template<typename Derived>
3902QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003903 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003904 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003905 QualType ElementType = getDerived().TransformType(T->getElementType());
3906 if (ElementType.isNull())
3907 return QualType();
3908
3909 QualType Result = TL.getType();
3910 if (getDerived().AlwaysRebuild() ||
3911 ElementType != T->getElementType()) {
3912 Result = getDerived().RebuildExtVectorType(ElementType,
3913 T->getNumElements(),
3914 /*FIXME*/ SourceLocation());
3915 if (Result.isNull())
3916 return QualType();
3917 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003918
John McCalla2becad2009-10-21 00:40:46 +00003919 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3920 NewTL.setNameLoc(TL.getNameLoc());
3921
3922 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003923}
Mike Stump1eb44332009-09-09 15:08:12 +00003924
3925template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003926ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003927TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003928 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003929 llvm::Optional<unsigned> NumExpansions,
3930 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003931 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003932 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003933
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003934 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003935 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003936 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003937 TypeLoc OldTL = OldDI->getTypeLoc();
3938 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003939
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003940 TypeLocBuilder TLB;
3941 TypeLoc NewTL = OldDI->getTypeLoc();
3942 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003943
3944 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003945 OldExpansionTL.getPatternLoc());
3946 if (Result.isNull())
3947 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003948
3949 Result = RebuildPackExpansionType(Result,
3950 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003951 OldExpansionTL.getEllipsisLoc(),
3952 NumExpansions);
3953 if (Result.isNull())
3954 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003955
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003956 PackExpansionTypeLoc NewExpansionTL
3957 = TLB.push<PackExpansionTypeLoc>(Result);
3958 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3959 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3960 } else
3961 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003962 if (!NewDI)
3963 return 0;
3964
John McCallfb44de92011-05-01 22:35:37 +00003965 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003966 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003967
3968 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3969 OldParm->getDeclContext(),
3970 OldParm->getInnerLocStart(),
3971 OldParm->getLocation(),
3972 OldParm->getIdentifier(),
3973 NewDI->getType(),
3974 NewDI,
3975 OldParm->getStorageClass(),
3976 OldParm->getStorageClassAsWritten(),
3977 /* DefArg */ NULL);
3978 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3979 OldParm->getFunctionScopeIndex() + indexAdjustment);
3980 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003981}
3982
3983template<typename Derived>
3984bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003985 TransformFunctionTypeParams(SourceLocation Loc,
3986 ParmVarDecl **Params, unsigned NumParams,
3987 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003988 SmallVectorImpl<QualType> &OutParamTypes,
3989 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003990 int indexAdjustment = 0;
3991
Douglas Gregora009b592011-01-07 00:20:55 +00003992 for (unsigned i = 0; i != NumParams; ++i) {
3993 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003994 assert(OldParm->getFunctionScopeIndex() == i);
3995
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003996 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003997 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003998 if (OldParm->isParameterPack()) {
3999 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004000 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004001
Douglas Gregor603cfb42011-01-05 23:12:31 +00004002 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004003 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
4004 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
4005 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4006 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004007 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4008
Douglas Gregor603cfb42011-01-05 23:12:31 +00004009 // Determine whether we should expand the parameter packs.
4010 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004011 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004012 llvm::Optional<unsigned> OrigNumExpansions
4013 = ExpansionTL.getTypePtr()->getNumExpansions();
4014 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004015 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4016 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004017 Unexpanded,
4018 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004019 RetainExpansion,
4020 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004021 return true;
4022 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004023
Douglas Gregor603cfb42011-01-05 23:12:31 +00004024 if (ShouldExpand) {
4025 // Expand the function parameter pack into multiple, separate
4026 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004027 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004028 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004029 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004030 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004031 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004032 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004033 OrigNumExpansions,
4034 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004035 if (!NewParm)
4036 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004037
Douglas Gregora009b592011-01-07 00:20:55 +00004038 OutParamTypes.push_back(NewParm->getType());
4039 if (PVars)
4040 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004041 }
Douglas Gregord3731192011-01-10 07:32:04 +00004042
4043 // If we're supposed to retain a pack expansion, do so by temporarily
4044 // forgetting the partially-substituted parameter pack.
4045 if (RetainExpansion) {
4046 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004047 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004048 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004049 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004050 OrigNumExpansions,
4051 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004052 if (!NewParm)
4053 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004054
Douglas Gregord3731192011-01-10 07:32:04 +00004055 OutParamTypes.push_back(NewParm->getType());
4056 if (PVars)
4057 PVars->push_back(NewParm);
4058 }
4059
John McCallfb44de92011-05-01 22:35:37 +00004060 // The next parameter should have the same adjustment as the
4061 // last thing we pushed, but we post-incremented indexAdjustment
4062 // on every push. Also, if we push nothing, the adjustment should
4063 // go down by one.
4064 indexAdjustment--;
4065
Douglas Gregor603cfb42011-01-05 23:12:31 +00004066 // We're done with the pack expansion.
4067 continue;
4068 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004069
4070 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004071 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004072 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4073 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004074 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004075 NumExpansions,
4076 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004077 } else {
4078 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004079 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004080 llvm::Optional<unsigned>(),
4081 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004082 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004083
John McCall21ef0fa2010-03-11 09:03:00 +00004084 if (!NewParm)
4085 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004086
Douglas Gregora009b592011-01-07 00:20:55 +00004087 OutParamTypes.push_back(NewParm->getType());
4088 if (PVars)
4089 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004090 continue;
4091 }
John McCall21ef0fa2010-03-11 09:03:00 +00004092
4093 // Deal with the possibility that we don't have a parameter
4094 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004095 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004096 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004097 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004098 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004099 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004100 = dyn_cast<PackExpansionType>(OldType)) {
4101 // We have a function parameter pack that may need to be expanded.
4102 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004103 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004104 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004105
Douglas Gregor603cfb42011-01-05 23:12:31 +00004106 // Determine whether we should expand the parameter packs.
4107 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004108 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004109 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004110 Unexpanded,
4111 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004112 RetainExpansion,
4113 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004114 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004115 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004116
Douglas Gregor603cfb42011-01-05 23:12:31 +00004117 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004118 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004119 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004120 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004121 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4122 QualType NewType = getDerived().TransformType(Pattern);
4123 if (NewType.isNull())
4124 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004125
Douglas Gregora009b592011-01-07 00:20:55 +00004126 OutParamTypes.push_back(NewType);
4127 if (PVars)
4128 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004129 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004130
Douglas Gregor603cfb42011-01-05 23:12:31 +00004131 // We're done with the pack expansion.
4132 continue;
4133 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004134
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004135 // If we're supposed to retain a pack expansion, do so by temporarily
4136 // forgetting the partially-substituted parameter pack.
4137 if (RetainExpansion) {
4138 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4139 QualType NewType = getDerived().TransformType(Pattern);
4140 if (NewType.isNull())
4141 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004142
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004143 OutParamTypes.push_back(NewType);
4144 if (PVars)
4145 PVars->push_back(0);
4146 }
Douglas Gregord3731192011-01-10 07:32:04 +00004147
Chad Rosier4a9d7952012-08-08 18:46:20 +00004148 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004149 // expansion.
4150 OldType = Expansion->getPattern();
4151 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004152 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4153 NewType = getDerived().TransformType(OldType);
4154 } else {
4155 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004156 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004157
Douglas Gregor603cfb42011-01-05 23:12:31 +00004158 if (NewType.isNull())
4159 return true;
4160
4161 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004162 NewType = getSema().Context.getPackExpansionType(NewType,
4163 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004164
Douglas Gregora009b592011-01-07 00:20:55 +00004165 OutParamTypes.push_back(NewType);
4166 if (PVars)
4167 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004168 }
4169
John McCallfb44de92011-05-01 22:35:37 +00004170#ifndef NDEBUG
4171 if (PVars) {
4172 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4173 if (ParmVarDecl *parm = (*PVars)[i])
4174 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004175 }
John McCallfb44de92011-05-01 22:35:37 +00004176#endif
4177
4178 return false;
4179}
John McCall21ef0fa2010-03-11 09:03:00 +00004180
4181template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004182QualType
John McCalla2becad2009-10-21 00:40:46 +00004183TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004184 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004185 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4186}
4187
4188template<typename Derived>
4189QualType
4190TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4191 FunctionProtoTypeLoc TL,
4192 CXXRecordDecl *ThisContext,
4193 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004194 // Transform the parameters and return type.
4195 //
Richard Smithe6975e92012-04-17 00:58:00 +00004196 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004197 // When the function has a trailing return type, we instantiate the
4198 // parameters before the return type, since the return type can then refer
4199 // to the parameters themselves (via decltype, sizeof, etc.).
4200 //
Chris Lattner686775d2011-07-20 06:58:45 +00004201 SmallVector<QualType, 4> ParamTypes;
4202 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004203 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004204
Douglas Gregordab60ad2010-10-01 18:44:50 +00004205 QualType ResultType;
4206
Richard Smith9fbf3272012-08-14 22:51:13 +00004207 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004208 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004209 TL.getParmArray(),
4210 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004211 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004212 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004213 return QualType();
4214
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004215 {
4216 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004217 // If a declaration declares a member function or member function
4218 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004219 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004220 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004221 // declarator.
4222 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004223
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004224 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4225 if (ResultType.isNull())
4226 return QualType();
4227 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004228 }
4229 else {
4230 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4231 if (ResultType.isNull())
4232 return QualType();
4233
Chad Rosier4a9d7952012-08-08 18:46:20 +00004234 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004235 TL.getParmArray(),
4236 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004237 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004238 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004239 return QualType();
4240 }
4241
Richard Smithe6975e92012-04-17 00:58:00 +00004242 // FIXME: Need to transform the exception-specification too.
4243
John McCalla2becad2009-10-21 00:40:46 +00004244 QualType Result = TL.getType();
4245 if (getDerived().AlwaysRebuild() ||
4246 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004247 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004248 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4249 Result = getDerived().RebuildFunctionProtoType(ResultType,
4250 ParamTypes.data(),
4251 ParamTypes.size(),
4252 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004253 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004254 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004255 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004256 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004257 if (Result.isNull())
4258 return QualType();
4259 }
Mike Stump1eb44332009-09-09 15:08:12 +00004260
John McCalla2becad2009-10-21 00:40:46 +00004261 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004262 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4263 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004264 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4265 NewTL.setArg(i, ParamDecls[i]);
4266
4267 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004268}
Mike Stump1eb44332009-09-09 15:08:12 +00004269
Douglas Gregor577f75a2009-08-04 16:50:30 +00004270template<typename Derived>
4271QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004272 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004273 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004274 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004275 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4276 if (ResultType.isNull())
4277 return QualType();
4278
4279 QualType Result = TL.getType();
4280 if (getDerived().AlwaysRebuild() ||
4281 ResultType != T->getResultType())
4282 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4283
4284 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004285 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4286 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004287
4288 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004289}
Mike Stump1eb44332009-09-09 15:08:12 +00004290
John McCalled976492009-12-04 22:46:56 +00004291template<typename Derived> QualType
4292TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004293 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004294 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004295 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004296 if (!D)
4297 return QualType();
4298
4299 QualType Result = TL.getType();
4300 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4301 Result = getDerived().RebuildUnresolvedUsingType(D);
4302 if (Result.isNull())
4303 return QualType();
4304 }
4305
4306 // We might get an arbitrary type spec type back. We should at
4307 // least always get a type spec type, though.
4308 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4309 NewTL.setNameLoc(TL.getNameLoc());
4310
4311 return Result;
4312}
4313
Douglas Gregor577f75a2009-08-04 16:50:30 +00004314template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004315QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004316 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004317 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004318 TypedefNameDecl *Typedef
4319 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4320 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004321 if (!Typedef)
4322 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004323
John McCalla2becad2009-10-21 00:40:46 +00004324 QualType Result = TL.getType();
4325 if (getDerived().AlwaysRebuild() ||
4326 Typedef != T->getDecl()) {
4327 Result = getDerived().RebuildTypedefType(Typedef);
4328 if (Result.isNull())
4329 return QualType();
4330 }
Mike Stump1eb44332009-09-09 15:08:12 +00004331
John McCalla2becad2009-10-21 00:40:46 +00004332 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4333 NewTL.setNameLoc(TL.getNameLoc());
4334
4335 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004336}
Mike Stump1eb44332009-09-09 15:08:12 +00004337
Douglas Gregor577f75a2009-08-04 16:50:30 +00004338template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004339QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004340 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004341 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004342 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004343
John McCall60d7b3a2010-08-24 06:29:42 +00004344 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004345 if (E.isInvalid())
4346 return QualType();
4347
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004348 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4349 if (E.isInvalid())
4350 return QualType();
4351
John McCalla2becad2009-10-21 00:40:46 +00004352 QualType Result = TL.getType();
4353 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004354 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004355 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004356 if (Result.isNull())
4357 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004358 }
John McCalla2becad2009-10-21 00:40:46 +00004359 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004360
John McCalla2becad2009-10-21 00:40:46 +00004361 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004362 NewTL.setTypeofLoc(TL.getTypeofLoc());
4363 NewTL.setLParenLoc(TL.getLParenLoc());
4364 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004365
4366 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004367}
Mike Stump1eb44332009-09-09 15:08:12 +00004368
4369template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004370QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004371 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004372 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4373 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4374 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004375 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004376
John McCalla2becad2009-10-21 00:40:46 +00004377 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004378 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4379 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004380 if (Result.isNull())
4381 return QualType();
4382 }
Mike Stump1eb44332009-09-09 15:08:12 +00004383
John McCalla2becad2009-10-21 00:40:46 +00004384 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004385 NewTL.setTypeofLoc(TL.getTypeofLoc());
4386 NewTL.setLParenLoc(TL.getLParenLoc());
4387 NewTL.setRParenLoc(TL.getRParenLoc());
4388 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004389
4390 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004391}
Mike Stump1eb44332009-09-09 15:08:12 +00004392
4393template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004394QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004395 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004396 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004397
Douglas Gregor670444e2009-08-04 22:27:00 +00004398 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004399 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4400 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004401
John McCall60d7b3a2010-08-24 06:29:42 +00004402 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004403 if (E.isInvalid())
4404 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004405
Richard Smith76f3f692012-02-22 02:04:18 +00004406 E = getSema().ActOnDecltypeExpression(E.take());
4407 if (E.isInvalid())
4408 return QualType();
4409
John McCalla2becad2009-10-21 00:40:46 +00004410 QualType Result = TL.getType();
4411 if (getDerived().AlwaysRebuild() ||
4412 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004413 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004414 if (Result.isNull())
4415 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004416 }
John McCalla2becad2009-10-21 00:40:46 +00004417 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004418
John McCalla2becad2009-10-21 00:40:46 +00004419 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4420 NewTL.setNameLoc(TL.getNameLoc());
4421
4422 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004423}
4424
4425template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004426QualType TreeTransform<Derived>::TransformUnaryTransformType(
4427 TypeLocBuilder &TLB,
4428 UnaryTransformTypeLoc TL) {
4429 QualType Result = TL.getType();
4430 if (Result->isDependentType()) {
4431 const UnaryTransformType *T = TL.getTypePtr();
4432 QualType NewBase =
4433 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4434 Result = getDerived().RebuildUnaryTransformType(NewBase,
4435 T->getUTTKind(),
4436 TL.getKWLoc());
4437 if (Result.isNull())
4438 return QualType();
4439 }
4440
4441 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4442 NewTL.setKWLoc(TL.getKWLoc());
4443 NewTL.setParensRange(TL.getParensRange());
4444 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4445 return Result;
4446}
4447
4448template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004449QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4450 AutoTypeLoc TL) {
4451 const AutoType *T = TL.getTypePtr();
4452 QualType OldDeduced = T->getDeducedType();
4453 QualType NewDeduced;
4454 if (!OldDeduced.isNull()) {
4455 NewDeduced = getDerived().TransformType(OldDeduced);
4456 if (NewDeduced.isNull())
4457 return QualType();
4458 }
4459
4460 QualType Result = TL.getType();
4461 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4462 Result = getDerived().RebuildAutoType(NewDeduced);
4463 if (Result.isNull())
4464 return QualType();
4465 }
4466
4467 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4468 NewTL.setNameLoc(TL.getNameLoc());
4469
4470 return Result;
4471}
4472
4473template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004474QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004475 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004476 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004477 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004478 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4479 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004480 if (!Record)
4481 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004482
John McCalla2becad2009-10-21 00:40:46 +00004483 QualType Result = TL.getType();
4484 if (getDerived().AlwaysRebuild() ||
4485 Record != T->getDecl()) {
4486 Result = getDerived().RebuildRecordType(Record);
4487 if (Result.isNull())
4488 return QualType();
4489 }
Mike Stump1eb44332009-09-09 15:08:12 +00004490
John McCalla2becad2009-10-21 00:40:46 +00004491 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4492 NewTL.setNameLoc(TL.getNameLoc());
4493
4494 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004495}
Mike Stump1eb44332009-09-09 15:08:12 +00004496
4497template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004498QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004499 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004500 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004501 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004502 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4503 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004504 if (!Enum)
4505 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004506
John McCalla2becad2009-10-21 00:40:46 +00004507 QualType Result = TL.getType();
4508 if (getDerived().AlwaysRebuild() ||
4509 Enum != T->getDecl()) {
4510 Result = getDerived().RebuildEnumType(Enum);
4511 if (Result.isNull())
4512 return QualType();
4513 }
Mike Stump1eb44332009-09-09 15:08:12 +00004514
John McCalla2becad2009-10-21 00:40:46 +00004515 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4516 NewTL.setNameLoc(TL.getNameLoc());
4517
4518 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004519}
John McCall7da24312009-09-05 00:15:47 +00004520
John McCall3cb0ebd2010-03-10 03:28:59 +00004521template<typename Derived>
4522QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4523 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004524 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004525 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4526 TL.getTypePtr()->getDecl());
4527 if (!D) return QualType();
4528
4529 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4530 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4531 return T;
4532}
4533
Douglas Gregor577f75a2009-08-04 16:50:30 +00004534template<typename Derived>
4535QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004536 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004537 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004538 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004539}
4540
Mike Stump1eb44332009-09-09 15:08:12 +00004541template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004542QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004543 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004544 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004545 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004546
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004547 // Substitute into the replacement type, which itself might involve something
4548 // that needs to be transformed. This only tends to occur with default
4549 // template arguments of template template parameters.
4550 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4551 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4552 if (Replacement.isNull())
4553 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004554
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004555 // Always canonicalize the replacement type.
4556 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4557 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004558 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004559 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004560
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004561 // Propagate type-source information.
4562 SubstTemplateTypeParmTypeLoc NewTL
4563 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4564 NewTL.setNameLoc(TL.getNameLoc());
4565 return Result;
4566
John McCall49a832b2009-10-18 09:09:24 +00004567}
4568
4569template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004570QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4571 TypeLocBuilder &TLB,
4572 SubstTemplateTypeParmPackTypeLoc TL) {
4573 return TransformTypeSpecType(TLB, TL);
4574}
4575
4576template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004577QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004578 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004579 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004580 const TemplateSpecializationType *T = TL.getTypePtr();
4581
Douglas Gregor1d752d72011-03-02 18:46:51 +00004582 // The nested-name-specifier never matters in a TemplateSpecializationType,
4583 // because we can't have a dependent nested-name-specifier anyway.
4584 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004585 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004586 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4587 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004588 if (Template.isNull())
4589 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004590
John McCall43fed0d2010-11-12 08:19:04 +00004591 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4592}
4593
Eli Friedmanb001de72011-10-06 23:00:33 +00004594template<typename Derived>
4595QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4596 AtomicTypeLoc TL) {
4597 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4598 if (ValueType.isNull())
4599 return QualType();
4600
4601 QualType Result = TL.getType();
4602 if (getDerived().AlwaysRebuild() ||
4603 ValueType != TL.getValueLoc().getType()) {
4604 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4605 if (Result.isNull())
4606 return QualType();
4607 }
4608
4609 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4610 NewTL.setKWLoc(TL.getKWLoc());
4611 NewTL.setLParenLoc(TL.getLParenLoc());
4612 NewTL.setRParenLoc(TL.getRParenLoc());
4613
4614 return Result;
4615}
4616
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004617namespace {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004618 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004619 /// container that provides a \c getArgLoc() member function.
4620 ///
4621 /// This iterator is intended to be used with the iterator form of
4622 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4623 template<typename ArgLocContainer>
4624 class TemplateArgumentLocContainerIterator {
4625 ArgLocContainer *Container;
4626 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004627
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004628 public:
4629 typedef TemplateArgumentLoc value_type;
4630 typedef TemplateArgumentLoc reference;
4631 typedef int difference_type;
4632 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004633
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004634 class pointer {
4635 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004636
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004637 public:
4638 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004639
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004640 const TemplateArgumentLoc *operator->() const {
4641 return &Arg;
4642 }
4643 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004644
4645
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004646 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004647
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004648 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4649 unsigned Index)
4650 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004651
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004652 TemplateArgumentLocContainerIterator &operator++() {
4653 ++Index;
4654 return *this;
4655 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004656
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004657 TemplateArgumentLocContainerIterator operator++(int) {
4658 TemplateArgumentLocContainerIterator Old(*this);
4659 ++(*this);
4660 return Old;
4661 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004662
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004663 TemplateArgumentLoc operator*() const {
4664 return Container->getArgLoc(Index);
4665 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004666
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004667 pointer operator->() const {
4668 return pointer(Container->getArgLoc(Index));
4669 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004670
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004671 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004672 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004673 return X.Container == Y.Container && X.Index == Y.Index;
4674 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004675
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004676 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004677 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004678 return !(X == Y);
4679 }
4680 };
4681}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004682
4683
John McCall43fed0d2010-11-12 08:19:04 +00004684template <typename Derived>
4685QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4686 TypeLocBuilder &TLB,
4687 TemplateSpecializationTypeLoc TL,
4688 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004689 TemplateArgumentListInfo NewTemplateArgs;
4690 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4691 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004692 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4693 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004694 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004695 ArgIterator(TL, TL.getNumArgs()),
4696 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004697 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004698
John McCall833ca992009-10-29 08:12:44 +00004699 // FIXME: maybe don't rebuild if all the template arguments are the same.
4700
4701 QualType Result =
4702 getDerived().RebuildTemplateSpecializationType(Template,
4703 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004704 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004705
4706 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004707 // Specializations of template template parameters are represented as
4708 // TemplateSpecializationTypes, and substitution of type alias templates
4709 // within a dependent context can transform them into
4710 // DependentTemplateSpecializationTypes.
4711 if (isa<DependentTemplateSpecializationType>(Result)) {
4712 DependentTemplateSpecializationTypeLoc NewTL
4713 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004714 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004715 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004716 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004717 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004718 NewTL.setLAngleLoc(TL.getLAngleLoc());
4719 NewTL.setRAngleLoc(TL.getRAngleLoc());
4720 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4721 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4722 return Result;
4723 }
4724
John McCall833ca992009-10-29 08:12:44 +00004725 TemplateSpecializationTypeLoc NewTL
4726 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004727 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004728 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4729 NewTL.setLAngleLoc(TL.getLAngleLoc());
4730 NewTL.setRAngleLoc(TL.getRAngleLoc());
4731 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4732 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004733 }
Mike Stump1eb44332009-09-09 15:08:12 +00004734
John McCall833ca992009-10-29 08:12:44 +00004735 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004736}
Mike Stump1eb44332009-09-09 15:08:12 +00004737
Douglas Gregora88f09f2011-02-28 17:23:35 +00004738template <typename Derived>
4739QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4740 TypeLocBuilder &TLB,
4741 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004742 TemplateName Template,
4743 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004744 TemplateArgumentListInfo NewTemplateArgs;
4745 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4746 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4747 typedef TemplateArgumentLocContainerIterator<
4748 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004749 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004750 ArgIterator(TL, TL.getNumArgs()),
4751 NewTemplateArgs))
4752 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004753
Douglas Gregora88f09f2011-02-28 17:23:35 +00004754 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004755
Douglas Gregora88f09f2011-02-28 17:23:35 +00004756 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4757 QualType Result
4758 = getSema().Context.getDependentTemplateSpecializationType(
4759 TL.getTypePtr()->getKeyword(),
4760 DTN->getQualifier(),
4761 DTN->getIdentifier(),
4762 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004763
Douglas Gregora88f09f2011-02-28 17:23:35 +00004764 DependentTemplateSpecializationTypeLoc NewTL
4765 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004766 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004767 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004768 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004769 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004770 NewTL.setLAngleLoc(TL.getLAngleLoc());
4771 NewTL.setRAngleLoc(TL.getRAngleLoc());
4772 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4773 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4774 return Result;
4775 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004776
4777 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004778 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004779 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004780 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004781
Douglas Gregora88f09f2011-02-28 17:23:35 +00004782 if (!Result.isNull()) {
4783 /// FIXME: Wrap this in an elaborated-type-specifier?
4784 TemplateSpecializationTypeLoc NewTL
4785 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004786 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004787 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004788 NewTL.setLAngleLoc(TL.getLAngleLoc());
4789 NewTL.setRAngleLoc(TL.getRAngleLoc());
4790 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4791 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4792 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004793
Douglas Gregora88f09f2011-02-28 17:23:35 +00004794 return Result;
4795}
4796
Mike Stump1eb44332009-09-09 15:08:12 +00004797template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004798QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004799TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004800 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004801 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004802
Douglas Gregor9e876872011-03-01 18:12:44 +00004803 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004804 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004805 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004806 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004807 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4808 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004809 return QualType();
4810 }
Mike Stump1eb44332009-09-09 15:08:12 +00004811
John McCall43fed0d2010-11-12 08:19:04 +00004812 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4813 if (NamedT.isNull())
4814 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004815
Richard Smith3e4c6c42011-05-05 21:57:07 +00004816 // C++0x [dcl.type.elab]p2:
4817 // If the identifier resolves to a typedef-name or the simple-template-id
4818 // resolves to an alias template specialization, the
4819 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004820 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4821 if (const TemplateSpecializationType *TST =
4822 NamedT->getAs<TemplateSpecializationType>()) {
4823 TemplateName Template = TST->getTemplateName();
4824 if (TypeAliasTemplateDecl *TAT =
4825 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4826 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4827 diag::err_tag_reference_non_tag) << 4;
4828 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4829 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004830 }
4831 }
4832
John McCalla2becad2009-10-21 00:40:46 +00004833 QualType Result = TL.getType();
4834 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004835 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004836 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004837 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004838 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004839 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004840 if (Result.isNull())
4841 return QualType();
4842 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004843
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004844 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004845 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004846 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004847 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004848}
Mike Stump1eb44332009-09-09 15:08:12 +00004849
4850template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004851QualType TreeTransform<Derived>::TransformAttributedType(
4852 TypeLocBuilder &TLB,
4853 AttributedTypeLoc TL) {
4854 const AttributedType *oldType = TL.getTypePtr();
4855 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4856 if (modifiedType.isNull())
4857 return QualType();
4858
4859 QualType result = TL.getType();
4860
4861 // FIXME: dependent operand expressions?
4862 if (getDerived().AlwaysRebuild() ||
4863 modifiedType != oldType->getModifiedType()) {
4864 // TODO: this is really lame; we should really be rebuilding the
4865 // equivalent type from first principles.
4866 QualType equivalentType
4867 = getDerived().TransformType(oldType->getEquivalentType());
4868 if (equivalentType.isNull())
4869 return QualType();
4870 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4871 modifiedType,
4872 equivalentType);
4873 }
4874
4875 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4876 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4877 if (TL.hasAttrOperand())
4878 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4879 if (TL.hasAttrExprOperand())
4880 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4881 else if (TL.hasAttrEnumOperand())
4882 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4883
4884 return result;
4885}
4886
4887template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004888QualType
4889TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4890 ParenTypeLoc TL) {
4891 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4892 if (Inner.isNull())
4893 return QualType();
4894
4895 QualType Result = TL.getType();
4896 if (getDerived().AlwaysRebuild() ||
4897 Inner != TL.getInnerLoc().getType()) {
4898 Result = getDerived().RebuildParenType(Inner);
4899 if (Result.isNull())
4900 return QualType();
4901 }
4902
4903 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4904 NewTL.setLParenLoc(TL.getLParenLoc());
4905 NewTL.setRParenLoc(TL.getRParenLoc());
4906 return Result;
4907}
4908
4909template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004910QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004911 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004912 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004913
Douglas Gregor2494dd02011-03-01 01:34:45 +00004914 NestedNameSpecifierLoc QualifierLoc
4915 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4916 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004917 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004918
John McCall33500952010-06-11 00:33:02 +00004919 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004920 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004921 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004922 QualifierLoc,
4923 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004924 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004925 if (Result.isNull())
4926 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004927
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004928 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4929 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004930 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4931
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004932 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004933 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004934 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004935 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004936 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004937 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004938 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004939 NewTL.setNameLoc(TL.getNameLoc());
4940 }
John McCalla2becad2009-10-21 00:40:46 +00004941 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004942}
Mike Stump1eb44332009-09-09 15:08:12 +00004943
Douglas Gregor577f75a2009-08-04 16:50:30 +00004944template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004945QualType TreeTransform<Derived>::
4946 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004947 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004948 NestedNameSpecifierLoc QualifierLoc;
4949 if (TL.getQualifierLoc()) {
4950 QualifierLoc
4951 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4952 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004953 return QualType();
4954 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004955
John McCall43fed0d2010-11-12 08:19:04 +00004956 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004957 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004958}
4959
4960template<typename Derived>
4961QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004962TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4963 DependentTemplateSpecializationTypeLoc TL,
4964 NestedNameSpecifierLoc QualifierLoc) {
4965 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004966
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004967 TemplateArgumentListInfo NewTemplateArgs;
4968 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4969 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004970
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004971 typedef TemplateArgumentLocContainerIterator<
4972 DependentTemplateSpecializationTypeLoc> ArgIterator;
4973 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4974 ArgIterator(TL, TL.getNumArgs()),
4975 NewTemplateArgs))
4976 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004977
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004978 QualType Result
4979 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4980 QualifierLoc,
4981 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004982 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004983 NewTemplateArgs);
4984 if (Result.isNull())
4985 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004986
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004987 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4988 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004989
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004990 // Copy information relevant to the template specialization.
4991 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004992 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004993 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004994 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004995 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4996 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004997 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004998 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004999
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005000 // Copy information relevant to the elaborated type.
5001 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005002 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005003 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005004 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5005 DependentTemplateSpecializationTypeLoc SpecTL
5006 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005007 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005008 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005009 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005010 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005011 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5012 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005013 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005014 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005015 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005016 TemplateSpecializationTypeLoc SpecTL
5017 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005018 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005019 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005020 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5021 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005022 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005023 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005024 }
5025 return Result;
5026}
5027
5028template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005029QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5030 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005031 QualType Pattern
5032 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005033 if (Pattern.isNull())
5034 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005035
5036 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005037 if (getDerived().AlwaysRebuild() ||
5038 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005039 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005040 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005041 TL.getEllipsisLoc(),
5042 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005043 if (Result.isNull())
5044 return QualType();
5045 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005046
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005047 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5048 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5049 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005050}
5051
5052template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005053QualType
5054TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005055 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005056 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005057 TLB.pushFullCopy(TL);
5058 return TL.getType();
5059}
5060
5061template<typename Derived>
5062QualType
5063TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005064 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005065 // ObjCObjectType is never dependent.
5066 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005067 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005068}
Mike Stump1eb44332009-09-09 15:08:12 +00005069
5070template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005071QualType
5072TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005073 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005074 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005075 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005076 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005077}
5078
Douglas Gregor577f75a2009-08-04 16:50:30 +00005079//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005080// Statement transformation
5081//===----------------------------------------------------------------------===//
5082template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005083StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005084TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005085 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005086}
5087
5088template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005089StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005090TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5091 return getDerived().TransformCompoundStmt(S, false);
5092}
5093
5094template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005095StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005096TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005097 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005098 Sema::CompoundScopeRAII CompoundScope(getSema());
5099
John McCall7114cba2010-08-27 19:56:05 +00005100 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005101 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005102 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00005103 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5104 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005105 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005106 if (Result.isInvalid()) {
5107 // Immediately fail if this was a DeclStmt, since it's very
5108 // likely that this will cause problems for future statements.
5109 if (isa<DeclStmt>(*B))
5110 return StmtError();
5111
5112 // Otherwise, just keep processing substatements and fail later.
5113 SubStmtInvalid = true;
5114 continue;
5115 }
Mike Stump1eb44332009-09-09 15:08:12 +00005116
Douglas Gregor43959a92009-08-20 07:17:43 +00005117 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5118 Statements.push_back(Result.takeAs<Stmt>());
5119 }
Mike Stump1eb44332009-09-09 15:08:12 +00005120
John McCall7114cba2010-08-27 19:56:05 +00005121 if (SubStmtInvalid)
5122 return StmtError();
5123
Douglas Gregor43959a92009-08-20 07:17:43 +00005124 if (!getDerived().AlwaysRebuild() &&
5125 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005126 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005127
5128 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
5129 move_arg(Statements),
5130 S->getRBracLoc(),
5131 IsStmtExpr);
5132}
Mike Stump1eb44332009-09-09 15:08:12 +00005133
Douglas Gregor43959a92009-08-20 07:17:43 +00005134template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005135StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005136TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005137 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005138 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005139 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5140 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005141
Eli Friedman264c1f82009-11-19 03:14:00 +00005142 // Transform the left-hand case value.
5143 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005144 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005145 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005146 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005147
Eli Friedman264c1f82009-11-19 03:14:00 +00005148 // Transform the right-hand case value (for the GNU case-range extension).
5149 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005150 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005151 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005152 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005153 }
Mike Stump1eb44332009-09-09 15:08:12 +00005154
Douglas Gregor43959a92009-08-20 07:17:43 +00005155 // Build the case statement.
5156 // Case statements are always rebuilt so that they will attached to their
5157 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005158 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005159 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005160 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005161 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005162 S->getColonLoc());
5163 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005164 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005165
Douglas Gregor43959a92009-08-20 07:17:43 +00005166 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005167 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005168 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005169 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005170
Douglas Gregor43959a92009-08-20 07:17:43 +00005171 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005172 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005173}
5174
5175template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005176StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005177TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005178 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005179 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005180 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005181 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005182
Douglas Gregor43959a92009-08-20 07:17:43 +00005183 // Default statements are always rebuilt
5184 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005185 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005186}
Mike Stump1eb44332009-09-09 15:08:12 +00005187
Douglas Gregor43959a92009-08-20 07:17:43 +00005188template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005189StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005190TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005191 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005192 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005193 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005194
Chris Lattner57ad3782011-02-17 20:34:02 +00005195 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5196 S->getDecl());
5197 if (!LD)
5198 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005199
5200
Douglas Gregor43959a92009-08-20 07:17:43 +00005201 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005202 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005203 cast<LabelDecl>(LD), SourceLocation(),
5204 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005205}
Mike Stump1eb44332009-09-09 15:08:12 +00005206
Douglas Gregor43959a92009-08-20 07:17:43 +00005207template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005208StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005209TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5210 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5211 if (SubStmt.isInvalid())
5212 return StmtError();
5213
5214 // TODO: transform attributes
5215 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5216 return S;
5217
5218 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5219 S->getAttrs(),
5220 SubStmt.get());
5221}
5222
5223template<typename Derived>
5224StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005225TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005226 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005227 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005228 VarDecl *ConditionVar = 0;
5229 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005230 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005231 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005232 getDerived().TransformDefinition(
5233 S->getConditionVariable()->getLocation(),
5234 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005235 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005236 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005237 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005238 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005239
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005240 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005241 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005242
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005243 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005244 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005245 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005246 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005247 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005248 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005249
John McCall9ae2f072010-08-23 23:25:46 +00005250 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005251 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005252 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005253
John McCall9ae2f072010-08-23 23:25:46 +00005254 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5255 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005256 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005257
Douglas Gregor43959a92009-08-20 07:17:43 +00005258 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005259 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005260 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005261 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005262
Douglas Gregor43959a92009-08-20 07:17:43 +00005263 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005264 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005265 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005266 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005267
Douglas Gregor43959a92009-08-20 07:17:43 +00005268 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005269 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005270 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005271 Then.get() == S->getThen() &&
5272 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005273 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005274
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005275 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005276 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005277 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005278}
5279
5280template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005281StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005282TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005283 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005284 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005285 VarDecl *ConditionVar = 0;
5286 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005287 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005288 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005289 getDerived().TransformDefinition(
5290 S->getConditionVariable()->getLocation(),
5291 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005292 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005293 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005294 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005295 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005296
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005297 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005298 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005299 }
Mike Stump1eb44332009-09-09 15:08:12 +00005300
Douglas Gregor43959a92009-08-20 07:17:43 +00005301 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005302 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005303 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005304 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005305 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005306 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005307
Douglas Gregor43959a92009-08-20 07:17:43 +00005308 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005309 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005310 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005311 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005312
Douglas Gregor43959a92009-08-20 07:17:43 +00005313 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005314 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5315 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005316}
Mike Stump1eb44332009-09-09 15:08:12 +00005317
Douglas Gregor43959a92009-08-20 07:17:43 +00005318template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005319StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005320TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005321 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005322 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005323 VarDecl *ConditionVar = 0;
5324 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005325 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005326 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005327 getDerived().TransformDefinition(
5328 S->getConditionVariable()->getLocation(),
5329 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005330 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005331 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005332 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005333 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005334
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005335 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005336 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005337
5338 if (S->getCond()) {
5339 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005340 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005341 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005342 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005343 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005344 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005345 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005346 }
Mike Stump1eb44332009-09-09 15:08:12 +00005347
John McCall9ae2f072010-08-23 23:25:46 +00005348 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5349 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005350 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005351
Douglas Gregor43959a92009-08-20 07:17:43 +00005352 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005353 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005354 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005355 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005356
Douglas Gregor43959a92009-08-20 07:17:43 +00005357 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005358 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005359 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005360 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005361 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005362
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005363 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005364 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005365}
Mike Stump1eb44332009-09-09 15:08:12 +00005366
Douglas Gregor43959a92009-08-20 07:17:43 +00005367template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005368StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005369TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005370 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005371 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005372 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005373 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005374
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005375 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005376 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005377 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005378 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005379
Douglas Gregor43959a92009-08-20 07:17:43 +00005380 if (!getDerived().AlwaysRebuild() &&
5381 Cond.get() == S->getCond() &&
5382 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005383 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005384
John McCall9ae2f072010-08-23 23:25:46 +00005385 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5386 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005387 S->getRParenLoc());
5388}
Mike Stump1eb44332009-09-09 15:08:12 +00005389
Douglas Gregor43959a92009-08-20 07:17:43 +00005390template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005391StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005392TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005393 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005394 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005395 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005396 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005397
Douglas Gregor43959a92009-08-20 07:17:43 +00005398 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005399 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005400 VarDecl *ConditionVar = 0;
5401 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005402 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005403 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005404 getDerived().TransformDefinition(
5405 S->getConditionVariable()->getLocation(),
5406 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005407 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005408 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005409 } else {
5410 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005411
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005412 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005413 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005414
5415 if (S->getCond()) {
5416 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005417 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005418 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005419 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005420 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005421
John McCall9ae2f072010-08-23 23:25:46 +00005422 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005423 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005424 }
Mike Stump1eb44332009-09-09 15:08:12 +00005425
Chad Rosier4a9d7952012-08-08 18:46:20 +00005426 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005427 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005428 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005429
Douglas Gregor43959a92009-08-20 07:17:43 +00005430 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005431 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005432 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005433 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005434
John McCall9ae2f072010-08-23 23:25:46 +00005435 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5436 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005437 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005438
Douglas Gregor43959a92009-08-20 07:17:43 +00005439 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005440 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005441 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005442 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005443
Douglas Gregor43959a92009-08-20 07:17:43 +00005444 if (!getDerived().AlwaysRebuild() &&
5445 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005446 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005447 Inc.get() == S->getInc() &&
5448 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005449 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005450
Douglas Gregor43959a92009-08-20 07:17:43 +00005451 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005452 Init.get(), FullCond, ConditionVar,
5453 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005454}
5455
5456template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005457StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005458TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005459 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5460 S->getLabel());
5461 if (!LD)
5462 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005463
Douglas Gregor43959a92009-08-20 07:17:43 +00005464 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005465 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005466 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005467}
5468
5469template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005470StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005471TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005472 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005473 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005474 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005475 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005476
Douglas Gregor43959a92009-08-20 07:17:43 +00005477 if (!getDerived().AlwaysRebuild() &&
5478 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005479 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005480
5481 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005482 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005483}
5484
5485template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005486StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005487TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005488 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005489}
Mike Stump1eb44332009-09-09 15:08:12 +00005490
Douglas Gregor43959a92009-08-20 07:17:43 +00005491template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005492StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005493TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005494 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005495}
Mike Stump1eb44332009-09-09 15:08:12 +00005496
Douglas Gregor43959a92009-08-20 07:17:43 +00005497template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005498StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005499TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005500 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005501 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005502 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005503
Mike Stump1eb44332009-09-09 15:08:12 +00005504 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005505 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005506 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005507}
Mike Stump1eb44332009-09-09 15:08:12 +00005508
Douglas Gregor43959a92009-08-20 07:17:43 +00005509template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005510StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005511TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005512 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005513 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005514 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5515 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005516 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5517 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005518 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005519 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005520
Douglas Gregor43959a92009-08-20 07:17:43 +00005521 if (Transformed != *D)
5522 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005523
Douglas Gregor43959a92009-08-20 07:17:43 +00005524 Decls.push_back(Transformed);
5525 }
Mike Stump1eb44332009-09-09 15:08:12 +00005526
Douglas Gregor43959a92009-08-20 07:17:43 +00005527 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005528 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005529
5530 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005531 S->getStartLoc(), S->getEndLoc());
5532}
Mike Stump1eb44332009-09-09 15:08:12 +00005533
Douglas Gregor43959a92009-08-20 07:17:43 +00005534template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005535StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005536TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005537
John McCallca0408f2010-08-23 06:44:23 +00005538 ASTOwningVector<Expr*> Constraints(getSema());
5539 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005540 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005541
John McCall60d7b3a2010-08-24 06:29:42 +00005542 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005543 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005544
5545 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005546
Anders Carlsson703e3942010-01-24 05:50:09 +00005547 // Go through the outputs.
5548 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005549 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005550
Anders Carlsson703e3942010-01-24 05:50:09 +00005551 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005552 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005553
Anders Carlsson703e3942010-01-24 05:50:09 +00005554 // Transform the output expr.
5555 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005556 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005557 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005558 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005559
Anders Carlsson703e3942010-01-24 05:50:09 +00005560 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005561
John McCall9ae2f072010-08-23 23:25:46 +00005562 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005563 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005564
Anders Carlsson703e3942010-01-24 05:50:09 +00005565 // Go through the inputs.
5566 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005567 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005568
Anders Carlsson703e3942010-01-24 05:50:09 +00005569 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005570 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005571
Anders Carlsson703e3942010-01-24 05:50:09 +00005572 // Transform the input expr.
5573 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005574 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005575 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005576 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005577
Anders Carlsson703e3942010-01-24 05:50:09 +00005578 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005579
John McCall9ae2f072010-08-23 23:25:46 +00005580 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005581 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005582
Anders Carlsson703e3942010-01-24 05:50:09 +00005583 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005584 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005585
5586 // Go through the clobbers.
5587 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005588 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005589
5590 // No need to transform the asm string literal.
5591 AsmString = SemaRef.Owned(S->getAsmString());
5592
5593 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5594 S->isSimple(),
5595 S->isVolatile(),
5596 S->getNumOutputs(),
5597 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005598 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005599 move_arg(Constraints),
5600 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005601 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005602 move_arg(Clobbers),
5603 S->getRParenLoc(),
5604 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005605}
5606
Chad Rosier8cd64b42012-06-11 20:47:18 +00005607template<typename Derived>
5608StmtResult
5609TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005610 ArrayRef<Token> AsmToks =
5611 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005612
Chad Rosier92570bd2012-08-14 23:14:45 +00005613 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), AsmToks, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005614}
Douglas Gregor43959a92009-08-20 07:17:43 +00005615
5616template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005617StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005618TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005619 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005620 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005621 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005622 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005623
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005624 // Transform the @catch statements (if present).
5625 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005626 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005627 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005628 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005629 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005630 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005631 if (Catch.get() != S->getCatchStmt(I))
5632 AnyCatchChanged = true;
5633 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005634 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005635
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005636 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005637 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005638 if (S->getFinallyStmt()) {
5639 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5640 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005641 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005642 }
5643
5644 // If nothing changed, just retain this statement.
5645 if (!getDerived().AlwaysRebuild() &&
5646 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005647 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005648 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005649 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005650
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005651 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005652 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5653 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005654}
Mike Stump1eb44332009-09-09 15:08:12 +00005655
Douglas Gregor43959a92009-08-20 07:17:43 +00005656template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005657StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005658TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005659 // Transform the @catch parameter, if there is one.
5660 VarDecl *Var = 0;
5661 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5662 TypeSourceInfo *TSInfo = 0;
5663 if (FromVar->getTypeSourceInfo()) {
5664 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5665 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005666 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005667 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005668
Douglas Gregorbe270a02010-04-26 17:57:08 +00005669 QualType T;
5670 if (TSInfo)
5671 T = TSInfo->getType();
5672 else {
5673 T = getDerived().TransformType(FromVar->getType());
5674 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005675 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005676 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005677
Douglas Gregorbe270a02010-04-26 17:57:08 +00005678 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5679 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005680 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005681 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005682
John McCall60d7b3a2010-08-24 06:29:42 +00005683 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005684 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005685 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005686
5687 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005688 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005689 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005690}
Mike Stump1eb44332009-09-09 15:08:12 +00005691
Douglas Gregor43959a92009-08-20 07:17:43 +00005692template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005693StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005694TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005695 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005696 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005697 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005698 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005699
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005700 // If nothing changed, just retain this statement.
5701 if (!getDerived().AlwaysRebuild() &&
5702 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005703 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005704
5705 // Build a new statement.
5706 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005707 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005708}
Mike Stump1eb44332009-09-09 15:08:12 +00005709
Douglas Gregor43959a92009-08-20 07:17:43 +00005710template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005711StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005712TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005713 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005714 if (S->getThrowExpr()) {
5715 Operand = getDerived().TransformExpr(S->getThrowExpr());
5716 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005717 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005718 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005719
Douglas Gregord1377b22010-04-22 21:44:01 +00005720 if (!getDerived().AlwaysRebuild() &&
5721 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005722 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005723
John McCall9ae2f072010-08-23 23:25:46 +00005724 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005725}
Mike Stump1eb44332009-09-09 15:08:12 +00005726
Douglas Gregor43959a92009-08-20 07:17:43 +00005727template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005728StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005729TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005730 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005731 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005732 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005733 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005734 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005735 Object =
5736 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5737 Object.get());
5738 if (Object.isInvalid())
5739 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005740
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005741 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005742 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005743 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005744 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005745
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005746 // If nothing change, just retain the current statement.
5747 if (!getDerived().AlwaysRebuild() &&
5748 Object.get() == S->getSynchExpr() &&
5749 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005750 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005751
5752 // Build a new statement.
5753 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005754 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005755}
5756
5757template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005758StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005759TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5760 ObjCAutoreleasePoolStmt *S) {
5761 // Transform the body.
5762 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5763 if (Body.isInvalid())
5764 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005765
John McCallf85e1932011-06-15 23:02:42 +00005766 // If nothing changed, just retain this statement.
5767 if (!getDerived().AlwaysRebuild() &&
5768 Body.get() == S->getSubStmt())
5769 return SemaRef.Owned(S);
5770
5771 // Build a new statement.
5772 return getDerived().RebuildObjCAutoreleasePoolStmt(
5773 S->getAtLoc(), Body.get());
5774}
5775
5776template<typename Derived>
5777StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005778TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005779 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005780 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005781 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005782 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005783 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005784
Douglas Gregorc3203e72010-04-22 23:10:45 +00005785 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005786 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005787 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005788 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005789
Douglas Gregorc3203e72010-04-22 23:10:45 +00005790 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005791 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005792 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005793 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005794
Douglas Gregorc3203e72010-04-22 23:10:45 +00005795 // If nothing changed, just retain this statement.
5796 if (!getDerived().AlwaysRebuild() &&
5797 Element.get() == S->getElement() &&
5798 Collection.get() == S->getCollection() &&
5799 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005800 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005801
Douglas Gregorc3203e72010-04-22 23:10:45 +00005802 // Build a new statement.
5803 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5804 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005805 Element.get(),
5806 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005807 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005808 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005809}
5810
5811
5812template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005813StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005814TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5815 // Transform the exception declaration, if any.
5816 VarDecl *Var = 0;
5817 if (S->getExceptionDecl()) {
5818 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005819 TypeSourceInfo *T = getDerived().TransformType(
5820 ExceptionDecl->getTypeSourceInfo());
5821 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005822 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005823
Douglas Gregor83cb9422010-09-09 17:09:21 +00005824 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005825 ExceptionDecl->getInnerLocStart(),
5826 ExceptionDecl->getLocation(),
5827 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005828 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005829 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005830 }
Mike Stump1eb44332009-09-09 15:08:12 +00005831
Douglas Gregor43959a92009-08-20 07:17:43 +00005832 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005833 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005834 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005835 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005836
Douglas Gregor43959a92009-08-20 07:17:43 +00005837 if (!getDerived().AlwaysRebuild() &&
5838 !Var &&
5839 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005840 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005841
5842 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5843 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005844 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005845}
Mike Stump1eb44332009-09-09 15:08:12 +00005846
Douglas Gregor43959a92009-08-20 07:17:43 +00005847template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005848StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005849TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5850 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005851 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005852 = getDerived().TransformCompoundStmt(S->getTryBlock());
5853 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005854 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005855
Douglas Gregor43959a92009-08-20 07:17:43 +00005856 // Transform the handlers.
5857 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005858 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005859 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005860 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005861 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5862 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005863 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005864
Douglas Gregor43959a92009-08-20 07:17:43 +00005865 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5866 Handlers.push_back(Handler.takeAs<Stmt>());
5867 }
Mike Stump1eb44332009-09-09 15:08:12 +00005868
Douglas Gregor43959a92009-08-20 07:17:43 +00005869 if (!getDerived().AlwaysRebuild() &&
5870 TryBlock.get() == S->getTryBlock() &&
5871 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005872 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005873
John McCall9ae2f072010-08-23 23:25:46 +00005874 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005875 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005876}
Mike Stump1eb44332009-09-09 15:08:12 +00005877
Richard Smithad762fc2011-04-14 22:09:26 +00005878template<typename Derived>
5879StmtResult
5880TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5881 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5882 if (Range.isInvalid())
5883 return StmtError();
5884
5885 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5886 if (BeginEnd.isInvalid())
5887 return StmtError();
5888
5889 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5890 if (Cond.isInvalid())
5891 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005892 if (Cond.get())
5893 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5894 if (Cond.isInvalid())
5895 return StmtError();
5896 if (Cond.get())
5897 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005898
5899 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5900 if (Inc.isInvalid())
5901 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005902 if (Inc.get())
5903 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005904
5905 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5906 if (LoopVar.isInvalid())
5907 return StmtError();
5908
5909 StmtResult NewStmt = S;
5910 if (getDerived().AlwaysRebuild() ||
5911 Range.get() != S->getRangeStmt() ||
5912 BeginEnd.get() != S->getBeginEndStmt() ||
5913 Cond.get() != S->getCond() ||
5914 Inc.get() != S->getInc() ||
5915 LoopVar.get() != S->getLoopVarStmt())
5916 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5917 S->getColonLoc(), Range.get(),
5918 BeginEnd.get(), Cond.get(),
5919 Inc.get(), LoopVar.get(),
5920 S->getRParenLoc());
5921
5922 StmtResult Body = getDerived().TransformStmt(S->getBody());
5923 if (Body.isInvalid())
5924 return StmtError();
5925
5926 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5927 // it now so we have a new statement to attach the body to.
5928 if (Body.get() != S->getBody() && NewStmt.get() == S)
5929 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5930 S->getColonLoc(), Range.get(),
5931 BeginEnd.get(), Cond.get(),
5932 Inc.get(), LoopVar.get(),
5933 S->getRParenLoc());
5934
5935 if (NewStmt.get() == S)
5936 return SemaRef.Owned(S);
5937
5938 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5939}
5940
John Wiegley28bbe4b2011-04-28 01:08:34 +00005941template<typename Derived>
5942StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005943TreeTransform<Derived>::TransformMSDependentExistsStmt(
5944 MSDependentExistsStmt *S) {
5945 // Transform the nested-name-specifier, if any.
5946 NestedNameSpecifierLoc QualifierLoc;
5947 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005948 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00005949 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5950 if (!QualifierLoc)
5951 return StmtError();
5952 }
5953
5954 // Transform the declaration name.
5955 DeclarationNameInfo NameInfo = S->getNameInfo();
5956 if (NameInfo.getName()) {
5957 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5958 if (!NameInfo.getName())
5959 return StmtError();
5960 }
5961
5962 // Check whether anything changed.
5963 if (!getDerived().AlwaysRebuild() &&
5964 QualifierLoc == S->getQualifierLoc() &&
5965 NameInfo.getName() == S->getNameInfo().getName())
5966 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005967
Douglas Gregorba0513d2011-10-25 01:33:02 +00005968 // Determine whether this name exists, if we can.
5969 CXXScopeSpec SS;
5970 SS.Adopt(QualifierLoc);
5971 bool Dependent = false;
5972 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5973 case Sema::IER_Exists:
5974 if (S->isIfExists())
5975 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005976
Douglas Gregorba0513d2011-10-25 01:33:02 +00005977 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5978
5979 case Sema::IER_DoesNotExist:
5980 if (S->isIfNotExists())
5981 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005982
Douglas Gregorba0513d2011-10-25 01:33:02 +00005983 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005984
Douglas Gregorba0513d2011-10-25 01:33:02 +00005985 case Sema::IER_Dependent:
5986 Dependent = true;
5987 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005988
Douglas Gregor65019ac2011-10-25 03:44:56 +00005989 case Sema::IER_Error:
5990 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005991 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005992
Douglas Gregorba0513d2011-10-25 01:33:02 +00005993 // We need to continue with the instantiation, so do so now.
5994 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5995 if (SubStmt.isInvalid())
5996 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005997
Douglas Gregorba0513d2011-10-25 01:33:02 +00005998 // If we have resolved the name, just transform to the substatement.
5999 if (!Dependent)
6000 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006001
Douglas Gregorba0513d2011-10-25 01:33:02 +00006002 // The name is still dependent, so build a dependent expression again.
6003 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6004 S->isIfExists(),
6005 QualifierLoc,
6006 NameInfo,
6007 SubStmt.get());
6008}
6009
6010template<typename Derived>
6011StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006012TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6013 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6014 if(TryBlock.isInvalid()) return StmtError();
6015
6016 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6017 if(!getDerived().AlwaysRebuild() &&
6018 TryBlock.get() == S->getTryBlock() &&
6019 Handler.get() == S->getHandler())
6020 return SemaRef.Owned(S);
6021
6022 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6023 S->getTryLoc(),
6024 TryBlock.take(),
6025 Handler.take());
6026}
6027
6028template<typename Derived>
6029StmtResult
6030TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6031 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6032 if(Block.isInvalid()) return StmtError();
6033
6034 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6035 Block.take());
6036}
6037
6038template<typename Derived>
6039StmtResult
6040TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6041 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6042 if(FilterExpr.isInvalid()) return StmtError();
6043
6044 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6045 if(Block.isInvalid()) return StmtError();
6046
6047 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6048 FilterExpr.take(),
6049 Block.take());
6050}
6051
6052template<typename Derived>
6053StmtResult
6054TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6055 if(isa<SEHFinallyStmt>(Handler))
6056 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6057 else
6058 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6059}
6060
Douglas Gregor43959a92009-08-20 07:17:43 +00006061//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006062// Expression transformation
6063//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006064template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006065ExprResult
John McCall454feb92009-12-08 09:21:05 +00006066TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006067 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006068}
Mike Stump1eb44332009-09-09 15:08:12 +00006069
6070template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006071ExprResult
John McCall454feb92009-12-08 09:21:05 +00006072TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006073 NestedNameSpecifierLoc QualifierLoc;
6074 if (E->getQualifierLoc()) {
6075 QualifierLoc
6076 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6077 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006078 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006079 }
John McCalldbd872f2009-12-08 09:08:17 +00006080
6081 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006082 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6083 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006084 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006085 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006086
John McCallec8045d2010-08-17 21:27:17 +00006087 DeclarationNameInfo NameInfo = E->getNameInfo();
6088 if (NameInfo.getName()) {
6089 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6090 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006091 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006092 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006093
6094 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006095 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006096 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006097 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006098 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006099
6100 // Mark it referenced in the new context regardless.
6101 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006102 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006103
John McCall3fa5cae2010-10-26 07:05:15 +00006104 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006105 }
John McCalldbd872f2009-12-08 09:08:17 +00006106
6107 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006108 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006109 TemplateArgs = &TransArgs;
6110 TransArgs.setLAngleLoc(E->getLAngleLoc());
6111 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006112 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6113 E->getNumTemplateArgs(),
6114 TransArgs))
6115 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006116 }
6117
Chad Rosier4a9d7952012-08-08 18:46:20 +00006118 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006119 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006120}
Mike Stump1eb44332009-09-09 15:08:12 +00006121
Douglas Gregorb98b1992009-08-11 05:31:07 +00006122template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006123ExprResult
John McCall454feb92009-12-08 09:21:05 +00006124TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006125 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006126}
Mike Stump1eb44332009-09-09 15:08:12 +00006127
Douglas Gregorb98b1992009-08-11 05:31:07 +00006128template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006129ExprResult
John McCall454feb92009-12-08 09:21:05 +00006130TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006131 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006132}
Mike Stump1eb44332009-09-09 15:08:12 +00006133
Douglas Gregorb98b1992009-08-11 05:31:07 +00006134template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006135ExprResult
John McCall454feb92009-12-08 09:21:05 +00006136TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006137 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006138}
Mike Stump1eb44332009-09-09 15:08:12 +00006139
Douglas Gregorb98b1992009-08-11 05:31:07 +00006140template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006141ExprResult
John McCall454feb92009-12-08 09:21:05 +00006142TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006143 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006144}
Mike Stump1eb44332009-09-09 15:08:12 +00006145
Douglas Gregorb98b1992009-08-11 05:31:07 +00006146template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006147ExprResult
John McCall454feb92009-12-08 09:21:05 +00006148TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006149 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006150}
6151
6152template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006153ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006154TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6155 return SemaRef.MaybeBindToTemporary(E);
6156}
6157
6158template<typename Derived>
6159ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006160TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6161 ExprResult ControllingExpr =
6162 getDerived().TransformExpr(E->getControllingExpr());
6163 if (ControllingExpr.isInvalid())
6164 return ExprError();
6165
Chris Lattner686775d2011-07-20 06:58:45 +00006166 SmallVector<Expr *, 4> AssocExprs;
6167 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006168 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6169 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6170 if (TS) {
6171 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6172 if (!AssocType)
6173 return ExprError();
6174 AssocTypes.push_back(AssocType);
6175 } else {
6176 AssocTypes.push_back(0);
6177 }
6178
6179 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6180 if (AssocExpr.isInvalid())
6181 return ExprError();
6182 AssocExprs.push_back(AssocExpr.release());
6183 }
6184
6185 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6186 E->getDefaultLoc(),
6187 E->getRParenLoc(),
6188 ControllingExpr.release(),
6189 AssocTypes.data(),
6190 AssocExprs.data(),
6191 E->getNumAssocs());
6192}
6193
6194template<typename Derived>
6195ExprResult
John McCall454feb92009-12-08 09:21:05 +00006196TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006197 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006198 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006199 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006200
Douglas Gregorb98b1992009-08-11 05:31:07 +00006201 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006202 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006203
John McCall9ae2f072010-08-23 23:25:46 +00006204 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006205 E->getRParen());
6206}
6207
Mike Stump1eb44332009-09-09 15:08:12 +00006208template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006209ExprResult
John McCall454feb92009-12-08 09:21:05 +00006210TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006211 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006212 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006213 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006214
Douglas Gregorb98b1992009-08-11 05:31:07 +00006215 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006216 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006217
Douglas Gregorb98b1992009-08-11 05:31:07 +00006218 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6219 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006220 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006221}
Mike Stump1eb44332009-09-09 15:08:12 +00006222
Douglas Gregorb98b1992009-08-11 05:31:07 +00006223template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006224ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006225TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6226 // Transform the type.
6227 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6228 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006229 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006230
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006231 // Transform all of the components into components similar to what the
6232 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006233 // FIXME: It would be slightly more efficient in the non-dependent case to
6234 // just map FieldDecls, rather than requiring the rebuilder to look for
6235 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006236 // template code that we don't care.
6237 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006238 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006239 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006240 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006241 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6242 const Node &ON = E->getComponent(I);
6243 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006244 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006245 Comp.LocStart = ON.getSourceRange().getBegin();
6246 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006247 switch (ON.getKind()) {
6248 case Node::Array: {
6249 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006250 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006251 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006252 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006253
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006254 ExprChanged = ExprChanged || Index.get() != FromIndex;
6255 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006256 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006257 break;
6258 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006259
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006260 case Node::Field:
6261 case Node::Identifier:
6262 Comp.isBrackets = false;
6263 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006264 if (!Comp.U.IdentInfo)
6265 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006266
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006267 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006268
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006269 case Node::Base:
6270 // Will be recomputed during the rebuild.
6271 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006272 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006273
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006274 Components.push_back(Comp);
6275 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006276
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006277 // If nothing changed, retain the existing expression.
6278 if (!getDerived().AlwaysRebuild() &&
6279 Type == E->getTypeSourceInfo() &&
6280 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006281 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006282
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006283 // Build a new offsetof expression.
6284 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6285 Components.data(), Components.size(),
6286 E->getRParenLoc());
6287}
6288
6289template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006290ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006291TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6292 assert(getDerived().AlreadyTransformed(E->getType()) &&
6293 "opaque value expression requires transformation");
6294 return SemaRef.Owned(E);
6295}
6296
6297template<typename Derived>
6298ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006299TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006300 // Rebuild the syntactic form. The original syntactic form has
6301 // opaque-value expressions in it, so strip those away and rebuild
6302 // the result. This is a really awful way of doing this, but the
6303 // better solution (rebuilding the semantic expressions and
6304 // rebinding OVEs as necessary) doesn't work; we'd need
6305 // TreeTransform to not strip away implicit conversions.
6306 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6307 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006308 if (result.isInvalid()) return ExprError();
6309
6310 // If that gives us a pseudo-object result back, the pseudo-object
6311 // expression must have been an lvalue-to-rvalue conversion which we
6312 // should reapply.
6313 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6314 result = SemaRef.checkPseudoObjectRValue(result.take());
6315
6316 return result;
6317}
6318
6319template<typename Derived>
6320ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006321TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6322 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006323 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006324 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006325
John McCalla93c9342009-12-07 02:54:59 +00006326 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006327 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006328 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006329
John McCall5ab75172009-11-04 07:28:41 +00006330 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006331 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006332
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006333 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6334 E->getKind(),
6335 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006336 }
Mike Stump1eb44332009-09-09 15:08:12 +00006337
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006338 // C++0x [expr.sizeof]p1:
6339 // The operand is either an expression, which is an unevaluated operand
6340 // [...]
6341 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006342
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006343 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6344 if (SubExpr.isInvalid())
6345 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006346
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006347 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6348 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006349
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006350 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6351 E->getOperatorLoc(),
6352 E->getKind(),
6353 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006354}
Mike Stump1eb44332009-09-09 15:08:12 +00006355
Douglas Gregorb98b1992009-08-11 05:31:07 +00006356template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006357ExprResult
John McCall454feb92009-12-08 09:21:05 +00006358TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006359 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006360 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006361 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006362
John McCall60d7b3a2010-08-24 06:29:42 +00006363 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006364 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006365 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006366
6367
Douglas Gregorb98b1992009-08-11 05:31:07 +00006368 if (!getDerived().AlwaysRebuild() &&
6369 LHS.get() == E->getLHS() &&
6370 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006371 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006372
John McCall9ae2f072010-08-23 23:25:46 +00006373 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006374 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006375 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006376 E->getRBracketLoc());
6377}
Mike Stump1eb44332009-09-09 15:08:12 +00006378
6379template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006380ExprResult
John McCall454feb92009-12-08 09:21:05 +00006381TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006382 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006383 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006384 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006385 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006386
6387 // Transform arguments.
6388 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006389 ASTOwningVector<Expr*> Args(SemaRef);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006390 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006391 &ArgChanged))
6392 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006393
Douglas Gregorb98b1992009-08-11 05:31:07 +00006394 if (!getDerived().AlwaysRebuild() &&
6395 Callee.get() == E->getCallee() &&
6396 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006397 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump1eb44332009-09-09 15:08:12 +00006398
Douglas Gregorb98b1992009-08-11 05:31:07 +00006399 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006400 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006401 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006402 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006403 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006404 E->getRParenLoc());
6405}
Mike Stump1eb44332009-09-09 15:08:12 +00006406
6407template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006408ExprResult
John McCall454feb92009-12-08 09:21:05 +00006409TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006410 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006411 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006412 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006413
Douglas Gregor40d96a62011-02-28 21:54:11 +00006414 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006415 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006416 QualifierLoc
6417 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006418
Douglas Gregor40d96a62011-02-28 21:54:11 +00006419 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006420 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006421 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006422 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006423
Eli Friedmanf595cc42009-12-04 06:40:45 +00006424 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006425 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6426 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006427 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006428 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006429
John McCall6bb80172010-03-30 21:47:33 +00006430 NamedDecl *FoundDecl = E->getFoundDecl();
6431 if (FoundDecl == E->getMemberDecl()) {
6432 FoundDecl = Member;
6433 } else {
6434 FoundDecl = cast_or_null<NamedDecl>(
6435 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6436 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006437 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006438 }
6439
Douglas Gregorb98b1992009-08-11 05:31:07 +00006440 if (!getDerived().AlwaysRebuild() &&
6441 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006442 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006443 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006444 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006445 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006446
Anders Carlsson1f240322009-12-22 05:24:09 +00006447 // Mark it referenced in the new context regardless.
6448 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006449 SemaRef.MarkMemberReferenced(E);
6450
John McCall3fa5cae2010-10-26 07:05:15 +00006451 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006452 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006453
John McCalld5532b62009-11-23 01:53:49 +00006454 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006455 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006456 TransArgs.setLAngleLoc(E->getLAngleLoc());
6457 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006458 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6459 E->getNumTemplateArgs(),
6460 TransArgs))
6461 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006462 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006463
Douglas Gregorb98b1992009-08-11 05:31:07 +00006464 // FIXME: Bogus source location for the operator
6465 SourceLocation FakeOperatorLoc
6466 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6467
John McCallc2233c52010-01-15 08:34:02 +00006468 // FIXME: to do this check properly, we will need to preserve the
6469 // first-qualifier-in-scope here, just in case we had a dependent
6470 // base (and therefore couldn't do the check) and a
6471 // nested-name-qualifier (and therefore could do the lookup).
6472 NamedDecl *FirstQualifierInScope = 0;
6473
John McCall9ae2f072010-08-23 23:25:46 +00006474 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006475 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006476 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006477 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006478 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006479 Member,
John McCall6bb80172010-03-30 21:47:33 +00006480 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006481 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006482 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006483 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006484}
Mike Stump1eb44332009-09-09 15:08:12 +00006485
Douglas Gregorb98b1992009-08-11 05:31:07 +00006486template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006487ExprResult
John McCall454feb92009-12-08 09:21:05 +00006488TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006489 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006490 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006491 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006492
John McCall60d7b3a2010-08-24 06:29:42 +00006493 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006494 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006495 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006496
Douglas Gregorb98b1992009-08-11 05:31:07 +00006497 if (!getDerived().AlwaysRebuild() &&
6498 LHS.get() == E->getLHS() &&
6499 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006500 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006501
Douglas Gregorb98b1992009-08-11 05:31:07 +00006502 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006503 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006504}
6505
Mike Stump1eb44332009-09-09 15:08:12 +00006506template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006507ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006508TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006509 CompoundAssignOperator *E) {
6510 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006511}
Mike Stump1eb44332009-09-09 15:08:12 +00006512
Douglas Gregorb98b1992009-08-11 05:31:07 +00006513template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006514ExprResult TreeTransform<Derived>::
6515TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6516 // Just rebuild the common and RHS expressions and see whether we
6517 // get any changes.
6518
6519 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6520 if (commonExpr.isInvalid())
6521 return ExprError();
6522
6523 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6524 if (rhs.isInvalid())
6525 return ExprError();
6526
6527 if (!getDerived().AlwaysRebuild() &&
6528 commonExpr.get() == e->getCommon() &&
6529 rhs.get() == e->getFalseExpr())
6530 return SemaRef.Owned(e);
6531
6532 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6533 e->getQuestionLoc(),
6534 0,
6535 e->getColonLoc(),
6536 rhs.get());
6537}
6538
6539template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006540ExprResult
John McCall454feb92009-12-08 09:21:05 +00006541TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006542 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006543 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006544 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006545
John McCall60d7b3a2010-08-24 06:29:42 +00006546 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006547 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006548 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006549
John McCall60d7b3a2010-08-24 06:29:42 +00006550 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006551 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006552 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006553
Douglas Gregorb98b1992009-08-11 05:31:07 +00006554 if (!getDerived().AlwaysRebuild() &&
6555 Cond.get() == E->getCond() &&
6556 LHS.get() == E->getLHS() &&
6557 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006558 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006559
John McCall9ae2f072010-08-23 23:25:46 +00006560 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006561 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006562 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006563 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006564 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006565}
Mike Stump1eb44332009-09-09 15:08:12 +00006566
6567template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006568ExprResult
John McCall454feb92009-12-08 09:21:05 +00006569TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006570 // Implicit casts are eliminated during transformation, since they
6571 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006572 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006573}
Mike Stump1eb44332009-09-09 15:08:12 +00006574
Douglas Gregorb98b1992009-08-11 05:31:07 +00006575template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006576ExprResult
John McCall454feb92009-12-08 09:21:05 +00006577TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006578 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6579 if (!Type)
6580 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006581
John McCall60d7b3a2010-08-24 06:29:42 +00006582 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006583 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006584 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006585 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006586
Douglas Gregorb98b1992009-08-11 05:31:07 +00006587 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006588 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006589 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006590 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006591
John McCall9d125032010-01-15 18:39:57 +00006592 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006593 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006594 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006595 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006596}
Mike Stump1eb44332009-09-09 15:08:12 +00006597
Douglas Gregorb98b1992009-08-11 05:31:07 +00006598template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006599ExprResult
John McCall454feb92009-12-08 09:21:05 +00006600TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006601 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6602 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6603 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006604 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006605
John McCall60d7b3a2010-08-24 06:29:42 +00006606 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006607 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006608 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006609
Douglas Gregorb98b1992009-08-11 05:31:07 +00006610 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006611 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006612 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006613 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006614
John McCall1d7d8d62010-01-19 22:33:45 +00006615 // Note: the expression type doesn't necessarily match the
6616 // type-as-written, but that's okay, because it should always be
6617 // derivable from the initializer.
6618
John McCall42f56b52010-01-18 19:35:47 +00006619 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006620 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006621 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006622}
Mike Stump1eb44332009-09-09 15:08:12 +00006623
Douglas Gregorb98b1992009-08-11 05:31:07 +00006624template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006625ExprResult
John McCall454feb92009-12-08 09:21:05 +00006626TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006627 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006628 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006629 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006630
Douglas Gregorb98b1992009-08-11 05:31:07 +00006631 if (!getDerived().AlwaysRebuild() &&
6632 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006633 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006634
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006636 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006637 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006638 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006639 E->getAccessorLoc(),
6640 E->getAccessor());
6641}
Mike Stump1eb44332009-09-09 15:08:12 +00006642
Douglas Gregorb98b1992009-08-11 05:31:07 +00006643template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006644ExprResult
John McCall454feb92009-12-08 09:21:05 +00006645TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006646 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006647
John McCallca0408f2010-08-23 06:44:23 +00006648 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006649 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006650 Inits, &InitChanged))
6651 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006652
Douglas Gregorb98b1992009-08-11 05:31:07 +00006653 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006654 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006655
Douglas Gregorb98b1992009-08-11 05:31:07 +00006656 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006657 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006658}
Mike Stump1eb44332009-09-09 15:08:12 +00006659
Douglas Gregorb98b1992009-08-11 05:31:07 +00006660template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006661ExprResult
John McCall454feb92009-12-08 09:21:05 +00006662TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006663 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006664
Douglas Gregor43959a92009-08-20 07:17:43 +00006665 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006666 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006667 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006668 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006669
Douglas Gregor43959a92009-08-20 07:17:43 +00006670 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006671 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006672 bool ExprChanged = false;
6673 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6674 DEnd = E->designators_end();
6675 D != DEnd; ++D) {
6676 if (D->isFieldDesignator()) {
6677 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6678 D->getDotLoc(),
6679 D->getFieldLoc()));
6680 continue;
6681 }
Mike Stump1eb44332009-09-09 15:08:12 +00006682
Douglas Gregorb98b1992009-08-11 05:31:07 +00006683 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006684 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006685 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006686 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006687
6688 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006689 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006690
Douglas Gregorb98b1992009-08-11 05:31:07 +00006691 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6692 ArrayExprs.push_back(Index.release());
6693 continue;
6694 }
Mike Stump1eb44332009-09-09 15:08:12 +00006695
Douglas Gregorb98b1992009-08-11 05:31:07 +00006696 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006697 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006698 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6699 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006700 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006701
John McCall60d7b3a2010-08-24 06:29:42 +00006702 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006703 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006704 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006705
6706 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006707 End.get(),
6708 D->getLBracketLoc(),
6709 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006710
Douglas Gregorb98b1992009-08-11 05:31:07 +00006711 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6712 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006713
Douglas Gregorb98b1992009-08-11 05:31:07 +00006714 ArrayExprs.push_back(Start.release());
6715 ArrayExprs.push_back(End.release());
6716 }
Mike Stump1eb44332009-09-09 15:08:12 +00006717
Douglas Gregorb98b1992009-08-11 05:31:07 +00006718 if (!getDerived().AlwaysRebuild() &&
6719 Init.get() == E->getInit() &&
6720 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006721 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006722
Douglas Gregorb98b1992009-08-11 05:31:07 +00006723 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6724 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006725 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006726}
Mike Stump1eb44332009-09-09 15:08:12 +00006727
Douglas Gregorb98b1992009-08-11 05:31:07 +00006728template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006729ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006730TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006731 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006732 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006733
Douglas Gregor5557b252009-10-28 00:29:27 +00006734 // FIXME: Will we ever have proper type location here? Will we actually
6735 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006736 QualType T = getDerived().TransformType(E->getType());
6737 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006738 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006739
Douglas Gregorb98b1992009-08-11 05:31:07 +00006740 if (!getDerived().AlwaysRebuild() &&
6741 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006742 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006743
Douglas Gregorb98b1992009-08-11 05:31:07 +00006744 return getDerived().RebuildImplicitValueInitExpr(T);
6745}
Mike Stump1eb44332009-09-09 15:08:12 +00006746
Douglas Gregorb98b1992009-08-11 05:31:07 +00006747template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006748ExprResult
John McCall454feb92009-12-08 09:21:05 +00006749TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006750 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6751 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006752 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006753
John McCall60d7b3a2010-08-24 06:29:42 +00006754 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006755 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006756 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006757
Douglas Gregorb98b1992009-08-11 05:31:07 +00006758 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006759 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006760 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006761 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006762
John McCall9ae2f072010-08-23 23:25:46 +00006763 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006764 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006765}
6766
6767template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006768ExprResult
John McCall454feb92009-12-08 09:21:05 +00006769TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006770 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006771 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006772 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6773 &ArgumentChanged))
6774 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006775
Douglas Gregorb98b1992009-08-11 05:31:07 +00006776 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6777 move_arg(Inits),
6778 E->getRParenLoc());
6779}
Mike Stump1eb44332009-09-09 15:08:12 +00006780
Douglas Gregorb98b1992009-08-11 05:31:07 +00006781/// \brief Transform an address-of-label expression.
6782///
6783/// By default, the transformation of an address-of-label expression always
6784/// rebuilds the expression, so that the label identifier can be resolved to
6785/// the corresponding label statement by semantic analysis.
6786template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006787ExprResult
John McCall454feb92009-12-08 09:21:05 +00006788TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006789 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6790 E->getLabel());
6791 if (!LD)
6792 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006793
Douglas Gregorb98b1992009-08-11 05:31:07 +00006794 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006795 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006796}
Mike Stump1eb44332009-09-09 15:08:12 +00006797
6798template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006799ExprResult
John McCall454feb92009-12-08 09:21:05 +00006800TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006801 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006802 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006803 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006804 if (SubStmt.isInvalid()) {
6805 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006806 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006807 }
Mike Stump1eb44332009-09-09 15:08:12 +00006808
Douglas Gregorb98b1992009-08-11 05:31:07 +00006809 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006810 SubStmt.get() == E->getSubStmt()) {
6811 // Calling this an 'error' is unintuitive, but it does the right thing.
6812 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006813 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006814 }
Mike Stump1eb44332009-09-09 15:08:12 +00006815
6816 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006817 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006818 E->getRParenLoc());
6819}
Mike Stump1eb44332009-09-09 15:08:12 +00006820
Douglas Gregorb98b1992009-08-11 05:31:07 +00006821template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006822ExprResult
John McCall454feb92009-12-08 09:21:05 +00006823TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006824 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006825 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006826 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006827
John McCall60d7b3a2010-08-24 06:29:42 +00006828 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006829 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006830 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006831
John McCall60d7b3a2010-08-24 06:29:42 +00006832 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006833 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006834 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006835
Douglas Gregorb98b1992009-08-11 05:31:07 +00006836 if (!getDerived().AlwaysRebuild() &&
6837 Cond.get() == E->getCond() &&
6838 LHS.get() == E->getLHS() &&
6839 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006840 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006841
Douglas Gregorb98b1992009-08-11 05:31:07 +00006842 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006843 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006844 E->getRParenLoc());
6845}
Mike Stump1eb44332009-09-09 15:08:12 +00006846
Douglas Gregorb98b1992009-08-11 05:31:07 +00006847template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006848ExprResult
John McCall454feb92009-12-08 09:21:05 +00006849TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006850 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006851}
6852
6853template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006854ExprResult
John McCall454feb92009-12-08 09:21:05 +00006855TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006856 switch (E->getOperator()) {
6857 case OO_New:
6858 case OO_Delete:
6859 case OO_Array_New:
6860 case OO_Array_Delete:
6861 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006862
Douglas Gregor668d6d92009-12-13 20:44:55 +00006863 case OO_Call: {
6864 // This is a call to an object's operator().
6865 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6866
6867 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006868 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006869 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006870 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006871
6872 // FIXME: Poor location information
6873 SourceLocation FakeLParenLoc
6874 = SemaRef.PP.getLocForEndOfToken(
6875 static_cast<Expr *>(Object.get())->getLocEnd());
6876
6877 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006878 ASTOwningVector<Expr*> Args(SemaRef);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006879 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006880 Args))
6881 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006882
John McCall9ae2f072010-08-23 23:25:46 +00006883 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006884 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006885 E->getLocEnd());
6886 }
6887
6888#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6889 case OO_##Name:
6890#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6891#include "clang/Basic/OperatorKinds.def"
6892 case OO_Subscript:
6893 // Handled below.
6894 break;
6895
6896 case OO_Conditional:
6897 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006898
6899 case OO_None:
6900 case NUM_OVERLOADED_OPERATORS:
6901 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006902 }
6903
John McCall60d7b3a2010-08-24 06:29:42 +00006904 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006905 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006906 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006907
John McCall60d7b3a2010-08-24 06:29:42 +00006908 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006909 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006910 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006911
John McCall60d7b3a2010-08-24 06:29:42 +00006912 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006913 if (E->getNumArgs() == 2) {
6914 Second = getDerived().TransformExpr(E->getArg(1));
6915 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006916 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006917 }
Mike Stump1eb44332009-09-09 15:08:12 +00006918
Douglas Gregorb98b1992009-08-11 05:31:07 +00006919 if (!getDerived().AlwaysRebuild() &&
6920 Callee.get() == E->getCallee() &&
6921 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006922 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006923 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006924
Douglas Gregorb98b1992009-08-11 05:31:07 +00006925 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6926 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006927 Callee.get(),
6928 First.get(),
6929 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006930}
Mike Stump1eb44332009-09-09 15:08:12 +00006931
Douglas Gregorb98b1992009-08-11 05:31:07 +00006932template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006933ExprResult
John McCall454feb92009-12-08 09:21:05 +00006934TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6935 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006936}
Mike Stump1eb44332009-09-09 15:08:12 +00006937
Douglas Gregorb98b1992009-08-11 05:31:07 +00006938template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006939ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006940TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6941 // Transform the callee.
6942 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6943 if (Callee.isInvalid())
6944 return ExprError();
6945
6946 // Transform exec config.
6947 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6948 if (EC.isInvalid())
6949 return ExprError();
6950
6951 // Transform arguments.
6952 bool ArgChanged = false;
6953 ASTOwningVector<Expr*> Args(SemaRef);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006954 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006955 &ArgChanged))
6956 return ExprError();
6957
6958 if (!getDerived().AlwaysRebuild() &&
6959 Callee.get() == E->getCallee() &&
6960 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006961 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006962
6963 // FIXME: Wrong source location information for the '('.
6964 SourceLocation FakeLParenLoc
6965 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6966 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6967 move_arg(Args),
6968 E->getRParenLoc(), EC.get());
6969}
6970
6971template<typename Derived>
6972ExprResult
John McCall454feb92009-12-08 09:21:05 +00006973TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006974 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6975 if (!Type)
6976 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006977
John McCall60d7b3a2010-08-24 06:29:42 +00006978 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006979 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006980 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006981 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006982
Douglas Gregorb98b1992009-08-11 05:31:07 +00006983 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006984 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006985 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006986 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006987
Douglas Gregorb98b1992009-08-11 05:31:07 +00006988 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006989 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006990 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6991 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6992 SourceLocation FakeRParenLoc
6993 = SemaRef.PP.getLocForEndOfToken(
6994 E->getSubExpr()->getSourceRange().getEnd());
6995 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006996 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006997 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006998 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006999 FakeRAngleLoc,
7000 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007001 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007002 FakeRParenLoc);
7003}
Mike Stump1eb44332009-09-09 15:08:12 +00007004
Douglas Gregorb98b1992009-08-11 05:31:07 +00007005template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007006ExprResult
John McCall454feb92009-12-08 09:21:05 +00007007TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7008 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007009}
Mike Stump1eb44332009-09-09 15:08:12 +00007010
7011template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007012ExprResult
John McCall454feb92009-12-08 09:21:05 +00007013TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7014 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007015}
7016
Douglas Gregorb98b1992009-08-11 05:31:07 +00007017template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007018ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007019TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007020 CXXReinterpretCastExpr *E) {
7021 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007022}
Mike Stump1eb44332009-09-09 15:08:12 +00007023
Douglas Gregorb98b1992009-08-11 05:31:07 +00007024template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007025ExprResult
John McCall454feb92009-12-08 09:21:05 +00007026TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7027 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007028}
Mike Stump1eb44332009-09-09 15:08:12 +00007029
Douglas Gregorb98b1992009-08-11 05:31:07 +00007030template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007031ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007032TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007033 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007034 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7035 if (!Type)
7036 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007037
John McCall60d7b3a2010-08-24 06:29:42 +00007038 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007039 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007040 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007041 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007042
Douglas Gregorb98b1992009-08-11 05:31:07 +00007043 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007044 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007045 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007046 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007047
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007048 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007049 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007050 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007051 E->getRParenLoc());
7052}
Mike Stump1eb44332009-09-09 15:08:12 +00007053
Douglas Gregorb98b1992009-08-11 05:31:07 +00007054template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007055ExprResult
John McCall454feb92009-12-08 09:21:05 +00007056TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007057 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007058 TypeSourceInfo *TInfo
7059 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7060 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007061 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007062
Douglas Gregorb98b1992009-08-11 05:31:07 +00007063 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007064 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007065 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007066
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007067 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7068 E->getLocStart(),
7069 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007070 E->getLocEnd());
7071 }
Mike Stump1eb44332009-09-09 15:08:12 +00007072
Eli Friedmanef331b72012-01-20 01:26:23 +00007073 // We don't know whether the subexpression is potentially evaluated until
7074 // after we perform semantic analysis. We speculatively assume it is
7075 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007076 // potentially evaluated.
Eli Friedmanef331b72012-01-20 01:26:23 +00007077 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00007078
John McCall60d7b3a2010-08-24 06:29:42 +00007079 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007080 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007081 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007082
Douglas Gregorb98b1992009-08-11 05:31:07 +00007083 if (!getDerived().AlwaysRebuild() &&
7084 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007085 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007086
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007087 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7088 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007089 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007090 E->getLocEnd());
7091}
7092
7093template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007094ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007095TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7096 if (E->isTypeOperand()) {
7097 TypeSourceInfo *TInfo
7098 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7099 if (!TInfo)
7100 return ExprError();
7101
7102 if (!getDerived().AlwaysRebuild() &&
7103 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007104 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007105
Douglas Gregor3c52a212011-03-06 17:40:41 +00007106 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007107 E->getLocStart(),
7108 TInfo,
7109 E->getLocEnd());
7110 }
7111
Francois Pichet01b7c302010-09-08 12:20:18 +00007112 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7113
7114 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7115 if (SubExpr.isInvalid())
7116 return ExprError();
7117
7118 if (!getDerived().AlwaysRebuild() &&
7119 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007120 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007121
7122 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7123 E->getLocStart(),
7124 SubExpr.get(),
7125 E->getLocEnd());
7126}
7127
7128template<typename Derived>
7129ExprResult
John McCall454feb92009-12-08 09:21:05 +00007130TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007131 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007132}
Mike Stump1eb44332009-09-09 15:08:12 +00007133
Douglas Gregorb98b1992009-08-11 05:31:07 +00007134template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007135ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007136TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007137 CXXNullPtrLiteralExpr *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
John McCall454feb92009-12-08 09:21:05 +00007143TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007144 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007145 QualType T;
7146 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7147 T = MD->getThisType(getSema().Context);
7148 else
7149 T = getSema().Context.getPointerType(
7150 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007151
Douglas Gregorec79d872012-02-24 17:41:38 +00007152 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7153 // Make sure that we capture 'this'.
7154 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007155 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007156 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007157
Douglas Gregor828a1972010-01-07 23:12:05 +00007158 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007159}
Mike Stump1eb44332009-09-09 15:08:12 +00007160
Douglas Gregorb98b1992009-08-11 05:31:07 +00007161template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007162ExprResult
John McCall454feb92009-12-08 09:21:05 +00007163TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007164 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007165 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007166 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007167
Douglas Gregorb98b1992009-08-11 05:31:07 +00007168 if (!getDerived().AlwaysRebuild() &&
7169 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007170 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007171
Douglas Gregorbca01b42011-07-06 22:04:06 +00007172 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7173 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007174}
Mike Stump1eb44332009-09-09 15:08:12 +00007175
Douglas Gregorb98b1992009-08-11 05:31:07 +00007176template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007177ExprResult
John McCall454feb92009-12-08 09:21:05 +00007178TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007179 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007180 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7181 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007182 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007183 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007184
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007185 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007186 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007187 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007188
Douglas Gregor036aed12009-12-23 23:03:06 +00007189 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007190}
Mike Stump1eb44332009-09-09 15:08:12 +00007191
Douglas Gregorb98b1992009-08-11 05:31:07 +00007192template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007193ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007194TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7195 CXXScalarValueInitExpr *E) {
7196 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7197 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007198 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007199
Douglas Gregorb98b1992009-08-11 05:31:07 +00007200 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007201 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007202 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007203
Chad Rosier4a9d7952012-08-08 18:46:20 +00007204 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007205 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007206 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007207}
Mike Stump1eb44332009-09-09 15:08:12 +00007208
Douglas Gregorb98b1992009-08-11 05:31:07 +00007209template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007210ExprResult
John McCall454feb92009-12-08 09:21:05 +00007211TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007212 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007213 TypeSourceInfo *AllocTypeInfo
7214 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7215 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007216 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007217
Douglas Gregorb98b1992009-08-11 05:31:07 +00007218 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007219 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007220 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007221 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007222
Douglas Gregorb98b1992009-08-11 05:31:07 +00007223 // Transform the placement arguments (if any).
7224 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007225 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007226 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007227 E->getNumPlacementArgs(), true,
7228 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007229 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007230
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007231 // Transform the initializer (if any).
7232 Expr *OldInit = E->getInitializer();
7233 ExprResult NewInit;
7234 if (OldInit)
7235 NewInit = getDerived().TransformExpr(OldInit);
7236 if (NewInit.isInvalid())
7237 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007238
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007239 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007240 FunctionDecl *OperatorNew = 0;
7241 if (E->getOperatorNew()) {
7242 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007243 getDerived().TransformDecl(E->getLocStart(),
7244 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007245 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007246 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007247 }
7248
7249 FunctionDecl *OperatorDelete = 0;
7250 if (E->getOperatorDelete()) {
7251 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007252 getDerived().TransformDecl(E->getLocStart(),
7253 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007254 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007255 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007256 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007257
Douglas Gregorb98b1992009-08-11 05:31:07 +00007258 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007259 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007260 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007261 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007262 OperatorNew == E->getOperatorNew() &&
7263 OperatorDelete == E->getOperatorDelete() &&
7264 !ArgumentChanged) {
7265 // Mark any declarations we need as referenced.
7266 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007267 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007268 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007269 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007270 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007271
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007272 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007273 QualType ElementType
7274 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7275 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7276 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7277 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007278 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007279 }
7280 }
7281 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007282
John McCall3fa5cae2010-10-26 07:05:15 +00007283 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007284 }
Mike Stump1eb44332009-09-09 15:08:12 +00007285
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007286 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007287 if (!ArraySize.get()) {
7288 // If no array size was specified, but the new expression was
7289 // instantiated with an array type (e.g., "new T" where T is
7290 // instantiated with "int[4]"), extract the outer bound from the
7291 // array type as our array size. We do this with constant and
7292 // dependently-sized array types.
7293 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7294 if (!ArrayT) {
7295 // Do nothing
7296 } else if (const ConstantArrayType *ConsArrayT
7297 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007298 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007299 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007300 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007301 SemaRef.Context.getSizeType(),
7302 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007303 AllocType = ConsArrayT->getElementType();
7304 } else if (const DependentSizedArrayType *DepArrayT
7305 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7306 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007307 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007308 AllocType = DepArrayT->getElementType();
7309 }
7310 }
7311 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007312
Douglas Gregorb98b1992009-08-11 05:31:07 +00007313 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7314 E->isGlobalNew(),
7315 /*FIXME:*/E->getLocStart(),
7316 move_arg(PlacementArgs),
7317 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007318 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007319 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007320 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007321 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007322 E->getDirectInitRange(),
7323 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007324}
Mike Stump1eb44332009-09-09 15:08:12 +00007325
Douglas Gregorb98b1992009-08-11 05:31:07 +00007326template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007327ExprResult
John McCall454feb92009-12-08 09:21:05 +00007328TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007329 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007330 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007331 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007332
Douglas Gregor1af74512010-02-26 00:38:10 +00007333 // Transform the delete operator, if known.
7334 FunctionDecl *OperatorDelete = 0;
7335 if (E->getOperatorDelete()) {
7336 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007337 getDerived().TransformDecl(E->getLocStart(),
7338 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007339 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007340 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007341 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007342
Douglas Gregorb98b1992009-08-11 05:31:07 +00007343 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007344 Operand.get() == E->getArgument() &&
7345 OperatorDelete == E->getOperatorDelete()) {
7346 // Mark any declarations we need as referenced.
7347 // FIXME: instantiation-specific.
7348 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007349 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007350
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007351 if (!E->getArgument()->isTypeDependent()) {
7352 QualType Destroyed = SemaRef.Context.getBaseElementType(
7353 E->getDestroyedType());
7354 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7355 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007356 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007357 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007358 }
7359 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007360
John McCall3fa5cae2010-10-26 07:05:15 +00007361 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007362 }
Mike Stump1eb44332009-09-09 15:08:12 +00007363
Douglas Gregorb98b1992009-08-11 05:31:07 +00007364 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7365 E->isGlobalDelete(),
7366 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007367 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007368}
Mike Stump1eb44332009-09-09 15:08:12 +00007369
Douglas Gregorb98b1992009-08-11 05:31:07 +00007370template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007371ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007372TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007373 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007374 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007375 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007376 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007377
John McCallb3d87482010-08-24 05:47:05 +00007378 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007379 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007380 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007381 E->getOperatorLoc(),
7382 E->isArrow()? tok::arrow : tok::period,
7383 ObjectTypePtr,
7384 MayBePseudoDestructor);
7385 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007386 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007387
John McCallb3d87482010-08-24 05:47:05 +00007388 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007389 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7390 if (QualifierLoc) {
7391 QualifierLoc
7392 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7393 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007394 return ExprError();
7395 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007396 CXXScopeSpec SS;
7397 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007398
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007399 PseudoDestructorTypeStorage Destroyed;
7400 if (E->getDestroyedTypeInfo()) {
7401 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007402 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007403 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007404 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007405 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007406 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007407 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007408 // We aren't likely to be able to resolve the identifier down to a type
7409 // now anyway, so just retain the identifier.
7410 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7411 E->getDestroyedTypeLoc());
7412 } else {
7413 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007414 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007415 *E->getDestroyedTypeIdentifier(),
7416 E->getDestroyedTypeLoc(),
7417 /*Scope=*/0,
7418 SS, ObjectTypePtr,
7419 false);
7420 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007421 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007422
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007423 Destroyed
7424 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7425 E->getDestroyedTypeLoc());
7426 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007427
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007428 TypeSourceInfo *ScopeTypeInfo = 0;
7429 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007430 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007431 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007432 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007433 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007434
John McCall9ae2f072010-08-23 23:25:46 +00007435 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007436 E->getOperatorLoc(),
7437 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007438 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007439 ScopeTypeInfo,
7440 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007441 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007442 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007443}
Mike Stump1eb44332009-09-09 15:08:12 +00007444
Douglas Gregora71d8192009-09-04 17:36:40 +00007445template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007446ExprResult
John McCallba135432009-11-21 08:51:07 +00007447TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007448 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007449 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7450 Sema::LookupOrdinaryName);
7451
7452 // Transform all the decls.
7453 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7454 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007455 NamedDecl *InstD = static_cast<NamedDecl*>(
7456 getDerived().TransformDecl(Old->getNameLoc(),
7457 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007458 if (!InstD) {
7459 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7460 // This can happen because of dependent hiding.
7461 if (isa<UsingShadowDecl>(*I))
7462 continue;
7463 else
John McCallf312b1e2010-08-26 23:41:50 +00007464 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007465 }
John McCallf7a1a742009-11-24 19:00:30 +00007466
7467 // Expand using declarations.
7468 if (isa<UsingDecl>(InstD)) {
7469 UsingDecl *UD = cast<UsingDecl>(InstD);
7470 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7471 E = UD->shadow_end(); I != E; ++I)
7472 R.addDecl(*I);
7473 continue;
7474 }
7475
7476 R.addDecl(InstD);
7477 }
7478
7479 // Resolve a kind, but don't do any further analysis. If it's
7480 // ambiguous, the callee needs to deal with it.
7481 R.resolveKind();
7482
7483 // Rebuild the nested-name qualifier, if present.
7484 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007485 if (Old->getQualifierLoc()) {
7486 NestedNameSpecifierLoc QualifierLoc
7487 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7488 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007489 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007490
Douglas Gregor4c9be892011-02-28 20:01:57 +00007491 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007492 }
7493
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007494 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007495 CXXRecordDecl *NamingClass
7496 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7497 Old->getNameLoc(),
7498 Old->getNamingClass()));
7499 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007500 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007501
Douglas Gregor66c45152010-04-27 16:10:10 +00007502 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007503 }
7504
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007505 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7506
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007507 // If we have neither explicit template arguments, nor the template keyword,
7508 // it's a normal declaration name.
7509 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007510 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7511
7512 // If we have template arguments, rebuild them, then rebuild the
7513 // templateid expression.
7514 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007515 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7516 Old->getNumTemplateArgs(),
7517 TransArgs))
7518 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007519
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007520 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007521 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007522}
Mike Stump1eb44332009-09-09 15:08:12 +00007523
Douglas Gregorb98b1992009-08-11 05:31:07 +00007524template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007525ExprResult
John McCall454feb92009-12-08 09:21:05 +00007526TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007527 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7528 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007529 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007530
Douglas Gregorb98b1992009-08-11 05:31:07 +00007531 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007532 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007533 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007534
Mike Stump1eb44332009-09-09 15:08:12 +00007535 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007536 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007537 T,
7538 E->getLocEnd());
7539}
Mike Stump1eb44332009-09-09 15:08:12 +00007540
Douglas Gregorb98b1992009-08-11 05:31:07 +00007541template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007542ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007543TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7544 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7545 if (!LhsT)
7546 return ExprError();
7547
7548 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7549 if (!RhsT)
7550 return ExprError();
7551
7552 if (!getDerived().AlwaysRebuild() &&
7553 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7554 return SemaRef.Owned(E);
7555
7556 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7557 E->getLocStart(),
7558 LhsT, RhsT,
7559 E->getLocEnd());
7560}
7561
7562template<typename Derived>
7563ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007564TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7565 bool ArgChanged = false;
7566 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7567 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7568 TypeSourceInfo *From = E->getArg(I);
7569 TypeLoc FromTL = From->getTypeLoc();
7570 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7571 TypeLocBuilder TLB;
7572 TLB.reserve(FromTL.getFullDataSize());
7573 QualType To = getDerived().TransformType(TLB, FromTL);
7574 if (To.isNull())
7575 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007576
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007577 if (To == From->getType())
7578 Args.push_back(From);
7579 else {
7580 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7581 ArgChanged = true;
7582 }
7583 continue;
7584 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007585
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007586 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007587
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007588 // We have a pack expansion. Instantiate it.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007589 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007590 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7591 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7592 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007593
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007594 // Determine whether the set of unexpanded parameter packs can and should
7595 // be expanded.
7596 bool Expand = true;
7597 bool RetainExpansion = false;
7598 llvm::Optional<unsigned> OrigNumExpansions
7599 = ExpansionTL.getTypePtr()->getNumExpansions();
7600 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7601 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7602 PatternTL.getSourceRange(),
7603 Unexpanded,
7604 Expand, RetainExpansion,
7605 NumExpansions))
7606 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007607
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007608 if (!Expand) {
7609 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007610 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007611 // expansion.
7612 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007613
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007614 TypeLocBuilder TLB;
7615 TLB.reserve(From->getTypeLoc().getFullDataSize());
7616
7617 QualType To = getDerived().TransformType(TLB, PatternTL);
7618 if (To.isNull())
7619 return ExprError();
7620
Chad Rosier4a9d7952012-08-08 18:46:20 +00007621 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007622 PatternTL.getSourceRange(),
7623 ExpansionTL.getEllipsisLoc(),
7624 NumExpansions);
7625 if (To.isNull())
7626 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007627
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007628 PackExpansionTypeLoc ToExpansionTL
7629 = TLB.push<PackExpansionTypeLoc>(To);
7630 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7631 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7632 continue;
7633 }
7634
7635 // Expand the pack expansion by substituting for each argument in the
7636 // pack(s).
7637 for (unsigned I = 0; I != *NumExpansions; ++I) {
7638 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7639 TypeLocBuilder TLB;
7640 TLB.reserve(PatternTL.getFullDataSize());
7641 QualType To = getDerived().TransformType(TLB, PatternTL);
7642 if (To.isNull())
7643 return ExprError();
7644
7645 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7646 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007647
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007648 if (!RetainExpansion)
7649 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007650
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007651 // If we're supposed to retain a pack expansion, do so by temporarily
7652 // forgetting the partially-substituted parameter pack.
7653 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7654
7655 TypeLocBuilder TLB;
7656 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007657
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007658 QualType To = getDerived().TransformType(TLB, PatternTL);
7659 if (To.isNull())
7660 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007661
7662 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007663 PatternTL.getSourceRange(),
7664 ExpansionTL.getEllipsisLoc(),
7665 NumExpansions);
7666 if (To.isNull())
7667 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007668
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007669 PackExpansionTypeLoc ToExpansionTL
7670 = TLB.push<PackExpansionTypeLoc>(To);
7671 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7672 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7673 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007674
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007675 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7676 return SemaRef.Owned(E);
7677
7678 return getDerived().RebuildTypeTrait(E->getTrait(),
7679 E->getLocStart(),
7680 Args,
7681 E->getLocEnd());
7682}
7683
7684template<typename Derived>
7685ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007686TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7687 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7688 if (!T)
7689 return ExprError();
7690
7691 if (!getDerived().AlwaysRebuild() &&
7692 T == E->getQueriedTypeSourceInfo())
7693 return SemaRef.Owned(E);
7694
7695 ExprResult SubExpr;
7696 {
7697 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7698 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7699 if (SubExpr.isInvalid())
7700 return ExprError();
7701
7702 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7703 return SemaRef.Owned(E);
7704 }
7705
7706 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7707 E->getLocStart(),
7708 T,
7709 SubExpr.get(),
7710 E->getLocEnd());
7711}
7712
7713template<typename Derived>
7714ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007715TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7716 ExprResult SubExpr;
7717 {
7718 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7719 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7720 if (SubExpr.isInvalid())
7721 return ExprError();
7722
7723 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7724 return SemaRef.Owned(E);
7725 }
7726
7727 return getDerived().RebuildExpressionTrait(
7728 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7729}
7730
7731template<typename Derived>
7732ExprResult
John McCall865d4472009-11-19 22:55:06 +00007733TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007734 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007735 NestedNameSpecifierLoc QualifierLoc
7736 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7737 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007738 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007739 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007740
John McCall43fed0d2010-11-12 08:19:04 +00007741 // TODO: If this is a conversion-function-id, verify that the
7742 // destination type name (if present) resolves the same way after
7743 // instantiation as it did in the local scope.
7744
Abramo Bagnara25777432010-08-11 22:01:17 +00007745 DeclarationNameInfo NameInfo
7746 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7747 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007748 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007749
John McCallf7a1a742009-11-24 19:00:30 +00007750 if (!E->hasExplicitTemplateArgs()) {
7751 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007752 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007753 // Note: it is sufficient to compare the Name component of NameInfo:
7754 // if name has not changed, DNLoc has not changed either.
7755 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007756 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007757
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007758 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007759 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007760 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007761 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007762 }
John McCalld5532b62009-11-23 01:53:49 +00007763
7764 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007765 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7766 E->getNumTemplateArgs(),
7767 TransArgs))
7768 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007769
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007770 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007771 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007772 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007773 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007774}
7775
7776template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007777ExprResult
John McCall454feb92009-12-08 09:21:05 +00007778TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007779 // CXXConstructExprs are always implicit, so when we have a
7780 // 1-argument construction we just transform that argument.
7781 if (E->getNumArgs() == 1 ||
7782 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7783 return getDerived().TransformExpr(E->getArg(0));
7784
Douglas Gregorb98b1992009-08-11 05:31:07 +00007785 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7786
7787 QualType T = getDerived().TransformType(E->getType());
7788 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007789 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007790
7791 CXXConstructorDecl *Constructor
7792 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007793 getDerived().TransformDecl(E->getLocStart(),
7794 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007795 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007796 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007797
Douglas Gregorb98b1992009-08-11 05:31:07 +00007798 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007799 ASTOwningVector<Expr*> Args(SemaRef);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007800 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007801 &ArgumentChanged))
7802 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007803
Douglas Gregorb98b1992009-08-11 05:31:07 +00007804 if (!getDerived().AlwaysRebuild() &&
7805 T == E->getType() &&
7806 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007807 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007808 // Mark the constructor as referenced.
7809 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007810 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007811 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007812 }
Mike Stump1eb44332009-09-09 15:08:12 +00007813
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007814 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7815 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007816 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007817 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007818 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007819 E->getConstructionKind(),
7820 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007821}
Mike Stump1eb44332009-09-09 15:08:12 +00007822
Douglas Gregorb98b1992009-08-11 05:31:07 +00007823/// \brief Transform a C++ temporary-binding expression.
7824///
Douglas Gregor51326552009-12-24 18:51:59 +00007825/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7826/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007827template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007828ExprResult
John McCall454feb92009-12-08 09:21:05 +00007829TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007830 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007831}
Mike Stump1eb44332009-09-09 15:08:12 +00007832
John McCall4765fa02010-12-06 08:20:24 +00007833/// \brief Transform a C++ expression that contains cleanups that should
7834/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007835///
John McCall4765fa02010-12-06 08:20:24 +00007836/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007837/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007838template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007839ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007840TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007841 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007842}
Mike Stump1eb44332009-09-09 15:08:12 +00007843
Douglas Gregorb98b1992009-08-11 05:31:07 +00007844template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007845ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007846TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007847 CXXTemporaryObjectExpr *E) {
7848 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7849 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007850 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007851
Douglas Gregorb98b1992009-08-11 05:31:07 +00007852 CXXConstructorDecl *Constructor
7853 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00007854 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007855 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007856 if (!Constructor)
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 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007860 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007861 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007862 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007863 &ArgumentChanged))
7864 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007865
Douglas Gregorb98b1992009-08-11 05:31:07 +00007866 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007867 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007868 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007869 !ArgumentChanged) {
7870 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007871 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007872 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007873 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007874
Douglas Gregorab6677e2010-09-08 00:15:04 +00007875 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7876 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007877 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007878 E->getLocEnd());
7879}
Mike Stump1eb44332009-09-09 15:08:12 +00007880
Douglas Gregorb98b1992009-08-11 05:31:07 +00007881template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007882ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007883TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007884 // Create the local class that will describe the lambda.
7885 CXXRecordDecl *Class
Douglas Gregorf54486a2012-04-04 17:40:10 +00007886 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7887 /*KnownDependent=*/false);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007888 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007889
Douglas Gregordfca6f52012-02-13 22:00:16 +00007890 // Transform the type of the lambda parameters and start the definition of
7891 // the lambda itself.
7892 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00007893 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00007894 if (!MethodTy)
7895 return ExprError();
7896
Douglas Gregorc6889e72012-02-14 22:28:59 +00007897 // Transform lambda parameters.
Douglas Gregorc6889e72012-02-14 22:28:59 +00007898 llvm::SmallVector<QualType, 4> ParamTypes;
7899 llvm::SmallVector<ParmVarDecl *, 4> Params;
7900 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7901 E->getCallOperator()->param_begin(),
7902 E->getCallOperator()->param_size(),
7903 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00007904 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00007905
Douglas Gregordfca6f52012-02-13 22:00:16 +00007906 // Build the call operator.
7907 CXXMethodDecl *CallOperator
7908 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007909 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007910 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007911 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007912 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00007913
Richard Smith612409e2012-07-25 03:56:55 +00007914 return getDerived().TransformLambdaScope(E, CallOperator);
7915}
7916
7917template<typename Derived>
7918ExprResult
7919TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
7920 CXXMethodDecl *CallOperator) {
Douglas Gregord5387e82012-02-14 00:00:48 +00007921 // Introduce the context of the call operator.
7922 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7923
Douglas Gregordfca6f52012-02-13 22:00:16 +00007924 // Enter the scope of the lambda.
7925 sema::LambdaScopeInfo *LSI
7926 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7927 E->getCaptureDefault(),
7928 E->hasExplicitParameters(),
7929 E->hasExplicitResultType(),
7930 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007931
Douglas Gregordfca6f52012-02-13 22:00:16 +00007932 // Transform captures.
Richard Smith612409e2012-07-25 03:56:55 +00007933 bool Invalid = false;
Douglas Gregordfca6f52012-02-13 22:00:16 +00007934 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007935 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007936 CEnd = E->capture_end();
7937 C != CEnd; ++C) {
7938 // When we hit the first implicit capture, tell Sema that we've finished
7939 // the list of explicit captures.
7940 if (!FinishedExplicitCaptures && C->isImplicit()) {
7941 getSema().finishLambdaExplicitCaptures(LSI);
7942 FinishedExplicitCaptures = true;
7943 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007944
Douglas Gregordfca6f52012-02-13 22:00:16 +00007945 // Capturing 'this' is trivial.
7946 if (C->capturesThis()) {
7947 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7948 continue;
7949 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007950
Douglas Gregora7365242012-02-14 19:27:52 +00007951 // Determine the capture kind for Sema.
7952 Sema::TryCaptureKind Kind
7953 = C->isImplicit()? Sema::TryCapture_Implicit
7954 : C->getCaptureKind() == LCK_ByCopy
7955 ? Sema::TryCapture_ExplicitByVal
7956 : Sema::TryCapture_ExplicitByRef;
7957 SourceLocation EllipsisLoc;
7958 if (C->isPackExpansion()) {
7959 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7960 bool ShouldExpand = false;
7961 bool RetainExpansion = false;
7962 llvm::Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007963 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7964 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00007965 Unexpanded,
7966 ShouldExpand, RetainExpansion,
7967 NumExpansions))
7968 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007969
Douglas Gregora7365242012-02-14 19:27:52 +00007970 if (ShouldExpand) {
7971 // The transform has determined that we should perform an expansion;
7972 // transform and capture each of the arguments.
7973 // expansion of the pattern. Do so.
7974 VarDecl *Pack = C->getCapturedVar();
7975 for (unsigned I = 0; I != *NumExpansions; ++I) {
7976 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7977 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00007978 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00007979 Pack));
7980 if (!CapturedVar) {
7981 Invalid = true;
7982 continue;
7983 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007984
Douglas Gregora7365242012-02-14 19:27:52 +00007985 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007986 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
7987 }
Douglas Gregora7365242012-02-14 19:27:52 +00007988 continue;
7989 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007990
Douglas Gregora7365242012-02-14 19:27:52 +00007991 EllipsisLoc = C->getEllipsisLoc();
7992 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007993
Douglas Gregordfca6f52012-02-13 22:00:16 +00007994 // Transform the captured variable.
7995 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00007996 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007997 C->getCapturedVar()));
7998 if (!CapturedVar) {
7999 Invalid = true;
8000 continue;
8001 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008002
Douglas Gregordfca6f52012-02-13 22:00:16 +00008003 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008004 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008005 }
8006 if (!FinishedExplicitCaptures)
8007 getSema().finishLambdaExplicitCaptures(LSI);
8008
Douglas Gregordfca6f52012-02-13 22:00:16 +00008009
8010 // Enter a new evaluation context to insulate the lambda from any
8011 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008012 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008013
8014 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008015 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008016 /*IsInstantiation=*/true);
8017 return ExprError();
8018 }
8019
8020 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008021 StmtResult Body = getDerived().TransformStmt(E->getBody());
8022 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008023 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008024 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008025 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008026 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008027
Chad Rosier4a9d7952012-08-08 18:46:20 +00008028 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008029 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008030}
8031
8032template<typename Derived>
8033ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008034TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008035 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008036 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8037 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008038 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008039
Douglas Gregorb98b1992009-08-11 05:31:07 +00008040 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008041 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008042 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008043 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008044 &ArgumentChanged))
8045 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008046
Douglas Gregorb98b1992009-08-11 05:31:07 +00008047 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008048 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008049 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008050 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008051
Douglas Gregorb98b1992009-08-11 05:31:07 +00008052 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008053 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008054 E->getLParenLoc(),
8055 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00008056 E->getRParenLoc());
8057}
Mike Stump1eb44332009-09-09 15:08:12 +00008058
Douglas Gregorb98b1992009-08-11 05:31:07 +00008059template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008060ExprResult
John McCall865d4472009-11-19 22:55:06 +00008061TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008062 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008063 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008064 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008065 Expr *OldBase;
8066 QualType BaseType;
8067 QualType ObjectType;
8068 if (!E->isImplicitAccess()) {
8069 OldBase = E->getBase();
8070 Base = getDerived().TransformExpr(OldBase);
8071 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008072 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008073
John McCallaa81e162009-12-01 22:10:20 +00008074 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008075 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008076 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008077 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008078 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008079 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008080 ObjectTy,
8081 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008082 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008083 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008084
John McCallb3d87482010-08-24 05:47:05 +00008085 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008086 BaseType = ((Expr*) Base.get())->getType();
8087 } else {
8088 OldBase = 0;
8089 BaseType = getDerived().TransformType(E->getBaseType());
8090 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8091 }
Mike Stump1eb44332009-09-09 15:08:12 +00008092
Douglas Gregor6cd21982009-10-20 05:58:46 +00008093 // Transform the first part of the nested-name-specifier that qualifies
8094 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008095 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008096 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008097 E->getFirstQualifierFoundInScope(),
8098 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008099
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008100 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008101 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008102 QualifierLoc
8103 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8104 ObjectType,
8105 FirstQualifierInScope);
8106 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008107 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008108 }
Mike Stump1eb44332009-09-09 15:08:12 +00008109
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008110 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8111
John McCall43fed0d2010-11-12 08:19:04 +00008112 // TODO: If this is a conversion-function-id, verify that the
8113 // destination type name (if present) resolves the same way after
8114 // instantiation as it did in the local scope.
8115
Abramo Bagnara25777432010-08-11 22:01:17 +00008116 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008117 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008118 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008119 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008120
John McCallaa81e162009-12-01 22:10:20 +00008121 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008122 // This is a reference to a member without an explicitly-specified
8123 // template argument list. Optimize for this common case.
8124 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008125 Base.get() == OldBase &&
8126 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008127 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008128 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008129 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008130 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008131
John McCall9ae2f072010-08-23 23:25:46 +00008132 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008133 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008134 E->isArrow(),
8135 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008136 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008137 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008138 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008139 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008140 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008141 }
8142
John McCalld5532b62009-11-23 01:53:49 +00008143 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008144 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8145 E->getNumTemplateArgs(),
8146 TransArgs))
8147 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008148
John McCall9ae2f072010-08-23 23:25:46 +00008149 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008150 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008151 E->isArrow(),
8152 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008153 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008154 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008155 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008156 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008157 &TransArgs);
8158}
8159
8160template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008161ExprResult
John McCall454feb92009-12-08 09:21:05 +00008162TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008163 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008164 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008165 QualType BaseType;
8166 if (!Old->isImplicitAccess()) {
8167 Base = getDerived().TransformExpr(Old->getBase());
8168 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008169 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008170 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8171 Old->isArrow());
8172 if (Base.isInvalid())
8173 return ExprError();
8174 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008175 } else {
8176 BaseType = getDerived().TransformType(Old->getBaseType());
8177 }
John McCall129e2df2009-11-30 22:42:35 +00008178
Douglas Gregor4c9be892011-02-28 20:01:57 +00008179 NestedNameSpecifierLoc QualifierLoc;
8180 if (Old->getQualifierLoc()) {
8181 QualifierLoc
8182 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8183 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008184 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008185 }
8186
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008187 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8188
Abramo Bagnara25777432010-08-11 22:01:17 +00008189 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008190 Sema::LookupOrdinaryName);
8191
8192 // Transform all the decls.
8193 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8194 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008195 NamedDecl *InstD = static_cast<NamedDecl*>(
8196 getDerived().TransformDecl(Old->getMemberLoc(),
8197 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008198 if (!InstD) {
8199 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8200 // This can happen because of dependent hiding.
8201 if (isa<UsingShadowDecl>(*I))
8202 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008203 else {
8204 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008205 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008206 }
John McCall9f54ad42009-12-10 09:41:52 +00008207 }
John McCall129e2df2009-11-30 22:42:35 +00008208
8209 // Expand using declarations.
8210 if (isa<UsingDecl>(InstD)) {
8211 UsingDecl *UD = cast<UsingDecl>(InstD);
8212 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8213 E = UD->shadow_end(); I != E; ++I)
8214 R.addDecl(*I);
8215 continue;
8216 }
8217
8218 R.addDecl(InstD);
8219 }
8220
8221 R.resolveKind();
8222
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008223 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008224 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008225 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008226 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008227 Old->getMemberLoc(),
8228 Old->getNamingClass()));
8229 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008230 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008231
Douglas Gregor66c45152010-04-27 16:10:10 +00008232 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008233 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008234
John McCall129e2df2009-11-30 22:42:35 +00008235 TemplateArgumentListInfo TransArgs;
8236 if (Old->hasExplicitTemplateArgs()) {
8237 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8238 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008239 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8240 Old->getNumTemplateArgs(),
8241 TransArgs))
8242 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008243 }
John McCallc2233c52010-01-15 08:34:02 +00008244
8245 // FIXME: to do this check properly, we will need to preserve the
8246 // first-qualifier-in-scope here, just in case we had a dependent
8247 // base (and therefore couldn't do the check) and a
8248 // nested-name-qualifier (and therefore could do the lookup).
8249 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008250
John McCall9ae2f072010-08-23 23:25:46 +00008251 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008252 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008253 Old->getOperatorLoc(),
8254 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008255 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008256 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008257 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008258 R,
8259 (Old->hasExplicitTemplateArgs()
8260 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008261}
8262
8263template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008264ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008265TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008266 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008267 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8268 if (SubExpr.isInvalid())
8269 return ExprError();
8270
8271 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008272 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008273
8274 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8275}
8276
8277template<typename Derived>
8278ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008279TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008280 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8281 if (Pattern.isInvalid())
8282 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008283
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008284 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8285 return SemaRef.Owned(E);
8286
Douglas Gregor67fd1252011-01-14 21:20:45 +00008287 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8288 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008289}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008290
8291template<typename Derived>
8292ExprResult
8293TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8294 // If E is not value-dependent, then nothing will change when we transform it.
8295 // Note: This is an instantiation-centric view.
8296 if (!E->isValueDependent())
8297 return SemaRef.Owned(E);
8298
8299 // Note: None of the implementations of TryExpandParameterPacks can ever
8300 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008301 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008302 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8303 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008304 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008305 llvm::Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008306 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008307 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008308 ShouldExpand, RetainExpansion,
8309 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008310 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008311
Douglas Gregor089e8932011-10-10 18:59:29 +00008312 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008313 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008314
Douglas Gregor089e8932011-10-10 18:59:29 +00008315 NamedDecl *Pack = E->getPack();
8316 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008317 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008318 Pack));
8319 if (!Pack)
8320 return ExprError();
8321 }
8322
Chad Rosier4a9d7952012-08-08 18:46:20 +00008323
Douglas Gregoree8aff02011-01-04 17:33:58 +00008324 // We now know the length of the parameter pack, so build a new expression
8325 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008326 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8327 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008328 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008329}
8330
Douglas Gregorbe230c32011-01-03 17:17:50 +00008331template<typename Derived>
8332ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008333TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8334 SubstNonTypeTemplateParmPackExpr *E) {
8335 // Default behavior is to do nothing with this transformation.
8336 return SemaRef.Owned(E);
8337}
8338
8339template<typename Derived>
8340ExprResult
John McCall91a57552011-07-15 05:09:51 +00008341TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8342 SubstNonTypeTemplateParmExpr *E) {
8343 // Default behavior is to do nothing with this transformation.
8344 return SemaRef.Owned(E);
8345}
8346
8347template<typename Derived>
8348ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008349TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8350 MaterializeTemporaryExpr *E) {
8351 return getDerived().TransformExpr(E->GetTemporaryExpr());
8352}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008353
Douglas Gregor03e80032011-06-21 17:03:29 +00008354template<typename Derived>
8355ExprResult
John McCall454feb92009-12-08 09:21:05 +00008356TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008357 return SemaRef.MaybeBindToTemporary(E);
8358}
8359
8360template<typename Derived>
8361ExprResult
8362TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008363 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008364}
8365
8366template<typename Derived>
8367ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008368TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8369 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8370 if (SubExpr.isInvalid())
8371 return ExprError();
8372
8373 if (!getDerived().AlwaysRebuild() &&
8374 SubExpr.get() == E->getSubExpr())
8375 return SemaRef.Owned(E);
8376
8377 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008378}
8379
8380template<typename Derived>
8381ExprResult
8382TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8383 // Transform each of the elements.
8384 llvm::SmallVector<Expr *, 8> Elements;
8385 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008386 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008387 /*IsCall=*/false, Elements, &ArgChanged))
8388 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008389
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008390 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8391 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008392
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008393 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8394 Elements.data(),
8395 Elements.size());
8396}
8397
8398template<typename Derived>
8399ExprResult
8400TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008401 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008402 // Transform each of the elements.
8403 llvm::SmallVector<ObjCDictionaryElement, 8> Elements;
8404 bool ArgChanged = false;
8405 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8406 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008407
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008408 if (OrigElement.isPackExpansion()) {
8409 // This key/value element is a pack expansion.
8410 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8411 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8412 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8413 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8414
8415 // Determine whether the set of unexpanded parameter packs can
8416 // and should be expanded.
8417 bool Expand = true;
8418 bool RetainExpansion = false;
8419 llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8420 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
8421 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8422 OrigElement.Value->getLocEnd());
8423 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8424 PatternRange,
8425 Unexpanded,
8426 Expand, RetainExpansion,
8427 NumExpansions))
8428 return ExprError();
8429
8430 if (!Expand) {
8431 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008432 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008433 // expansion.
8434 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8435 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8436 if (Key.isInvalid())
8437 return ExprError();
8438
8439 if (Key.get() != OrigElement.Key)
8440 ArgChanged = true;
8441
8442 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8443 if (Value.isInvalid())
8444 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008445
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008446 if (Value.get() != OrigElement.Value)
8447 ArgChanged = true;
8448
Chad Rosier4a9d7952012-08-08 18:46:20 +00008449 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008450 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8451 };
8452 Elements.push_back(Expansion);
8453 continue;
8454 }
8455
8456 // Record right away that the argument was changed. This needs
8457 // to happen even if the array expands to nothing.
8458 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008459
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008460 // The transform has determined that we should perform an elementwise
8461 // expansion of the pattern. Do so.
8462 for (unsigned I = 0; I != *NumExpansions; ++I) {
8463 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8464 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8465 if (Key.isInvalid())
8466 return ExprError();
8467
8468 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8469 if (Value.isInvalid())
8470 return ExprError();
8471
Chad Rosier4a9d7952012-08-08 18:46:20 +00008472 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008473 Key.get(), Value.get(), SourceLocation(), NumExpansions
8474 };
8475
8476 // If any unexpanded parameter packs remain, we still have a
8477 // pack expansion.
8478 if (Key.get()->containsUnexpandedParameterPack() ||
8479 Value.get()->containsUnexpandedParameterPack())
8480 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008481
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008482 Elements.push_back(Element);
8483 }
8484
8485 // We've finished with this pack expansion.
8486 continue;
8487 }
8488
8489 // Transform and check key.
8490 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8491 if (Key.isInvalid())
8492 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008493
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008494 if (Key.get() != OrigElement.Key)
8495 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008496
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008497 // Transform and check value.
8498 ExprResult Value
8499 = getDerived().TransformExpr(OrigElement.Value);
8500 if (Value.isInvalid())
8501 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008502
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008503 if (Value.get() != OrigElement.Value)
8504 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008505
8506 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008507 Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8508 };
8509 Elements.push_back(Element);
8510 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008511
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008512 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8513 return SemaRef.MaybeBindToTemporary(E);
8514
8515 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8516 Elements.data(),
8517 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008518}
8519
Mike Stump1eb44332009-09-09 15:08:12 +00008520template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008521ExprResult
John McCall454feb92009-12-08 09:21:05 +00008522TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008523 TypeSourceInfo *EncodedTypeInfo
8524 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8525 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008526 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008527
Douglas Gregorb98b1992009-08-11 05:31:07 +00008528 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008529 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008530 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008531
8532 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008533 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008534 E->getRParenLoc());
8535}
Mike Stump1eb44332009-09-09 15:08:12 +00008536
Douglas Gregorb98b1992009-08-11 05:31:07 +00008537template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008538ExprResult TreeTransform<Derived>::
8539TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8540 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8541 if (result.isInvalid()) return ExprError();
8542 Expr *subExpr = result.take();
8543
8544 if (!getDerived().AlwaysRebuild() &&
8545 subExpr == E->getSubExpr())
8546 return SemaRef.Owned(E);
8547
8548 return SemaRef.Owned(new(SemaRef.Context)
8549 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8550}
8551
8552template<typename Derived>
8553ExprResult TreeTransform<Derived>::
8554TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008555 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008556 = getDerived().TransformType(E->getTypeInfoAsWritten());
8557 if (!TSInfo)
8558 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008559
John McCallf85e1932011-06-15 23:02:42 +00008560 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008561 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008562 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008563
John McCallf85e1932011-06-15 23:02:42 +00008564 if (!getDerived().AlwaysRebuild() &&
8565 TSInfo == E->getTypeInfoAsWritten() &&
8566 Result.get() == E->getSubExpr())
8567 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008568
John McCallf85e1932011-06-15 23:02:42 +00008569 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008570 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008571 Result.get());
8572}
8573
8574template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008575ExprResult
John McCall454feb92009-12-08 09:21:05 +00008576TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008577 // Transform arguments.
8578 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008579 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008580 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008581 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008582 &ArgChanged))
8583 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008584
Douglas Gregor92e986e2010-04-22 16:44:27 +00008585 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8586 // Class message: transform the receiver type.
8587 TypeSourceInfo *ReceiverTypeInfo
8588 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8589 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008590 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008591
Douglas Gregor92e986e2010-04-22 16:44:27 +00008592 // If nothing changed, just retain the existing message send.
8593 if (!getDerived().AlwaysRebuild() &&
8594 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008595 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008596
8597 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008598 SmallVector<SourceLocation, 16> SelLocs;
8599 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008600 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8601 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008602 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008603 E->getMethodDecl(),
8604 E->getLeftLoc(),
8605 move_arg(Args),
8606 E->getRightLoc());
8607 }
8608
8609 // Instance message: transform the receiver
8610 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8611 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008612 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008613 = getDerived().TransformExpr(E->getInstanceReceiver());
8614 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008615 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008616
8617 // If nothing changed, just retain the existing message send.
8618 if (!getDerived().AlwaysRebuild() &&
8619 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008620 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008621
Douglas Gregor92e986e2010-04-22 16:44:27 +00008622 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008623 SmallVector<SourceLocation, 16> SelLocs;
8624 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008625 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008626 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008627 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008628 E->getMethodDecl(),
8629 E->getLeftLoc(),
8630 move_arg(Args),
8631 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008632}
8633
Mike Stump1eb44332009-09-09 15:08:12 +00008634template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008635ExprResult
John McCall454feb92009-12-08 09:21:05 +00008636TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008637 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008638}
8639
Mike Stump1eb44332009-09-09 15:08:12 +00008640template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008641ExprResult
John McCall454feb92009-12-08 09:21:05 +00008642TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008643 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008644}
8645
Mike Stump1eb44332009-09-09 15:08:12 +00008646template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008647ExprResult
John McCall454feb92009-12-08 09:21:05 +00008648TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008649 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008650 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008651 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008652 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008653
8654 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008655
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008656 // If nothing changed, just retain the existing expression.
8657 if (!getDerived().AlwaysRebuild() &&
8658 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008659 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008660
John McCall9ae2f072010-08-23 23:25:46 +00008661 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008662 E->getLocation(),
8663 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008664}
8665
Mike Stump1eb44332009-09-09 15:08:12 +00008666template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008667ExprResult
John McCall454feb92009-12-08 09:21:05 +00008668TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008669 // 'super' and types never change. Property never changes. Just
8670 // retain the existing expression.
8671 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008672 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008673
Douglas Gregore3303542010-04-26 20:47:02 +00008674 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008675 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008676 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008677 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008678
Douglas Gregore3303542010-04-26 20:47:02 +00008679 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008680
Douglas Gregore3303542010-04-26 20:47:02 +00008681 // If nothing changed, just retain the existing expression.
8682 if (!getDerived().AlwaysRebuild() &&
8683 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008684 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008685
John McCall12f78a62010-12-02 01:19:52 +00008686 if (E->isExplicitProperty())
8687 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8688 E->getExplicitProperty(),
8689 E->getLocation());
8690
8691 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008692 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008693 E->getImplicitPropertyGetter(),
8694 E->getImplicitPropertySetter(),
8695 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008696}
8697
Mike Stump1eb44332009-09-09 15:08:12 +00008698template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008699ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008700TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8701 // Transform the base expression.
8702 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8703 if (Base.isInvalid())
8704 return ExprError();
8705
8706 // Transform the key expression.
8707 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8708 if (Key.isInvalid())
8709 return ExprError();
8710
8711 // If nothing changed, just retain the existing expression.
8712 if (!getDerived().AlwaysRebuild() &&
8713 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8714 return SemaRef.Owned(E);
8715
Chad Rosier4a9d7952012-08-08 18:46:20 +00008716 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008717 Base.get(), Key.get(),
8718 E->getAtIndexMethodDecl(),
8719 E->setAtIndexMethodDecl());
8720}
8721
8722template<typename Derived>
8723ExprResult
John McCall454feb92009-12-08 09:21:05 +00008724TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008725 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008726 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008727 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008728 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008729
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008730 // If nothing changed, just retain the existing expression.
8731 if (!getDerived().AlwaysRebuild() &&
8732 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008733 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008734
John McCall9ae2f072010-08-23 23:25:46 +00008735 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008736 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008737}
8738
Mike Stump1eb44332009-09-09 15:08:12 +00008739template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008740ExprResult
John McCall454feb92009-12-08 09:21:05 +00008741TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008742 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008743 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008744 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008745 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008746 SubExprs, &ArgumentChanged))
8747 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008748
Douglas Gregorb98b1992009-08-11 05:31:07 +00008749 if (!getDerived().AlwaysRebuild() &&
8750 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008751 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008752
Douglas Gregorb98b1992009-08-11 05:31:07 +00008753 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8754 move_arg(SubExprs),
8755 E->getRParenLoc());
8756}
8757
Mike Stump1eb44332009-09-09 15:08:12 +00008758template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008759ExprResult
John McCall454feb92009-12-08 09:21:05 +00008760TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008761 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008762
John McCallc6ac9c32011-02-04 18:33:18 +00008763 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8764 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8765
8766 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008767 blockScope->TheDecl->setBlockMissingReturnType(
8768 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008769
Chris Lattner686775d2011-07-20 06:58:45 +00008770 SmallVector<ParmVarDecl*, 4> params;
8771 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008772
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008773 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008774 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8775 oldBlock->param_begin(),
8776 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008777 0, paramTypes, &params)) {
8778 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008779 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008780 }
John McCallc6ac9c32011-02-04 18:33:18 +00008781
8782 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008783 QualType exprResultType =
8784 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008785
8786 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008787 if (exprResultType->isObjCObjectType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008788 getSema().Diag(E->getCaretLocation(),
8789 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008790 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008791 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008792 return ExprError();
8793 }
John McCall711c52b2011-01-05 12:14:39 +00008794
John McCallc6ac9c32011-02-04 18:33:18 +00008795 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008796 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008797 paramTypes.data(),
8798 paramTypes.size(),
8799 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008800 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008801 exprFunctionType->getExtInfo());
8802 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008803
8804 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008805 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008806 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008807
8808 if (!oldBlock->blockMissingReturnType()) {
8809 blockScope->HasImplicitReturnType = false;
8810 blockScope->ReturnType = exprResultType;
8811 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008812
John McCall711c52b2011-01-05 12:14:39 +00008813 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008814 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008815 if (body.isInvalid()) {
8816 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008817 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008818 }
John McCall711c52b2011-01-05 12:14:39 +00008819
John McCallc6ac9c32011-02-04 18:33:18 +00008820#ifndef NDEBUG
8821 // In builds with assertions, make sure that we captured everything we
8822 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008823 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8824 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8825 e = oldBlock->capture_end(); i != e; ++i) {
8826 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008827
Douglas Gregorfc921372011-05-20 15:32:55 +00008828 // Ignore parameter packs.
8829 if (isa<ParmVarDecl>(oldCapture) &&
8830 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8831 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008832
Douglas Gregorfc921372011-05-20 15:32:55 +00008833 VarDecl *newCapture =
8834 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8835 oldCapture));
8836 assert(blockScope->CaptureMap.count(newCapture));
8837 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008838 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008839 }
8840#endif
8841
8842 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8843 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008844}
8845
Mike Stump1eb44332009-09-09 15:08:12 +00008846template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008847ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008848TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008849 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008850}
Eli Friedman276b0612011-10-11 02:20:01 +00008851
8852template<typename Derived>
8853ExprResult
8854TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008855 QualType RetTy = getDerived().TransformType(E->getType());
8856 bool ArgumentChanged = false;
8857 ASTOwningVector<Expr*> SubExprs(SemaRef);
8858 SubExprs.reserve(E->getNumSubExprs());
8859 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8860 SubExprs, &ArgumentChanged))
8861 return ExprError();
8862
8863 if (!getDerived().AlwaysRebuild() &&
8864 !ArgumentChanged)
8865 return SemaRef.Owned(E);
8866
8867 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8868 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008869}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008870
Douglas Gregorb98b1992009-08-11 05:31:07 +00008871//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008872// Type reconstruction
8873//===----------------------------------------------------------------------===//
8874
Mike Stump1eb44332009-09-09 15:08:12 +00008875template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008876QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8877 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008878 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008879 getDerived().getBaseEntity());
8880}
8881
Mike Stump1eb44332009-09-09 15:08:12 +00008882template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008883QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8884 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008885 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008886 getDerived().getBaseEntity());
8887}
8888
Mike Stump1eb44332009-09-09 15:08:12 +00008889template<typename Derived>
8890QualType
John McCall85737a72009-10-30 00:06:24 +00008891TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8892 bool WrittenAsLValue,
8893 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008894 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008895 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008896}
8897
8898template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008899QualType
John McCall85737a72009-10-30 00:06:24 +00008900TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8901 QualType ClassType,
8902 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008903 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008904 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008905}
8906
8907template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008908QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008909TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8910 ArrayType::ArraySizeModifier SizeMod,
8911 const llvm::APInt *Size,
8912 Expr *SizeExpr,
8913 unsigned IndexTypeQuals,
8914 SourceRange BracketsRange) {
8915 if (SizeExpr || !Size)
8916 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8917 IndexTypeQuals, BracketsRange,
8918 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008919
8920 QualType Types[] = {
8921 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8922 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8923 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008924 };
8925 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8926 QualType SizeType;
8927 for (unsigned I = 0; I != NumTypes; ++I)
8928 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8929 SizeType = Types[I];
8930 break;
8931 }
Mike Stump1eb44332009-09-09 15:08:12 +00008932
Eli Friedman01f276d2012-01-25 23:20:27 +00008933 // Note that we can return a VariableArrayType here in the case where
8934 // the element type was a dependent VariableArrayType.
8935 IntegerLiteral *ArraySize
8936 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8937 /*FIXME*/BracketsRange.getBegin());
8938 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008939 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008940 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008941}
Mike Stump1eb44332009-09-09 15:08:12 +00008942
Douglas Gregor577f75a2009-08-04 16:50:30 +00008943template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008944QualType
8945TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008946 ArrayType::ArraySizeModifier SizeMod,
8947 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008948 unsigned IndexTypeQuals,
8949 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008950 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008951 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008952}
8953
8954template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008955QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008956TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008957 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008958 unsigned IndexTypeQuals,
8959 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008960 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008961 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008962}
Mike Stump1eb44332009-09-09 15:08:12 +00008963
Douglas Gregor577f75a2009-08-04 16:50:30 +00008964template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008965QualType
8966TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008967 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008968 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008969 unsigned IndexTypeQuals,
8970 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008971 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008972 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008973 IndexTypeQuals, BracketsRange);
8974}
8975
8976template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008977QualType
8978TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008979 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008980 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008981 unsigned IndexTypeQuals,
8982 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008983 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008984 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008985 IndexTypeQuals, BracketsRange);
8986}
8987
8988template<typename Derived>
8989QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008990 unsigned NumElements,
8991 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008992 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008993 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008994}
Mike Stump1eb44332009-09-09 15:08:12 +00008995
Douglas Gregor577f75a2009-08-04 16:50:30 +00008996template<typename Derived>
8997QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8998 unsigned NumElements,
8999 SourceLocation AttributeLoc) {
9000 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9001 NumElements, true);
9002 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009003 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9004 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009005 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009006}
Mike Stump1eb44332009-09-09 15:08:12 +00009007
Douglas Gregor577f75a2009-08-04 16:50:30 +00009008template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009009QualType
9010TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009011 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009012 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009013 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009014}
Mike Stump1eb44332009-09-09 15:08:12 +00009015
Douglas Gregor577f75a2009-08-04 16:50:30 +00009016template<typename Derived>
9017QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00009018 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009019 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00009020 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009021 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00009022 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00009023 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00009024 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00009025 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009026 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009027 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009028 getDerived().getBaseEntity(),
9029 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009030}
Mike Stump1eb44332009-09-09 15:08:12 +00009031
Douglas Gregor577f75a2009-08-04 16:50:30 +00009032template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009033QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9034 return SemaRef.Context.getFunctionNoProtoType(T);
9035}
9036
9037template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009038QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9039 assert(D && "no decl found");
9040 if (D->isInvalidDecl()) return QualType();
9041
Douglas Gregor92e986e2010-04-22 16:44:27 +00009042 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009043 TypeDecl *Ty;
9044 if (isa<UsingDecl>(D)) {
9045 UsingDecl *Using = cast<UsingDecl>(D);
9046 assert(Using->isTypeName() &&
9047 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9048
9049 // A valid resolved using typename decl points to exactly one type decl.
9050 assert(++Using->shadow_begin() == Using->shadow_end());
9051 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009052
John McCalled976492009-12-04 22:46:56 +00009053 } else {
9054 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9055 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9056 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9057 }
9058
9059 return SemaRef.Context.getTypeDeclType(Ty);
9060}
9061
9062template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009063QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9064 SourceLocation Loc) {
9065 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009066}
9067
9068template<typename Derived>
9069QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9070 return SemaRef.Context.getTypeOfType(Underlying);
9071}
9072
9073template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009074QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9075 SourceLocation Loc) {
9076 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009077}
9078
9079template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009080QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9081 UnaryTransformType::UTTKind UKind,
9082 SourceLocation Loc) {
9083 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9084}
9085
9086template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009087QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009088 TemplateName Template,
9089 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009090 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009091 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009092}
Mike Stump1eb44332009-09-09 15:08:12 +00009093
Douglas Gregordcee1a12009-08-06 05:28:30 +00009094template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009095QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9096 SourceLocation KWLoc) {
9097 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9098}
9099
9100template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009101TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009102TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009103 bool TemplateKW,
9104 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009105 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009106 Template);
9107}
9108
9109template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009110TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009111TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9112 const IdentifierInfo &Name,
9113 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009114 QualType ObjectType,
9115 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009116 UnqualifiedId TemplateName;
9117 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009118 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009119 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009120 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009121 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009122 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009123 /*EnteringContext=*/false,
9124 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009125 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009126}
Mike Stump1eb44332009-09-09 15:08:12 +00009127
Douglas Gregorb98b1992009-08-11 05:31:07 +00009128template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009129TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009130TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009131 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009132 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009133 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009134 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009135 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009136 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009137 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009138 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009139 Sema::TemplateTy Template;
9140 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009141 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009142 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009143 /*EnteringContext=*/false,
9144 Template);
9145 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009146}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009147
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009148template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009149ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009150TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9151 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009152 Expr *OrigCallee,
9153 Expr *First,
9154 Expr *Second) {
9155 Expr *Callee = OrigCallee->IgnoreParenCasts();
9156 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009157
Douglas Gregorb98b1992009-08-11 05:31:07 +00009158 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009159 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009160 if (!First->getType()->isOverloadableType() &&
9161 !Second->getType()->isOverloadableType())
9162 return getSema().CreateBuiltinArraySubscriptExpr(First,
9163 Callee->getLocStart(),
9164 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009165 } else if (Op == OO_Arrow) {
9166 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009167 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9168 } else if (Second == 0 || isPostIncDec) {
9169 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009170 // The argument is not of overloadable type, so try to create a
9171 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009172 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009173 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009174
John McCall9ae2f072010-08-23 23:25:46 +00009175 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009176 }
9177 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009178 if (!First->getType()->isOverloadableType() &&
9179 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009180 // Neither of the arguments is an overloadable type, so try to
9181 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009182 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009183 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009184 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009185 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009186 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009187
Douglas Gregorb98b1992009-08-11 05:31:07 +00009188 return move(Result);
9189 }
9190 }
Mike Stump1eb44332009-09-09 15:08:12 +00009191
9192 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009193 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009194 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009195
John McCall9ae2f072010-08-23 23:25:46 +00009196 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009197 assert(ULE->requiresADL());
9198
9199 // FIXME: Do we have to check
9200 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009201 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009202 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009203 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00009204 }
Mike Stump1eb44332009-09-09 15:08:12 +00009205
Douglas Gregorb98b1992009-08-11 05:31:07 +00009206 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009207 Expr *Args[2] = { First, Second };
9208 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009209
Douglas Gregorb98b1992009-08-11 05:31:07 +00009210 // Create the overloaded operator invocation for unary operators.
9211 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009212 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009213 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009214 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009215 }
Mike Stump1eb44332009-09-09 15:08:12 +00009216
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009217 if (Op == OO_Subscript) {
9218 SourceLocation LBrace;
9219 SourceLocation RBrace;
9220
9221 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9222 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9223 LBrace = SourceLocation::getFromRawEncoding(
9224 NameLoc.CXXOperatorName.BeginOpNameLoc);
9225 RBrace = SourceLocation::getFromRawEncoding(
9226 NameLoc.CXXOperatorName.EndOpNameLoc);
9227 } else {
9228 LBrace = Callee->getLocStart();
9229 RBrace = OpLoc;
9230 }
9231
9232 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9233 First, Second);
9234 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009235
Douglas Gregorb98b1992009-08-11 05:31:07 +00009236 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009237 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009238 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009239 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9240 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009241 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009242
Mike Stump1eb44332009-09-09 15:08:12 +00009243 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009244}
Mike Stump1eb44332009-09-09 15:08:12 +00009245
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009246template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009247ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009248TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009249 SourceLocation OperatorLoc,
9250 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009251 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009252 TypeSourceInfo *ScopeType,
9253 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009254 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009255 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009256 QualType BaseType = Base->getType();
9257 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009258 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009259 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009260 !BaseType->getAs<PointerType>()->getPointeeType()
9261 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009262 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009263 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009264 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009265 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009266 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009267 /*FIXME?*/true);
9268 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009269
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009270 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009271 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9272 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9273 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9274 NameInfo.setNamedTypeInfo(DestroyedType);
9275
Richard Smith6314db92012-05-15 06:15:11 +00009276 // The scope type is now known to be a valid nested name specifier
9277 // component. Tack it on to the end of the nested name specifier.
9278 if (ScopeType)
9279 SS.Extend(SemaRef.Context, SourceLocation(),
9280 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009281
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009282 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009283 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009284 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009285 SS, TemplateKWLoc,
9286 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009287 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009288 /*TemplateArgs*/ 0);
9289}
9290
Douglas Gregor577f75a2009-08-04 16:50:30 +00009291} // end namespace clang
9292
9293#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H