blob: 52f6c4d4c08a66d858f203084c8136918b70318d [file] [log] [blame]
Chris Lattner57ad3782011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner57ad3782011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattner57ad3782011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregor577f75a2009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
Chandler Carruth55fc8732012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3e4c6c42011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000027#include "clang/Lex/Preprocessor.h"
Chandler Carruth55fc8732012-12-04 09:13:33 +000028#include "clang/Sema/Designator.h"
29#include "clang/Sema/Lookup.h"
30#include "clang/Sema/Ownership.h"
31#include "clang/Sema/ParsedTemplate.h"
32#include "clang/Sema/ScopeInfo.h"
33#include "clang/Sema/SemaDiagnostic.h"
34#include "clang/Sema/SemaInternal.h"
David Blaikiea71f9d02011-09-22 02:34:54 +000035#include "llvm/ADT/ArrayRef.h"
John McCalla2becad2009-10-21 00:40:46 +000036#include "llvm/Support/ErrorHandling.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCall781472f2010-08-25 08:40:02 +000040using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000041
Douglas Gregor577f75a2009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump1eb44332009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump1eb44332009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor9151c112011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000101
Douglas Gregord3731192011-01-10 07:32:04 +0000102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000106
Douglas Gregord3731192011-01-10 07:32:04 +0000107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
Chad Rosier4a9d7952012-08-08 18:46:20 +0000111
Douglas Gregor577f75a2009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000114
Douglas Gregordfca6f52012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000119
Mike Stump1eb44332009-09-09 15:08:12 +0000120public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000123
Douglas Gregor577f75a2009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000130 }
131
John McCall60d7b3a2010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000134
Douglas Gregor577f75a2009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000138
Douglas Gregor577f75a2009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
144 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000145
Douglas Gregor577f75a2009-08-04 16:50:30 +0000146 /// \brief Returns the location of the entity being transformed, if that
147 /// information was not available elsewhere in the AST.
148 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000149 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000150 /// provide an alternative implementation that provides better location
151 /// information.
152 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000153
Douglas Gregor577f75a2009-08-04 16:50:30 +0000154 /// \brief Returns the name of the entity being transformed, if that
155 /// information was not available elsewhere in the AST.
156 ///
157 /// By default, returns an empty name. Subclasses can provide an alternative
158 /// implementation with a more precise name.
159 DeclarationName getBaseEntity() { return DeclarationName(); }
160
Douglas Gregorb98b1992009-08-11 05:31:07 +0000161 /// \brief Sets the "base" location and entity when that
162 /// information is known based on another transformation.
163 ///
164 /// By default, the source location and entity are ignored. Subclasses can
165 /// override this function to provide a customized implementation.
166 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000167
Douglas Gregorb98b1992009-08-11 05:31:07 +0000168 /// \brief RAII object that temporarily sets the base location and entity
169 /// used for reporting diagnostics in types.
170 class TemporaryBase {
171 TreeTransform &Self;
172 SourceLocation OldLocation;
173 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000174
Douglas Gregorb98b1992009-08-11 05:31:07 +0000175 public:
176 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000177 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000178 OldLocation = Self.getDerived().getBaseLocation();
179 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000180
Douglas Gregorae201f72011-01-25 17:51:48 +0000181 if (Location.isValid())
182 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000183 }
Mike Stump1eb44332009-09-09 15:08:12 +0000184
Douglas Gregorb98b1992009-08-11 05:31:07 +0000185 ~TemporaryBase() {
186 Self.getDerived().setBase(OldLocation, OldEntity);
187 }
188 };
Mike Stump1eb44332009-09-09 15:08:12 +0000189
190 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000191 /// transformed.
192 ///
193 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000194 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000195 /// not change. For example, template instantiation need not traverse
196 /// non-dependent types.
197 bool AlreadyTransformed(QualType T) {
198 return T.isNull();
199 }
200
Douglas Gregor6eef5192009-12-14 19:27:10 +0000201 /// \brief Determine whether the given call argument should be dropped, e.g.,
202 /// because it is a default argument.
203 ///
204 /// Subclasses can provide an alternative implementation of this routine to
205 /// determine which kinds of call arguments get dropped. By default,
206 /// CXXDefaultArgument nodes are dropped (prior to transformation).
207 bool DropCallArgument(Expr *E) {
208 return E->isDefaultArgument();
209 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000210
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000211 /// \brief Determine whether we should expand a pack expansion with the
212 /// given set of parameter packs into separate arguments by repeatedly
213 /// transforming the pattern.
214 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000215 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000216 /// Subclasses can override this routine to provide different behavior.
217 ///
218 /// \param EllipsisLoc The location of the ellipsis that identifies the
219 /// pack expansion.
220 ///
221 /// \param PatternRange The source range that covers the entire pattern of
222 /// the pack expansion.
223 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000224 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000225 /// pattern.
226 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000227 /// \param ShouldExpand Will be set to \c true if the transformer should
228 /// expand the corresponding pack expansions into separate arguments. When
229 /// set, \c NumExpansions must also be set.
230 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000231 /// \param RetainExpansion Whether the caller should add an unexpanded
232 /// pack expansion after all of the expanded arguments. This is used
233 /// when extending explicitly-specified template argument packs per
234 /// C++0x [temp.arg.explicit]p9.
235 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000236 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000237 /// the expanded form of the corresponding pack expansion. This is both an
238 /// input and an output parameter, which can be set by the caller if the
239 /// number of expansions is known a priori (e.g., due to a prior substitution)
240 /// and will be set by the callee when the number of expansions is known.
241 /// The callee must set this value when \c ShouldExpand is \c true; it may
242 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000243 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000244 /// \returns true if an error occurred (e.g., because the parameter packs
245 /// are to be instantiated with arguments of different lengths), false
246 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000247 /// must be set.
248 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
249 SourceRange PatternRange,
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
Richard Smithc83c2302012-12-19 01:39:02 +0000326 /// \brief Transform the given initializer.
327 ///
328 /// By default, this routine transforms an initializer by stripping off the
329 /// semantic nodes added by initialization, then passing the result to
330 /// TransformExpr or TransformExprs.
331 ///
332 /// \returns the transformed initializer.
333 ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
334
Douglas Gregoraa165f82011-01-03 19:04:46 +0000335 /// \brief Transform the given list of expressions.
336 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000337 /// This routine transforms a list of expressions by invoking
338 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregoraa165f82011-01-03 19:04:46 +0000339 /// support for variadic templates by expanding any pack expansions (if the
340 /// derived class permits such expansion) along the way. When pack expansions
341 /// are present, the number of outputs may not equal the number of inputs.
342 ///
343 /// \param Inputs The set of expressions to be transformed.
344 ///
345 /// \param NumInputs The number of expressions in \c Inputs.
346 ///
347 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier4a9d7952012-08-08 18:46:20 +0000348 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregoraa165f82011-01-03 19:04:46 +0000349 /// be.
350 ///
351 /// \param Outputs The transformed input expressions will be added to this
352 /// vector.
353 ///
354 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
355 /// due to transformation.
356 ///
357 /// \returns true if an error occurred, false otherwise.
358 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +0000359 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000360 bool *ArgChanged = 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000361
Douglas Gregor577f75a2009-08-04 16:50:30 +0000362 /// \brief Transform the given declaration, which is referenced from a type
363 /// or expression.
364 ///
Douglas Gregordfca6f52012-02-13 22:00:16 +0000365 /// By default, acts as the identity function on declarations, unless the
366 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregordcee1a12009-08-06 05:28:30 +0000367 /// may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000368 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregordfca6f52012-02-13 22:00:16 +0000369 llvm::DenseMap<Decl *, Decl *>::iterator Known
370 = TransformedLocalDecls.find(D);
371 if (Known != TransformedLocalDecls.end())
372 return Known->second;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000373
374 return D;
Douglas Gregordfca6f52012-02-13 22:00:16 +0000375 }
Douglas Gregor43959a92009-08-20 07:17:43 +0000376
Chad Rosier4a9d7952012-08-08 18:46:20 +0000377 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregordfca6f52012-02-13 22:00:16 +0000378 /// place them on the new declaration.
379 ///
380 /// By default, this operation does nothing. Subclasses may override this
381 /// behavior to transform attributes.
382 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000383
Douglas Gregordfca6f52012-02-13 22:00:16 +0000384 /// \brief Note that a local declaration has been transformed by this
385 /// transformer.
386 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000387 /// Local declarations are typically transformed via a call to
Douglas Gregordfca6f52012-02-13 22:00:16 +0000388 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
389 /// the transformer itself has to transform the declarations. This routine
390 /// can be overridden by a subclass that keeps track of such mappings.
391 void transformedLocalDecl(Decl *Old, Decl *New) {
392 TransformedLocalDecls[Old] = New;
393 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000394
Douglas Gregor43959a92009-08-20 07:17:43 +0000395 /// \brief Transform the definition of the given declaration.
396 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000397 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000398 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000399 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
400 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000401 }
Mike Stump1eb44332009-09-09 15:08:12 +0000402
Douglas Gregor6cd21982009-10-20 05:58:46 +0000403 /// \brief Transform the given declaration, which was the first part of a
404 /// nested-name-specifier in a member access expression.
405 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000406 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000407 /// identifier in a nested-name-specifier of a member access expression, e.g.,
408 /// the \c T in \c x->T::member
409 ///
410 /// By default, invokes TransformDecl() to transform the declaration.
411 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000412 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
413 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000414 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000415
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000416 /// \brief Transform the given nested-name-specifier with source-location
417 /// information.
418 ///
419 /// By default, transforms all of the types and declarations within the
420 /// nested-name-specifier. Subclasses may override this function to provide
421 /// alternate behavior.
422 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
423 NestedNameSpecifierLoc NNS,
424 QualType ObjectType = QualType(),
425 NamedDecl *FirstQualifierInScope = 0);
426
Douglas Gregor81499bb2009-09-03 22:13:48 +0000427 /// \brief Transform the given declaration name.
428 ///
429 /// By default, transforms the types of conversion function, constructor,
430 /// and destructor names and then (if needed) rebuilds the declaration name.
431 /// Identifiers and selectors are returned unmodified. Sublcasses may
432 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000433 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000434 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000435
Douglas Gregor577f75a2009-08-04 16:50:30 +0000436 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000437 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000438 /// \param SS The nested-name-specifier that qualifies the template
439 /// name. This nested-name-specifier must already have been transformed.
440 ///
441 /// \param Name The template name to transform.
442 ///
443 /// \param NameLoc The source location of the template name.
444 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000445 /// \param ObjectType If we're translating a template name within a member
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000446 /// access expression, this is the type of the object whose member template
447 /// is being referenced.
448 ///
449 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
450 /// also refers to a name within the current (lexical) scope, this is the
451 /// declaration it refers to.
452 ///
453 /// By default, transforms the template name by transforming the declarations
454 /// and nested-name-specifiers that occur within the template name.
455 /// Subclasses may override this function to provide alternate behavior.
456 TemplateName TransformTemplateName(CXXScopeSpec &SS,
457 TemplateName Name,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000458 SourceLocation NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000459 QualType ObjectType = QualType(),
460 NamedDecl *FirstQualifierInScope = 0);
461
Douglas Gregor577f75a2009-08-04 16:50:30 +0000462 /// \brief Transform the given template argument.
463 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000464 /// By default, this operation transforms the type, expression, or
465 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000466 /// new template argument from the transformed result. Subclasses may
467 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000468 ///
469 /// Returns true if there was an error.
470 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
471 TemplateArgumentLoc &Output);
472
Douglas Gregorfcc12532010-12-20 17:31:10 +0000473 /// \brief Transform the given set of template arguments.
474 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000475 /// By default, this operation transforms all of the template arguments
Douglas Gregorfcc12532010-12-20 17:31:10 +0000476 /// in the input set using \c TransformTemplateArgument(), and appends
477 /// the transformed arguments to the output list.
478 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000479 /// Note that this overload of \c TransformTemplateArguments() is merely
480 /// a convenience function. Subclasses that wish to override this behavior
481 /// should override the iterator-based member template version.
482 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000483 /// \param Inputs The set of template arguments to be transformed.
484 ///
485 /// \param NumInputs The number of template arguments in \p Inputs.
486 ///
487 /// \param Outputs The set of transformed template arguments output by this
488 /// routine.
489 ///
490 /// Returns true if an error occurred.
491 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
492 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000493 TemplateArgumentListInfo &Outputs) {
494 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
495 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000496
497 /// \brief Transform the given set of template arguments.
498 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000499 /// By default, this operation transforms all of the template arguments
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000500 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier4a9d7952012-08-08 18:46:20 +0000501 /// the transformed arguments to the output list.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000502 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000503 /// \param First An iterator to the first template argument.
504 ///
505 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000506 ///
507 /// \param Outputs The set of transformed template arguments output by this
508 /// routine.
509 ///
510 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000511 template<typename InputIterator>
512 bool TransformTemplateArguments(InputIterator First,
513 InputIterator Last,
514 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000515
John McCall833ca992009-10-29 08:12:44 +0000516 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
517 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
518 TemplateArgumentLoc &ArgLoc);
519
John McCalla93c9342009-12-07 02:54:59 +0000520 /// \brief Fakes up a TypeSourceInfo for a type.
521 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
522 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000523 getDerived().getBaseLocation());
524 }
Mike Stump1eb44332009-09-09 15:08:12 +0000525
John McCalla2becad2009-10-21 00:40:46 +0000526#define ABSTRACT_TYPELOC(CLASS, PARENT)
527#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000528 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000529#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000530
Douglas Gregorcefc3af2012-04-16 07:05:22 +0000531 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
532 FunctionProtoTypeLoc TL,
533 CXXRecordDecl *ThisContext,
534 unsigned ThisTypeQuals);
535
John Wiegley28bbe4b2011-04-28 01:08:34 +0000536 StmtResult
537 TransformSEHHandler(Stmt *Handler);
538
Chad Rosier4a9d7952012-08-08 18:46:20 +0000539 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000540 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
541 TemplateSpecializationTypeLoc TL,
542 TemplateName Template);
543
Chad Rosier4a9d7952012-08-08 18:46:20 +0000544 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000545 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
546 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000547 TemplateName Template,
548 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000549
Chad Rosier4a9d7952012-08-08 18:46:20 +0000550 QualType
Douglas Gregora88f09f2011-02-28 17:23:35 +0000551 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000552 DependentTemplateSpecializationTypeLoc TL,
553 NestedNameSpecifierLoc QualifierLoc);
554
John McCall21ef0fa2010-03-11 09:03:00 +0000555 /// \brief Transforms the parameters of a function type into the
556 /// given vectors.
557 ///
558 /// The result vectors should be kept in sync; null entries in the
559 /// variables vector are acceptable.
560 ///
561 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000562 bool TransformFunctionTypeParams(SourceLocation Loc,
563 ParmVarDecl **Params, unsigned NumParams,
564 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000565 SmallVectorImpl<QualType> &PTypes,
566 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000567
568 /// \brief Transforms a single function-type parameter. Return null
569 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000570 ///
571 /// \param indexAdjustment - A number to add to the parameter's
572 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000573 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000574 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000575 llvm::Optional<unsigned> NumExpansions,
576 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000577
John McCall43fed0d2010-11-12 08:19:04 +0000578 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000579
John McCall60d7b3a2010-08-24 06:29:42 +0000580 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
581 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000582
Richard Smith612409e2012-07-25 03:56:55 +0000583 /// \brief Transform the captures and body of a lambda expression.
584 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator);
585
Richard Smithefeeccf2012-10-21 03:28:35 +0000586 ExprResult TransformAddressOfOperand(Expr *E);
587 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
588 bool IsAddressOfOperand);
589
Douglas Gregor43959a92009-08-20 07:17:43 +0000590#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000591 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000592#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000593 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000594#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000595#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000596
Douglas Gregor577f75a2009-08-04 16:50:30 +0000597 /// \brief Build a new pointer type given its pointee type.
598 ///
599 /// By default, performs semantic analysis when building the pointer type.
600 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000601 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000602
603 /// \brief Build a new block pointer type given its pointee type.
604 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000605 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000606 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000607 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000608
John McCall85737a72009-10-30 00:06:24 +0000609 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000610 ///
John McCall85737a72009-10-30 00:06:24 +0000611 /// By default, performs semantic analysis when building the
612 /// reference type. Subclasses may override this routine to provide
613 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000614 ///
John McCall85737a72009-10-30 00:06:24 +0000615 /// \param LValue whether the type was written with an lvalue sigil
616 /// or an rvalue sigil.
617 QualType RebuildReferenceType(QualType ReferentType,
618 bool LValue,
619 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000620
Douglas Gregor577f75a2009-08-04 16:50:30 +0000621 /// \brief Build a new member pointer type given the pointee type and the
622 /// class type it refers into.
623 ///
624 /// By default, performs semantic analysis when building the member pointer
625 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000626 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
627 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000628
Douglas Gregor577f75a2009-08-04 16:50:30 +0000629 /// \brief Build a new array type given the element type, size
630 /// modifier, size of the array (if known), size expression, and index type
631 /// qualifiers.
632 ///
633 /// By default, performs semantic analysis when building the array type.
634 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000635 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000636 QualType RebuildArrayType(QualType ElementType,
637 ArrayType::ArraySizeModifier SizeMod,
638 const llvm::APInt *Size,
639 Expr *SizeExpr,
640 unsigned IndexTypeQuals,
641 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000642
Douglas Gregor577f75a2009-08-04 16:50:30 +0000643 /// \brief Build a new constant array type given the element type, size
644 /// modifier, (known) size of the array, and index type qualifiers.
645 ///
646 /// By default, performs semantic analysis when building the array type.
647 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000648 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000649 ArrayType::ArraySizeModifier SizeMod,
650 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000651 unsigned IndexTypeQuals,
652 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000653
Douglas Gregor577f75a2009-08-04 16:50:30 +0000654 /// \brief Build a new incomplete array type given the element type, size
655 /// modifier, and index type qualifiers.
656 ///
657 /// By default, performs semantic analysis when building the array type.
658 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000659 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000660 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000661 unsigned IndexTypeQuals,
662 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000663
Mike Stump1eb44332009-09-09 15:08:12 +0000664 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000665 /// size modifier, size expression, and index type qualifiers.
666 ///
667 /// By default, performs semantic analysis when building the array type.
668 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000669 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000670 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000671 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000672 unsigned IndexTypeQuals,
673 SourceRange BracketsRange);
674
Mike Stump1eb44332009-09-09 15:08:12 +0000675 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000676 /// size modifier, size expression, and index type qualifiers.
677 ///
678 /// By default, performs semantic analysis when building the array type.
679 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000680 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000681 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000682 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000683 unsigned IndexTypeQuals,
684 SourceRange BracketsRange);
685
686 /// \brief Build a new vector type given the element type and
687 /// number of elements.
688 ///
689 /// By default, performs semantic analysis when building the vector type.
690 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000691 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000692 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000693
Douglas Gregor577f75a2009-08-04 16:50:30 +0000694 /// \brief Build a new extended vector type given the element type and
695 /// number of elements.
696 ///
697 /// By default, performs semantic analysis when building the vector type.
698 /// Subclasses may override this routine to provide different behavior.
699 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
700 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000701
702 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000703 /// given the element type and number of elements.
704 ///
705 /// By default, performs semantic analysis when building the vector type.
706 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000707 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000708 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000709 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000710
Douglas Gregor577f75a2009-08-04 16:50:30 +0000711 /// \brief Build a new function type.
712 ///
713 /// By default, performs semantic analysis when building the function type.
714 /// Subclasses may override this routine to provide different behavior.
715 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000716 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000717 unsigned NumParamTypes,
Richard Smitheefb3d52012-02-10 09:58:53 +0000718 bool Variadic, bool HasTrailingReturn,
719 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000720 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000721 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000722
John McCalla2becad2009-10-21 00:40:46 +0000723 /// \brief Build a new unprototyped function type.
724 QualType RebuildFunctionNoProtoType(QualType ResultType);
725
John McCalled976492009-12-04 22:46:56 +0000726 /// \brief Rebuild an unresolved typename type, given the decl that
727 /// the UnresolvedUsingTypenameDecl was transformed to.
728 QualType RebuildUnresolvedUsingType(Decl *D);
729
Douglas Gregor577f75a2009-08-04 16:50:30 +0000730 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000731 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000732 return SemaRef.Context.getTypeDeclType(Typedef);
733 }
734
735 /// \brief Build a new class/struct/union type.
736 QualType RebuildRecordType(RecordDecl *Record) {
737 return SemaRef.Context.getTypeDeclType(Record);
738 }
739
740 /// \brief Build a new Enum type.
741 QualType RebuildEnumType(EnumDecl *Enum) {
742 return SemaRef.Context.getTypeDeclType(Enum);
743 }
John McCall7da24312009-09-05 00:15:47 +0000744
Mike Stump1eb44332009-09-09 15:08:12 +0000745 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000746 ///
747 /// By default, performs semantic analysis when building the typeof type.
748 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000749 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000750
Mike Stump1eb44332009-09-09 15:08:12 +0000751 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000752 ///
753 /// By default, builds a new TypeOfType with the given underlying type.
754 QualType RebuildTypeOfType(QualType Underlying);
755
Sean Huntca63c202011-05-24 22:41:36 +0000756 /// \brief Build a new unary transform type.
757 QualType RebuildUnaryTransformType(QualType BaseType,
758 UnaryTransformType::UTTKind UKind,
759 SourceLocation Loc);
760
Mike Stump1eb44332009-09-09 15:08:12 +0000761 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000762 ///
763 /// By default, performs semantic analysis when building the decltype type.
764 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000765 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000766
Richard Smith34b41d92011-02-20 03:19:35 +0000767 /// \brief Build a new C++0x auto type.
768 ///
769 /// By default, builds a new AutoType with the given deduced type.
770 QualType RebuildAutoType(QualType Deduced) {
771 return SemaRef.Context.getAutoType(Deduced);
772 }
773
Douglas Gregor577f75a2009-08-04 16:50:30 +0000774 /// \brief Build a new template specialization type.
775 ///
776 /// By default, performs semantic analysis when building the template
777 /// specialization type. Subclasses may override this routine to provide
778 /// different behavior.
779 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000780 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000781 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000782
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000783 /// \brief Build a new parenthesized type.
784 ///
785 /// By default, builds a new ParenType type from the inner type.
786 /// Subclasses may override this routine to provide different behavior.
787 QualType RebuildParenType(QualType InnerType) {
788 return SemaRef.Context.getParenType(InnerType);
789 }
790
Douglas Gregor577f75a2009-08-04 16:50:30 +0000791 /// \brief Build a new qualified name type.
792 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000793 /// By default, builds a new ElaboratedType type from the keyword,
794 /// the nested-name-specifier and the named type.
795 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000796 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
797 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000798 NestedNameSpecifierLoc QualifierLoc,
799 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000800 return SemaRef.Context.getElaboratedType(Keyword,
801 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000802 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000803 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000804
805 /// \brief Build a new typename type that refers to a template-id.
806 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000807 /// By default, builds a new DependentNameType type from the
808 /// nested-name-specifier and the given type. Subclasses may override
809 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000810 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000811 ElaboratedTypeKeyword Keyword,
812 NestedNameSpecifierLoc QualifierLoc,
813 const IdentifierInfo *Name,
814 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000815 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000816 // Rebuild the template name.
817 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000818 CXXScopeSpec SS;
819 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000820 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000821 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000822
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000823 if (InstName.isNull())
824 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000825
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000826 // If it's still dependent, make a dependent specialization.
827 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000828 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
829 QualifierLoc.getNestedNameSpecifier(),
830 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000831 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000832
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000833 // Otherwise, make an elaborated type wrapping a non-dependent
834 // specialization.
835 QualType T =
836 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
837 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000838
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000839 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
840 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000841
842 return SemaRef.Context.getElaboratedType(Keyword,
843 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000844 T);
845 }
846
Douglas Gregor577f75a2009-08-04 16:50:30 +0000847 /// \brief Build a new typename type that refers to an identifier.
848 ///
849 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000850 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000851 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000852 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000853 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000854 NestedNameSpecifierLoc QualifierLoc,
855 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000856 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000857 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000858 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000859
Douglas Gregor2494dd02011-03-01 01:34:45 +0000860 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000861 // If the name is still dependent, just build a new dependent name type.
862 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000863 return SemaRef.Context.getDependentNameType(Keyword,
864 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000865 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000866 }
867
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000868 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000869 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000870 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000871
872 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
873
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000874 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000875 // into a non-dependent elaborated-type-specifier. Find the tag we're
876 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000877 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000878 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
879 if (!DC)
880 return QualType();
881
John McCall56138762010-05-27 06:40:31 +0000882 if (SemaRef.RequireCompleteDeclContext(SS, DC))
883 return QualType();
884
Douglas Gregor40336422010-03-31 22:19:08 +0000885 TagDecl *Tag = 0;
886 SemaRef.LookupQualifiedName(Result, DC);
887 switch (Result.getResultKind()) {
888 case LookupResult::NotFound:
889 case LookupResult::NotFoundInCurrentInstantiation:
890 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000891
Douglas Gregor40336422010-03-31 22:19:08 +0000892 case LookupResult::Found:
893 Tag = Result.getAsSingle<TagDecl>();
894 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000895
Douglas Gregor40336422010-03-31 22:19:08 +0000896 case LookupResult::FoundOverloaded:
897 case LookupResult::FoundUnresolvedValue:
898 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000899
Douglas Gregor40336422010-03-31 22:19:08 +0000900 case LookupResult::Ambiguous:
901 // Let the LookupResult structure handle ambiguities.
902 return QualType();
903 }
904
905 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000906 // Check where the name exists but isn't a tag type and use that to emit
907 // better diagnostics.
908 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
909 SemaRef.LookupQualifiedName(Result, DC);
910 switch (Result.getResultKind()) {
911 case LookupResult::Found:
912 case LookupResult::FoundOverloaded:
913 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000914 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000915 unsigned Kind = 0;
916 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000917 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
918 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000919 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
920 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
921 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000922 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000923 default:
924 // FIXME: Would be nice to highlight just the source range.
925 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
926 << Kind << Id << DC;
927 break;
928 }
Douglas Gregor40336422010-03-31 22:19:08 +0000929 return QualType();
930 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000931
Richard Trieubbf34c02011-06-10 03:11:26 +0000932 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
933 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000934 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000935 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
936 return QualType();
937 }
938
939 // Build the elaborated-type-specifier type.
940 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000941 return SemaRef.Context.getElaboratedType(Keyword,
942 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000943 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000944 }
Mike Stump1eb44332009-09-09 15:08:12 +0000945
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000946 /// \brief Build a new pack expansion type.
947 ///
948 /// By default, builds a new PackExpansionType type from the given pattern.
949 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000950 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000951 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000952 SourceLocation EllipsisLoc,
953 llvm::Optional<unsigned> NumExpansions) {
954 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
955 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000956 }
957
Eli Friedmanb001de72011-10-06 23:00:33 +0000958 /// \brief Build a new atomic type given its value type.
959 ///
960 /// By default, performs semantic analysis when building the atomic type.
961 /// Subclasses may override this routine to provide different behavior.
962 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
963
Douglas Gregord1067e52009-08-06 06:41:21 +0000964 /// \brief Build a new template name given a nested name specifier, a flag
965 /// indicating whether the "template" keyword was provided, and the template
966 /// that the template name refers to.
967 ///
968 /// By default, builds the new template name directly. Subclasses may override
969 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000970 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000971 bool TemplateKW,
972 TemplateDecl *Template);
973
Douglas Gregord1067e52009-08-06 06:41:21 +0000974 /// \brief Build a new template name given a nested name specifier and the
975 /// 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,
982 const IdentifierInfo &Name,
983 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000984 QualType ObjectType,
985 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000986
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000987 /// \brief Build a new template name given a nested name specifier and the
988 /// overloaded operator name that is referred to as a template.
989 ///
990 /// By default, performs semantic analysis to determine whether the name can
991 /// be resolved to a specific template, then builds the appropriate kind of
992 /// template name. Subclasses may override this routine to provide different
993 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000994 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000995 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000996 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000997 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000998
999 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +00001000 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001001 ///
1002 /// By default, performs semantic analysis to determine whether the name can
1003 /// be resolved to a specific template, then builds the appropriate kind of
1004 /// template name. Subclasses may override this routine to provide different
1005 /// behavior.
1006 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1007 const TemplateArgument &ArgPack) {
1008 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1009 }
1010
Douglas Gregor43959a92009-08-20 07:17:43 +00001011 /// \brief Build a new compound statement.
1012 ///
1013 /// By default, performs semantic analysis to build the new statement.
1014 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001015 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001016 MultiStmtArg Statements,
1017 SourceLocation RBraceLoc,
1018 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001019 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001020 IsStmtExpr);
1021 }
1022
1023 /// \brief Build 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 RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001028 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001029 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001030 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001031 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001032 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001033 ColonLoc);
1034 }
Mike Stump1eb44332009-09-09 15:08:12 +00001035
Douglas Gregor43959a92009-08-20 07:17:43 +00001036 /// \brief Attach the body to a new case statement.
1037 ///
1038 /// By default, performs semantic analysis to build the new statement.
1039 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001040 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001041 getSema().ActOnCaseStmtBody(S, Body);
1042 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001043 }
Mike Stump1eb44332009-09-09 15:08:12 +00001044
Douglas Gregor43959a92009-08-20 07:17:43 +00001045 /// \brief Build a new default statement.
1046 ///
1047 /// By default, performs semantic analysis to build the new statement.
1048 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001049 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001050 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001051 Stmt *SubStmt) {
1052 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001053 /*CurScope=*/0);
1054 }
Mike Stump1eb44332009-09-09 15:08:12 +00001055
Douglas Gregor43959a92009-08-20 07:17:43 +00001056 /// \brief Build a new label statement.
1057 ///
1058 /// By default, performs semantic analysis to build the new statement.
1059 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001060 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1061 SourceLocation ColonLoc, Stmt *SubStmt) {
1062 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001063 }
Mike Stump1eb44332009-09-09 15:08:12 +00001064
Richard Smith534986f2012-04-14 00:33:13 +00001065 /// \brief Build a new label statement.
1066 ///
1067 /// By default, performs semantic analysis to build the new statement.
1068 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001069 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1070 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001071 Stmt *SubStmt) {
1072 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1073 }
1074
Douglas Gregor43959a92009-08-20 07:17:43 +00001075 /// \brief Build a new "if" statement.
1076 ///
1077 /// By default, performs semantic analysis to build the new statement.
1078 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001079 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001080 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001081 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001082 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001083 }
Mike Stump1eb44332009-09-09 15:08:12 +00001084
Douglas Gregor43959a92009-08-20 07:17:43 +00001085 /// \brief Start building a new switch statement.
1086 ///
1087 /// By default, performs semantic analysis to build the new statement.
1088 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001089 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001090 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001091 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001092 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001093 }
Mike Stump1eb44332009-09-09 15:08:12 +00001094
Douglas Gregor43959a92009-08-20 07:17:43 +00001095 /// \brief Attach the body to the switch statement.
1096 ///
1097 /// By default, performs semantic analysis to build the new statement.
1098 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001099 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001100 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001101 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001102 }
1103
1104 /// \brief Build a new while statement.
1105 ///
1106 /// By default, performs semantic analysis to build the new statement.
1107 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001108 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1109 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001110 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001111 }
Mike Stump1eb44332009-09-09 15:08:12 +00001112
Douglas Gregor43959a92009-08-20 07:17:43 +00001113 /// \brief Build a new do-while statement.
1114 ///
1115 /// By default, performs semantic analysis to build the new statement.
1116 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001117 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001118 SourceLocation WhileLoc, SourceLocation LParenLoc,
1119 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001120 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1121 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001122 }
1123
1124 /// \brief Build a new for statement.
1125 ///
1126 /// By default, performs semantic analysis to build the new statement.
1127 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001128 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001129 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001130 VarDecl *CondVar, Sema::FullExprArg Inc,
1131 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001132 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001133 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001134 }
Mike Stump1eb44332009-09-09 15:08:12 +00001135
Douglas Gregor43959a92009-08-20 07:17:43 +00001136 /// \brief Build a new goto statement.
1137 ///
1138 /// By default, performs semantic analysis to build the new statement.
1139 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001140 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1141 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001142 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001143 }
1144
1145 /// \brief Build a new indirect goto statement.
1146 ///
1147 /// By default, performs semantic analysis to build the new statement.
1148 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001149 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001150 SourceLocation StarLoc,
1151 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001152 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001153 }
Mike Stump1eb44332009-09-09 15:08:12 +00001154
Douglas Gregor43959a92009-08-20 07:17:43 +00001155 /// \brief Build a new return statement.
1156 ///
1157 /// By default, performs semantic analysis to build the new statement.
1158 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001159 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001160 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001161 }
Mike Stump1eb44332009-09-09 15:08:12 +00001162
Douglas Gregor43959a92009-08-20 07:17:43 +00001163 /// \brief Build a new declaration statement.
1164 ///
1165 /// By default, performs semantic analysis to build the new statement.
1166 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001167 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001168 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001169 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001170 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1171 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001172 }
Mike Stump1eb44332009-09-09 15:08:12 +00001173
Anders Carlsson703e3942010-01-24 05:50:09 +00001174 /// \brief Build a new inline asm statement.
1175 ///
1176 /// By default, performs semantic analysis to build the new statement.
1177 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001178 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1179 bool IsVolatile, unsigned NumOutputs,
1180 unsigned NumInputs, IdentifierInfo **Names,
1181 MultiExprArg Constraints, MultiExprArg Exprs,
1182 Expr *AsmString, MultiExprArg Clobbers,
1183 SourceLocation RParenLoc) {
1184 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1185 NumInputs, Names, Constraints, Exprs,
1186 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001187 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001188
Chad Rosier8cd64b42012-06-11 20:47:18 +00001189 /// \brief Build a new MS style inline asm statement.
1190 ///
1191 /// By default, performs semantic analysis to build the new statement.
1192 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001193 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
1194 ArrayRef<Token> AsmToks, SourceLocation EndLoc) {
Chad Rosier7bd092b2012-08-15 16:53:30 +00001195 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001196 }
1197
James Dennett699c9042012-06-15 07:13:21 +00001198 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001199 ///
1200 /// By default, performs semantic analysis to build the new statement.
1201 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001202 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001203 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001204 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001205 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001206 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001207 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001208 }
1209
Douglas Gregorbe270a02010-04-26 17:57:08 +00001210 /// \brief Rebuild an Objective-C exception declaration.
1211 ///
1212 /// By default, performs semantic analysis to build the new declaration.
1213 /// Subclasses may override this routine to provide different behavior.
1214 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1215 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001216 return getSema().BuildObjCExceptionDecl(TInfo, T,
1217 ExceptionDecl->getInnerLocStart(),
1218 ExceptionDecl->getLocation(),
1219 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001220 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001221
James Dennett699c9042012-06-15 07:13:21 +00001222 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001223 ///
1224 /// By default, performs semantic analysis to build the new statement.
1225 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001226 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001227 SourceLocation RParenLoc,
1228 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001229 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001230 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001231 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001232 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001233
James Dennett699c9042012-06-15 07:13:21 +00001234 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001235 ///
1236 /// By default, performs semantic analysis to build the new statement.
1237 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001238 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001239 Stmt *Body) {
1240 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001241 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001242
James Dennett699c9042012-06-15 07:13:21 +00001243 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001244 ///
1245 /// By default, performs semantic analysis to build the new statement.
1246 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001247 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001248 Expr *Operand) {
1249 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001250 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001251
James Dennett699c9042012-06-15 07:13:21 +00001252 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001253 ///
1254 /// By default, performs semantic analysis to build the new statement.
1255 /// Subclasses may override this routine to provide different behavior.
1256 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1257 Expr *object) {
1258 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1259 }
1260
James Dennett699c9042012-06-15 07:13:21 +00001261 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001262 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001263 /// By default, performs semantic analysis to build the new statement.
1264 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001265 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001266 Expr *Object, Stmt *Body) {
1267 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001268 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001269
James Dennett699c9042012-06-15 07:13:21 +00001270 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001271 ///
1272 /// By default, performs semantic analysis to build the new statement.
1273 /// Subclasses may override this routine to provide different behavior.
1274 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1275 Stmt *Body) {
1276 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1277 }
John McCall990567c2011-07-27 01:07:15 +00001278
Douglas Gregorc3203e72010-04-22 23:10:45 +00001279 /// \brief Build a new Objective-C fast enumeration statement.
1280 ///
1281 /// By default, performs semantic analysis to build the new statement.
1282 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001283 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001284 Stmt *Element,
1285 Expr *Collection,
1286 SourceLocation RParenLoc,
1287 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001288 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001289 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001290 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001291 RParenLoc);
1292 if (ForEachStmt.isInvalid())
1293 return StmtError();
1294
1295 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001296 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001297
Douglas Gregor43959a92009-08-20 07:17:43 +00001298 /// \brief Build a new C++ exception declaration.
1299 ///
1300 /// By default, performs semantic analysis to build the new decaration.
1301 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001302 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001303 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001304 SourceLocation StartLoc,
1305 SourceLocation IdLoc,
1306 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001307 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1308 StartLoc, IdLoc, Id);
1309 if (Var)
1310 getSema().CurContext->addDecl(Var);
1311 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001312 }
1313
1314 /// \brief Build a new C++ catch statement.
1315 ///
1316 /// By default, performs semantic analysis to build the new statement.
1317 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001318 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001319 VarDecl *ExceptionDecl,
1320 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001321 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1322 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001323 }
Mike Stump1eb44332009-09-09 15:08:12 +00001324
Douglas Gregor43959a92009-08-20 07:17:43 +00001325 /// \brief Build a new C++ try statement.
1326 ///
1327 /// By default, performs semantic analysis to build the new statement.
1328 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001329 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001330 Stmt *TryBlock,
1331 MultiStmtArg Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001332 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001333 }
Mike Stump1eb44332009-09-09 15:08:12 +00001334
Richard Smithad762fc2011-04-14 22:09:26 +00001335 /// \brief Build a new C++0x range-based for statement.
1336 ///
1337 /// By default, performs semantic analysis to build the new statement.
1338 /// Subclasses may override this routine to provide different behavior.
1339 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1340 SourceLocation ColonLoc,
1341 Stmt *Range, Stmt *BeginEnd,
1342 Expr *Cond, Expr *Inc,
1343 Stmt *LoopVar,
1344 SourceLocation RParenLoc) {
1345 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001346 Cond, Inc, LoopVar, RParenLoc,
1347 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001348 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001349
1350 /// \brief Build a new C++0x range-based for statement.
1351 ///
1352 /// By default, performs semantic analysis to build the new statement.
1353 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001354 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001355 bool IsIfExists,
1356 NestedNameSpecifierLoc QualifierLoc,
1357 DeclarationNameInfo NameInfo,
1358 Stmt *Nested) {
1359 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1360 QualifierLoc, NameInfo, Nested);
1361 }
1362
Richard Smithad762fc2011-04-14 22:09:26 +00001363 /// \brief Attach body to a C++0x range-based for statement.
1364 ///
1365 /// By default, performs semantic analysis to finish the new statement.
1366 /// Subclasses may override this routine to provide different behavior.
1367 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1368 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1369 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001370
John Wiegley28bbe4b2011-04-28 01:08:34 +00001371 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1372 SourceLocation TryLoc,
1373 Stmt *TryBlock,
1374 Stmt *Handler) {
1375 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1376 }
1377
1378 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1379 Expr *FilterExpr,
1380 Stmt *Block) {
1381 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1382 }
1383
1384 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1385 Stmt *Block) {
1386 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1387 }
1388
Douglas Gregorb98b1992009-08-11 05:31:07 +00001389 /// \brief Build a new expression that references a declaration.
1390 ///
1391 /// By default, performs semantic analysis to build the new expression.
1392 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001393 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001394 LookupResult &R,
1395 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001396 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1397 }
1398
1399
1400 /// \brief Build a new expression that references a declaration.
1401 ///
1402 /// By default, performs semantic analysis to build the new expression.
1403 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001404 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001405 ValueDecl *VD,
1406 const DeclarationNameInfo &NameInfo,
1407 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001408 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001409 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001410
1411 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001412
1413 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001414 }
Mike Stump1eb44332009-09-09 15:08:12 +00001415
Douglas Gregorb98b1992009-08-11 05:31:07 +00001416 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001417 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001418 /// By default, performs semantic analysis to build the new expression.
1419 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001420 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001421 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001422 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001423 }
1424
Douglas Gregora71d8192009-09-04 17:36:40 +00001425 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001426 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001427 /// By default, performs semantic analysis to build the new expression.
1428 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001429 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001430 SourceLocation OperatorLoc,
1431 bool isArrow,
1432 CXXScopeSpec &SS,
1433 TypeSourceInfo *ScopeType,
1434 SourceLocation CCLoc,
1435 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001436 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001437
Douglas Gregorb98b1992009-08-11 05:31:07 +00001438 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001439 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001440 /// By default, performs semantic analysis to build the new expression.
1441 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001442 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001443 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001444 Expr *SubExpr) {
1445 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001446 }
Mike Stump1eb44332009-09-09 15:08:12 +00001447
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001448 /// \brief Build a new builtin offsetof expression.
1449 ///
1450 /// By default, performs semantic analysis to build the new expression.
1451 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001452 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001453 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001454 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001455 unsigned NumComponents,
1456 SourceLocation RParenLoc) {
1457 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1458 NumComponents, RParenLoc);
1459 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001460
1461 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001462 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001463 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001464 /// By default, performs semantic analysis to build the new expression.
1465 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001466 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1467 SourceLocation OpLoc,
1468 UnaryExprOrTypeTrait ExprKind,
1469 SourceRange R) {
1470 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001471 }
1472
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001473 /// \brief Build a new sizeof, alignof or vec step expression with an
1474 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001475 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001476 /// By default, performs semantic analysis to build the new expression.
1477 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001478 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1479 UnaryExprOrTypeTrait ExprKind,
1480 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001481 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001482 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001483 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001484 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001485
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001486 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001487 }
Mike Stump1eb44332009-09-09 15:08:12 +00001488
Douglas Gregorb98b1992009-08-11 05:31:07 +00001489 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001490 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001491 /// By default, performs semantic analysis to build the new expression.
1492 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001493 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001494 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001495 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001496 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001497 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1498 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001499 RBracketLoc);
1500 }
1501
1502 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001503 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001504 /// By default, performs semantic analysis to build the new expression.
1505 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001506 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001507 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001508 SourceLocation RParenLoc,
1509 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001510 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001511 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001512 }
1513
1514 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001515 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001516 /// By default, performs semantic analysis to build the new expression.
1517 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001518 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001519 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001520 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001521 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001522 const DeclarationNameInfo &MemberNameInfo,
1523 ValueDecl *Member,
1524 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001525 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001526 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001527 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1528 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001529 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001530 // We have a reference to an unnamed field. This is always the
1531 // base of an anonymous struct/union member access, i.e. the
1532 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001533 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001534 assert(Member->getType()->isRecordType() &&
1535 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001536
Richard Smith9138b4e2011-10-26 19:06:56 +00001537 BaseResult =
1538 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001539 QualifierLoc.getNestedNameSpecifier(),
1540 FoundDecl, Member);
1541 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001542 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001543 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001544 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001545 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001546 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001547 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001548 cast<FieldDecl>(Member)->getType(),
1549 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001550 return getSema().Owned(ME);
1551 }
Mike Stump1eb44332009-09-09 15:08:12 +00001552
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001553 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001554 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001555
John Wiegley429bb272011-04-08 18:41:53 +00001556 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001557 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001558
John McCall6bb80172010-03-30 21:47:33 +00001559 // FIXME: this involves duplicating earlier analysis in a lot of
1560 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001561 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001562 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001563 R.resolveKind();
1564
John McCall9ae2f072010-08-23 23:25:46 +00001565 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001566 SS, TemplateKWLoc,
1567 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001568 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001569 }
Mike Stump1eb44332009-09-09 15:08:12 +00001570
Douglas Gregorb98b1992009-08-11 05:31:07 +00001571 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001572 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001573 /// By default, performs semantic analysis to build the new expression.
1574 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001575 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001576 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001577 Expr *LHS, Expr *RHS) {
1578 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001579 }
1580
1581 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001582 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001583 /// By default, performs semantic analysis to build the new expression.
1584 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001585 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001586 SourceLocation QuestionLoc,
1587 Expr *LHS,
1588 SourceLocation ColonLoc,
1589 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001590 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1591 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001592 }
1593
Douglas Gregorb98b1992009-08-11 05:31:07 +00001594 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001595 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001596 /// By default, performs semantic analysis to build the new expression.
1597 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001598 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001599 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001600 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001601 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001602 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001603 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001604 }
Mike Stump1eb44332009-09-09 15:08:12 +00001605
Douglas Gregorb98b1992009-08-11 05:31:07 +00001606 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001607 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001608 /// By default, performs semantic analysis to build the new expression.
1609 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001610 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001611 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001612 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001613 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001614 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001615 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001616 }
Mike Stump1eb44332009-09-09 15:08:12 +00001617
Douglas Gregorb98b1992009-08-11 05:31:07 +00001618 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001619 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001620 /// By default, performs semantic analysis to build the new expression.
1621 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001622 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001623 SourceLocation OpLoc,
1624 SourceLocation AccessorLoc,
1625 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001626
John McCall129e2df2009-11-30 22:42:35 +00001627 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001628 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001629 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001630 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001631 SS, SourceLocation(),
1632 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001633 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001634 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001635 }
Mike Stump1eb44332009-09-09 15:08:12 +00001636
Douglas Gregorb98b1992009-08-11 05:31:07 +00001637 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001638 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001639 /// By default, performs semantic analysis to build the new expression.
1640 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001641 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001642 MultiExprArg Inits,
1643 SourceLocation RBraceLoc,
1644 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001645 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001646 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001647 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001648 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001649
Douglas Gregore48319a2009-11-09 17:16:50 +00001650 // Patch in the result type we were given, which may have been computed
1651 // when the initial InitListExpr was built.
1652 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1653 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001654 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001655 }
Mike Stump1eb44332009-09-09 15:08:12 +00001656
Douglas Gregorb98b1992009-08-11 05:31:07 +00001657 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001658 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001659 /// By default, performs semantic analysis to build the new expression.
1660 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001661 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001662 MultiExprArg ArrayExprs,
1663 SourceLocation EqualOrColonLoc,
1664 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001665 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001666 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001667 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001668 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001669 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001670 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001671
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001672 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001673 }
Mike Stump1eb44332009-09-09 15:08:12 +00001674
Douglas Gregorb98b1992009-08-11 05:31:07 +00001675 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001676 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001677 /// By default, builds the implicit value initialization without performing
1678 /// any semantic analysis. Subclasses may override this routine to provide
1679 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001680 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001681 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1682 }
Mike Stump1eb44332009-09-09 15:08:12 +00001683
Douglas Gregorb98b1992009-08-11 05:31:07 +00001684 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001685 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001686 /// By default, performs semantic analysis to build the new expression.
1687 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001688 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001689 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001690 SourceLocation RParenLoc) {
1691 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001692 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001693 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001694 }
1695
1696 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001697 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001698 /// By default, performs semantic analysis to build the new expression.
1699 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001700 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001701 MultiExprArg SubExprs,
1702 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001703 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001704 }
Mike Stump1eb44332009-09-09 15:08:12 +00001705
Douglas Gregorb98b1992009-08-11 05:31:07 +00001706 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001707 ///
1708 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001709 /// rather than attempting to map the label statement itself.
1710 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001711 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001712 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001713 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001714 }
Mike Stump1eb44332009-09-09 15:08:12 +00001715
Douglas Gregorb98b1992009-08-11 05:31:07 +00001716 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001717 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 /// By default, performs semantic analysis to build the new expression.
1719 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001720 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001721 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001722 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001723 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001724 }
Mike Stump1eb44332009-09-09 15:08:12 +00001725
Douglas Gregorb98b1992009-08-11 05:31:07 +00001726 /// \brief Build a new __builtin_choose_expr expression.
1727 ///
1728 /// By default, performs semantic analysis to build the new expression.
1729 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001730 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001731 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001732 SourceLocation RParenLoc) {
1733 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001734 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001735 RParenLoc);
1736 }
Mike Stump1eb44332009-09-09 15:08:12 +00001737
Peter Collingbournef111d932011-04-15 00:35:48 +00001738 /// \brief Build a new generic selection expression.
1739 ///
1740 /// By default, performs semantic analysis to build the new expression.
1741 /// Subclasses may override this routine to provide different behavior.
1742 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1743 SourceLocation DefaultLoc,
1744 SourceLocation RParenLoc,
1745 Expr *ControllingExpr,
1746 TypeSourceInfo **Types,
1747 Expr **Exprs,
1748 unsigned NumAssocs) {
1749 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1750 ControllingExpr, Types, Exprs,
1751 NumAssocs);
1752 }
1753
Douglas Gregorb98b1992009-08-11 05:31:07 +00001754 /// \brief Build a new overloaded operator call expression.
1755 ///
1756 /// By default, performs semantic analysis to build the new expression.
1757 /// The semantic analysis provides the behavior of template instantiation,
1758 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001759 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001760 /// argument-dependent lookup, etc. Subclasses may override this routine to
1761 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001762 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001763 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001764 Expr *Callee,
1765 Expr *First,
1766 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001767
1768 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001769 /// reinterpret_cast.
1770 ///
1771 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001772 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001773 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001774 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001775 Stmt::StmtClass Class,
1776 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001777 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001778 SourceLocation RAngleLoc,
1779 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001780 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001781 SourceLocation RParenLoc) {
1782 switch (Class) {
1783 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001784 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001785 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001786 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001787
1788 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001789 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001790 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001791 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001792
Douglas Gregorb98b1992009-08-11 05:31:07 +00001793 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001794 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001795 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001796 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001797 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001798
Douglas Gregorb98b1992009-08-11 05:31:07 +00001799 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001800 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001801 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001802 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001803
Douglas Gregorb98b1992009-08-11 05:31:07 +00001804 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001805 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001806 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001807 }
Mike Stump1eb44332009-09-09 15:08:12 +00001808
Douglas Gregorb98b1992009-08-11 05:31:07 +00001809 /// \brief Build a new C++ static_cast expression.
1810 ///
1811 /// By default, performs semantic analysis to build the new expression.
1812 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001813 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001814 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001815 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001816 SourceLocation RAngleLoc,
1817 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001818 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001819 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001820 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001821 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001822 SourceRange(LAngleLoc, RAngleLoc),
1823 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001824 }
1825
1826 /// \brief Build a new C++ dynamic_cast expression.
1827 ///
1828 /// By default, performs semantic analysis to build the new expression.
1829 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001830 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001831 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001832 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001833 SourceLocation RAngleLoc,
1834 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001835 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001836 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001837 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001838 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001839 SourceRange(LAngleLoc, RAngleLoc),
1840 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001841 }
1842
1843 /// \brief Build a new C++ reinterpret_cast expression.
1844 ///
1845 /// By default, performs semantic analysis to build the new expression.
1846 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001847 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001848 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001849 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001850 SourceLocation RAngleLoc,
1851 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001852 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001853 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001854 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001855 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001856 SourceRange(LAngleLoc, RAngleLoc),
1857 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001858 }
1859
1860 /// \brief Build a new C++ const_cast expression.
1861 ///
1862 /// By default, performs semantic analysis to build the new expression.
1863 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001864 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001865 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001866 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001867 SourceLocation RAngleLoc,
1868 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001869 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001870 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001871 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001872 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001873 SourceRange(LAngleLoc, RAngleLoc),
1874 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001875 }
Mike Stump1eb44332009-09-09 15:08:12 +00001876
Douglas Gregorb98b1992009-08-11 05:31:07 +00001877 /// \brief Build a new C++ functional-style cast expression.
1878 ///
1879 /// By default, performs semantic analysis to build the new expression.
1880 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001881 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1882 SourceLocation LParenLoc,
1883 Expr *Sub,
1884 SourceLocation RParenLoc) {
1885 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001886 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001887 RParenLoc);
1888 }
Mike Stump1eb44332009-09-09 15:08:12 +00001889
Douglas Gregorb98b1992009-08-11 05:31:07 +00001890 /// \brief Build a new C++ typeid(type) expression.
1891 ///
1892 /// By default, performs semantic analysis to build the new expression.
1893 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001894 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001895 SourceLocation TypeidLoc,
1896 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001897 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001898 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001899 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001900 }
Mike Stump1eb44332009-09-09 15:08:12 +00001901
Francois Pichet01b7c302010-09-08 12:20:18 +00001902
Douglas Gregorb98b1992009-08-11 05:31:07 +00001903 /// \brief Build a new C++ typeid(expr) expression.
1904 ///
1905 /// By default, performs semantic analysis to build the new expression.
1906 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001907 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001908 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001909 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001910 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001911 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001912 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001913 }
1914
Francois Pichet01b7c302010-09-08 12:20:18 +00001915 /// \brief Build a new C++ __uuidof(type) expression.
1916 ///
1917 /// By default, performs semantic analysis to build the new expression.
1918 /// Subclasses may override this routine to provide different behavior.
1919 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1920 SourceLocation TypeidLoc,
1921 TypeSourceInfo *Operand,
1922 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001923 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00001924 RParenLoc);
1925 }
1926
1927 /// \brief Build a new C++ __uuidof(expr) expression.
1928 ///
1929 /// By default, performs semantic analysis to build the new expression.
1930 /// Subclasses may override this routine to provide different behavior.
1931 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1932 SourceLocation TypeidLoc,
1933 Expr *Operand,
1934 SourceLocation RParenLoc) {
1935 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1936 RParenLoc);
1937 }
1938
Douglas Gregorb98b1992009-08-11 05:31:07 +00001939 /// \brief Build a new C++ "this" expression.
1940 ///
1941 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001942 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001943 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001944 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001945 QualType ThisType,
1946 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001947 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001948 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001949 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1950 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001951 }
1952
1953 /// \brief Build a new C++ throw expression.
1954 ///
1955 /// By default, performs semantic analysis to build the new expression.
1956 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001957 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1958 bool IsThrownVariableInScope) {
1959 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001960 }
1961
1962 /// \brief Build a new C++ default-argument expression.
1963 ///
1964 /// By default, builds a new default-argument expression, which does not
1965 /// require any semantic analysis. Subclasses may override this routine to
1966 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001967 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001968 ParmVarDecl *Param) {
1969 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1970 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001971 }
1972
1973 /// \brief Build a new C++ zero-initialization expression.
1974 ///
1975 /// By default, performs semantic analysis to build the new expression.
1976 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001977 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1978 SourceLocation LParenLoc,
1979 SourceLocation RParenLoc) {
1980 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Benjamin Kramer5354e772012-08-23 23:38:35 +00001981 MultiExprArg(), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001982 }
Mike Stump1eb44332009-09-09 15:08:12 +00001983
Douglas Gregorb98b1992009-08-11 05:31:07 +00001984 /// \brief Build a new C++ "new" expression.
1985 ///
1986 /// By default, performs semantic analysis to build the new expression.
1987 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001988 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001989 bool UseGlobal,
1990 SourceLocation PlacementLParen,
1991 MultiExprArg PlacementArgs,
1992 SourceLocation PlacementRParen,
1993 SourceRange TypeIdParens,
1994 QualType AllocatedType,
1995 TypeSourceInfo *AllocatedTypeInfo,
1996 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001997 SourceRange DirectInitRange,
1998 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00001999 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002000 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002001 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002002 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002003 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002004 AllocatedType,
2005 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002006 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002007 DirectInitRange,
2008 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002009 }
Mike Stump1eb44332009-09-09 15:08:12 +00002010
Douglas Gregorb98b1992009-08-11 05:31:07 +00002011 /// \brief Build a new C++ "delete" expression.
2012 ///
2013 /// By default, performs semantic analysis to build the new expression.
2014 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002015 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002016 bool IsGlobalDelete,
2017 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002018 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002019 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002020 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002021 }
Mike Stump1eb44332009-09-09 15:08:12 +00002022
Douglas Gregorb98b1992009-08-11 05:31:07 +00002023 /// \brief Build a new unary type trait expression.
2024 ///
2025 /// By default, performs semantic analysis to build the new expression.
2026 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002027 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002028 SourceLocation StartLoc,
2029 TypeSourceInfo *T,
2030 SourceLocation RParenLoc) {
2031 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002032 }
2033
Francois Pichet6ad6f282010-12-07 00:08:36 +00002034 /// \brief Build a new binary type trait expression.
2035 ///
2036 /// By default, performs semantic analysis to build the new expression.
2037 /// Subclasses may override this routine to provide different behavior.
2038 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2039 SourceLocation StartLoc,
2040 TypeSourceInfo *LhsT,
2041 TypeSourceInfo *RhsT,
2042 SourceLocation RParenLoc) {
2043 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2044 }
2045
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002046 /// \brief Build a new type trait expression.
2047 ///
2048 /// By default, performs semantic analysis to build the new expression.
2049 /// Subclasses may override this routine to provide different behavior.
2050 ExprResult RebuildTypeTrait(TypeTrait Trait,
2051 SourceLocation StartLoc,
2052 ArrayRef<TypeSourceInfo *> Args,
2053 SourceLocation RParenLoc) {
2054 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2055 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002056
John Wiegley21ff2e52011-04-28 00:16:57 +00002057 /// \brief Build a new array type trait expression.
2058 ///
2059 /// By default, performs semantic analysis to build the new expression.
2060 /// Subclasses may override this routine to provide different behavior.
2061 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2062 SourceLocation StartLoc,
2063 TypeSourceInfo *TSInfo,
2064 Expr *DimExpr,
2065 SourceLocation RParenLoc) {
2066 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2067 }
2068
John Wiegley55262202011-04-25 06:54:41 +00002069 /// \brief Build a new expression trait expression.
2070 ///
2071 /// By default, performs semantic analysis to build the new expression.
2072 /// Subclasses may override this routine to provide different behavior.
2073 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2074 SourceLocation StartLoc,
2075 Expr *Queried,
2076 SourceLocation RParenLoc) {
2077 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2078 }
2079
Mike Stump1eb44332009-09-09 15:08:12 +00002080 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002081 /// expression.
2082 ///
2083 /// By default, performs semantic analysis to build the new expression.
2084 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002085 ExprResult RebuildDependentScopeDeclRefExpr(
2086 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002087 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002088 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002089 const TemplateArgumentListInfo *TemplateArgs,
2090 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002091 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002092 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002093
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002094 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002095 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002096 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002097
Richard Smithefeeccf2012-10-21 03:28:35 +00002098 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2099 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002100 }
2101
2102 /// \brief Build a new template-id expression.
2103 ///
2104 /// By default, performs semantic analysis to build the new expression.
2105 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002106 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002107 SourceLocation TemplateKWLoc,
2108 LookupResult &R,
2109 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002110 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002111 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2112 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002113 }
2114
2115 /// \brief Build a new object-construction expression.
2116 ///
2117 /// By default, performs semantic analysis to build the new expression.
2118 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002119 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002120 SourceLocation Loc,
2121 CXXConstructorDecl *Constructor,
2122 bool IsElidable,
2123 MultiExprArg Args,
2124 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002125 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002126 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002127 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002128 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002129 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002130 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002131 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002132 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002133
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002134 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002135 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002136 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002137 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002138 RequiresZeroInit, ConstructKind,
2139 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002140 }
2141
2142 /// \brief Build a new object-construction expression.
2143 ///
2144 /// By default, performs semantic analysis to build the new expression.
2145 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002146 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2147 SourceLocation LParenLoc,
2148 MultiExprArg Args,
2149 SourceLocation RParenLoc) {
2150 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002151 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002152 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002153 RParenLoc);
2154 }
2155
2156 /// \brief Build a new object-construction expression.
2157 ///
2158 /// By default, performs semantic analysis to build the new expression.
2159 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002160 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2161 SourceLocation LParenLoc,
2162 MultiExprArg Args,
2163 SourceLocation RParenLoc) {
2164 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002165 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002166 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002167 RParenLoc);
2168 }
Mike Stump1eb44332009-09-09 15:08:12 +00002169
Douglas Gregorb98b1992009-08-11 05:31:07 +00002170 /// \brief Build a new member reference expression.
2171 ///
2172 /// By default, performs semantic analysis to build the new expression.
2173 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002174 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002175 QualType BaseType,
2176 bool IsArrow,
2177 SourceLocation OperatorLoc,
2178 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002179 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002180 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002181 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002182 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002183 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002184 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002185
John McCall9ae2f072010-08-23 23:25:46 +00002186 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002187 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002188 SS, TemplateKWLoc,
2189 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002190 MemberNameInfo,
2191 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002192 }
2193
John McCall129e2df2009-11-30 22:42:35 +00002194 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002195 ///
2196 /// By default, performs semantic analysis to build the new expression.
2197 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002198 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2199 SourceLocation OperatorLoc,
2200 bool IsArrow,
2201 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002202 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002203 NamedDecl *FirstQualifierInScope,
2204 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002205 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002206 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002207 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002208
John McCall9ae2f072010-08-23 23:25:46 +00002209 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002210 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002211 SS, TemplateKWLoc,
2212 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002213 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002214 }
Mike Stump1eb44332009-09-09 15:08:12 +00002215
Sebastian Redl2e156222010-09-10 20:55:43 +00002216 /// \brief Build a new noexcept expression.
2217 ///
2218 /// By default, performs semantic analysis to build the new expression.
2219 /// Subclasses may override this routine to provide different behavior.
2220 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2221 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2222 }
2223
Douglas Gregoree8aff02011-01-04 17:33:58 +00002224 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002225 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2226 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002227 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002228 llvm::Optional<unsigned> Length) {
2229 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002230 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2231 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002232 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002233
2234 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2235 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002236 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002237 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002238
Patrick Beardeb382ec2012-04-19 00:25:12 +00002239 /// \brief Build a new Objective-C boxed expression.
2240 ///
2241 /// By default, performs semantic analysis to build the new expression.
2242 /// Subclasses may override this routine to provide different behavior.
2243 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2244 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2245 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002246
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002247 /// \brief Build a new Objective-C array literal.
2248 ///
2249 /// By default, performs semantic analysis to build the new expression.
2250 /// Subclasses may override this routine to provide different behavior.
2251 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2252 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002253 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002254 MultiExprArg(Elements, NumElements));
2255 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002256
2257 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002258 Expr *Base, Expr *Key,
2259 ObjCMethodDecl *getterMethod,
2260 ObjCMethodDecl *setterMethod) {
2261 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2262 getterMethod, setterMethod);
2263 }
2264
2265 /// \brief Build a new Objective-C dictionary literal.
2266 ///
2267 /// By default, performs semantic analysis to build the new expression.
2268 /// Subclasses may override this routine to provide different behavior.
2269 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2270 ObjCDictionaryElement *Elements,
2271 unsigned NumElements) {
2272 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2273 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002274
James Dennett699c9042012-06-15 07:13:21 +00002275 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002276 ///
2277 /// By default, performs semantic analysis to build the new expression.
2278 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002279 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002280 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002281 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002282 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002283 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002284 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002285
Douglas Gregor92e986e2010-04-22 16:44:27 +00002286 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002287 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002288 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002289 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002290 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002291 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002292 MultiExprArg Args,
2293 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002294 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2295 ReceiverTypeInfo->getType(),
2296 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002297 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002298 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002299 }
2300
2301 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002302 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002303 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002304 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002305 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002306 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002307 MultiExprArg Args,
2308 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002309 return SemaRef.BuildInstanceMessage(Receiver,
2310 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002311 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002312 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002313 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002314 }
2315
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002316 /// \brief Build a new Objective-C ivar reference expression.
2317 ///
2318 /// By default, performs semantic analysis to build the new expression.
2319 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002320 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002321 SourceLocation IvarLoc,
2322 bool IsArrow, bool IsFreeIvar) {
2323 // FIXME: We lose track of the IsFreeIvar bit.
2324 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002325 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002326 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2327 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002328 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002329 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002330 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002331 false);
John Wiegley429bb272011-04-08 18:41:53 +00002332 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002333 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002334
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002335 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002336 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002337
John Wiegley429bb272011-04-08 18:41:53 +00002338 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002339 /*FIXME:*/IvarLoc, IsArrow,
2340 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002341 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002342 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002343 /*TemplateArgs=*/0);
2344 }
Douglas Gregore3303542010-04-26 20:47:02 +00002345
2346 /// \brief Build a new Objective-C property reference expression.
2347 ///
2348 /// By default, performs semantic analysis to build the new expression.
2349 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002350 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002351 ObjCPropertyDecl *Property,
2352 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002353 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002354 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002355 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2356 Sema::LookupMemberName);
2357 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002358 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002359 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002360 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002361 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002362 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002363
Douglas Gregore3303542010-04-26 20:47:02 +00002364 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002365 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002366
John Wiegley429bb272011-04-08 18:41:53 +00002367 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002368 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002369 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002370 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002371 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002372 /*TemplateArgs=*/0);
2373 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002374
John McCall12f78a62010-12-02 01:19:52 +00002375 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002376 ///
2377 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002378 /// Subclasses may override this routine to provide different behavior.
2379 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2380 ObjCMethodDecl *Getter,
2381 ObjCMethodDecl *Setter,
2382 SourceLocation PropertyLoc) {
2383 // Since these expressions can only be value-dependent, we do not
2384 // need to perform semantic analysis again.
2385 return Owned(
2386 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2387 VK_LValue, OK_ObjCProperty,
2388 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002389 }
2390
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002391 /// \brief Build a new Objective-C "isa" expression.
2392 ///
2393 /// By default, performs semantic analysis to build the new expression.
2394 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002395 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002396 bool IsArrow) {
2397 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002398 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002399 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2400 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002401 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002402 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002403 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002404 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002405 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002406
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002407 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002408 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002409
John Wiegley429bb272011-04-08 18:41:53 +00002410 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002411 /*FIXME:*/IsaLoc, IsArrow,
2412 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002413 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002414 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002415 /*TemplateArgs=*/0);
2416 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002417
Douglas Gregorb98b1992009-08-11 05:31:07 +00002418 /// \brief Build a new shuffle vector expression.
2419 ///
2420 /// By default, performs semantic analysis to build the new expression.
2421 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002422 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002423 MultiExprArg SubExprs,
2424 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002425 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002426 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002427 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2428 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2429 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002430 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002431
Douglas Gregorb98b1992009-08-11 05:31:07 +00002432 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002433 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002434 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2435 SemaRef.Context.BuiltinFnTy,
2436 VK_RValue, BuiltinLoc);
2437 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2438 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2439 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002440
2441 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002442 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002443 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002444 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002445 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002446 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002447
Douglas Gregorb98b1992009-08-11 05:31:07 +00002448 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002449 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002450 }
John McCall43fed0d2010-11-12 08:19:04 +00002451
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002452 /// \brief Build a new template argument pack expansion.
2453 ///
2454 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002455 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002456 /// different behavior.
2457 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002458 SourceLocation EllipsisLoc,
2459 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002460 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002461 case TemplateArgument::Expression: {
2462 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002463 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2464 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002465 if (Result.isInvalid())
2466 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002467
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002468 return TemplateArgumentLoc(Result.get(), Result.get());
2469 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002470
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002471 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002472 return TemplateArgumentLoc(TemplateArgument(
2473 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002474 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002475 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002476 Pattern.getTemplateNameLoc(),
2477 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002478
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002479 case TemplateArgument::Null:
2480 case TemplateArgument::Integral:
2481 case TemplateArgument::Declaration:
2482 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002483 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002484 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002485 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002486
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002487 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002488 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002489 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002490 EllipsisLoc,
2491 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002492 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2493 Expansion);
2494 break;
2495 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002496
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002497 return TemplateArgumentLoc();
2498 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002499
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002500 /// \brief Build a new expression pack expansion.
2501 ///
2502 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002503 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002504 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002505 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2506 llvm::Optional<unsigned> NumExpansions) {
2507 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002508 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002509
2510 /// \brief Build a new atomic operation expression.
2511 ///
2512 /// By default, performs semantic analysis to build the new expression.
2513 /// Subclasses may override this routine to provide different behavior.
2514 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2515 MultiExprArg SubExprs,
2516 QualType RetTy,
2517 AtomicExpr::AtomicOp Op,
2518 SourceLocation RParenLoc) {
2519 // Just create the expression; there is not any interesting semantic
2520 // analysis here because we can't actually build an AtomicExpr until
2521 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002522 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002523 RParenLoc);
2524 }
2525
John McCall43fed0d2010-11-12 08:19:04 +00002526private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002527 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2528 QualType ObjectType,
2529 NamedDecl *FirstQualifierInScope,
2530 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002531
2532 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2533 QualType ObjectType,
2534 NamedDecl *FirstQualifierInScope,
2535 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002536};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002537
Douglas Gregor43959a92009-08-20 07:17:43 +00002538template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002539StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002540 if (!S)
2541 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002542
Douglas Gregor43959a92009-08-20 07:17:43 +00002543 switch (S->getStmtClass()) {
2544 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002545
Douglas Gregor43959a92009-08-20 07:17:43 +00002546 // Transform individual statement nodes
2547#define STMT(Node, Parent) \
2548 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002549#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002550#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002551#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002552
Douglas Gregor43959a92009-08-20 07:17:43 +00002553 // Transform expressions by calling TransformExpr.
2554#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002555#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002556#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002557#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002558 {
John McCall60d7b3a2010-08-24 06:29:42 +00002559 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002560 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002561 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002562
John McCall9ae2f072010-08-23 23:25:46 +00002563 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002564 }
Mike Stump1eb44332009-09-09 15:08:12 +00002565 }
2566
John McCall3fa5cae2010-10-26 07:05:15 +00002567 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002568}
Mike Stump1eb44332009-09-09 15:08:12 +00002569
2570
Douglas Gregor670444e2009-08-04 22:27:00 +00002571template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002572ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002573 if (!E)
2574 return SemaRef.Owned(E);
2575
2576 switch (E->getStmtClass()) {
2577 case Stmt::NoStmtClass: break;
2578#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002579#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002580#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002581 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002582#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002583 }
2584
John McCall3fa5cae2010-10-26 07:05:15 +00002585 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002586}
2587
2588template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002589ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2590 bool CXXDirectInit) {
2591 // Initializers are instantiated like expressions, except that various outer
2592 // layers are stripped.
2593 if (!Init)
2594 return SemaRef.Owned(Init);
2595
2596 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2597 Init = ExprTemp->getSubExpr();
2598
2599 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2600 Init = Binder->getSubExpr();
2601
2602 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2603 Init = ICE->getSubExprAsWritten();
2604
2605 // If this is a direct-initializer, we take apart CXXConstructExprs.
2606 // Everything else is passed through.
2607 CXXConstructExpr *Construct;
2608 if (!(Construct = dyn_cast<CXXConstructExpr>(Init)) ||
2609 isa<CXXTemporaryObjectExpr>(Construct) ||
2610 (!CXXDirectInit && !Construct->isListInitialization()))
2611 return getDerived().TransformExpr(Init);
2612
2613 SmallVector<Expr*, 8> NewArgs;
2614 bool ArgChanged = false;
2615 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2616 /*IsCall*/true, NewArgs, &ArgChanged))
2617 return ExprError();
2618
2619 // If this was list initialization, revert to list form.
2620 if (Construct->isListInitialization())
2621 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2622 Construct->getLocEnd(),
2623 Construct->getType());
2624
2625 // Treat an empty initializer like none.
2626 if (NewArgs.empty())
2627 return SemaRef.Owned((Expr*)0);
2628
2629 // Build a ParenListExpr to represent anything else.
2630 SourceRange Parens = Construct->getParenRange();
2631 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2632 Parens.getEnd());
2633}
2634
2635template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002636bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2637 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002638 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002639 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002640 bool *ArgChanged) {
2641 for (unsigned I = 0; I != NumInputs; ++I) {
2642 // If requested, drop call arguments that need to be dropped.
2643 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2644 if (ArgChanged)
2645 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002646
Douglas Gregoraa165f82011-01-03 19:04:46 +00002647 break;
2648 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002649
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002650 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2651 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002652
Chris Lattner686775d2011-07-20 06:58:45 +00002653 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002654 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2655 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002656
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002657 // Determine whether the set of unexpanded parameter packs can and should
2658 // be expanded.
2659 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002660 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002661 llvm::Optional<unsigned> OrigNumExpansions
2662 = Expansion->getNumExpansions();
2663 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002664 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2665 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002666 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002667 Expand, RetainExpansion,
2668 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002669 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002670
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002671 if (!Expand) {
2672 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002673 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002674 // expansion.
2675 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2676 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2677 if (OutPattern.isInvalid())
2678 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002679
2680 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002681 Expansion->getEllipsisLoc(),
2682 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002683 if (Out.isInvalid())
2684 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002685
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002686 if (ArgChanged)
2687 *ArgChanged = true;
2688 Outputs.push_back(Out.get());
2689 continue;
2690 }
John McCallc8fc90a2011-07-06 07:30:07 +00002691
2692 // Record right away that the argument was changed. This needs
2693 // to happen even if the array expands to nothing.
2694 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002695
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002696 // The transform has determined that we should perform an elementwise
2697 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002698 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002699 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2700 ExprResult Out = getDerived().TransformExpr(Pattern);
2701 if (Out.isInvalid())
2702 return true;
2703
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002704 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002705 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2706 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002707 if (Out.isInvalid())
2708 return true;
2709 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002710
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002711 Outputs.push_back(Out.get());
2712 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002713
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002714 continue;
2715 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002716
Richard Smithc83c2302012-12-19 01:39:02 +00002717 ExprResult Result =
2718 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2719 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002720 if (Result.isInvalid())
2721 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002722
Douglas Gregoraa165f82011-01-03 19:04:46 +00002723 if (Result.get() != Inputs[I] && ArgChanged)
2724 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002725
2726 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002727 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002728
Douglas Gregoraa165f82011-01-03 19:04:46 +00002729 return false;
2730}
2731
2732template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002733NestedNameSpecifierLoc
2734TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2735 NestedNameSpecifierLoc NNS,
2736 QualType ObjectType,
2737 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002738 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002739 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002740 Qualifier = Qualifier.getPrefix())
2741 Qualifiers.push_back(Qualifier);
2742
2743 CXXScopeSpec SS;
2744 while (!Qualifiers.empty()) {
2745 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2746 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002747
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002748 switch (QNNS->getKind()) {
2749 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002750 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002751 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002752 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002753 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002754 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002755 FirstQualifierInScope, false))
2756 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002757
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002758 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002759
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002760 case NestedNameSpecifier::Namespace: {
2761 NamespaceDecl *NS
2762 = cast_or_null<NamespaceDecl>(
2763 getDerived().TransformDecl(
2764 Q.getLocalBeginLoc(),
2765 QNNS->getAsNamespace()));
2766 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2767 break;
2768 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002769
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002770 case NestedNameSpecifier::NamespaceAlias: {
2771 NamespaceAliasDecl *Alias
2772 = cast_or_null<NamespaceAliasDecl>(
2773 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2774 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002775 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002776 Q.getLocalEndLoc());
2777 break;
2778 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002779
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002780 case NestedNameSpecifier::Global:
2781 // There is no meaningful transformation that one could perform on the
2782 // global scope.
2783 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2784 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002785
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002786 case NestedNameSpecifier::TypeSpecWithTemplate:
2787 case NestedNameSpecifier::TypeSpec: {
2788 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2789 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002790
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002791 if (!TL)
2792 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002793
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002794 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00002795 (SemaRef.getLangOpts().CPlusPlus0x &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002796 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002797 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002798 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002799 if (TL.getType()->isEnumeralType())
2800 SemaRef.Diag(TL.getBeginLoc(),
2801 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002802 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2803 Q.getLocalEndLoc());
2804 break;
2805 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002806 // If the nested-name-specifier is an invalid type def, don't emit an
2807 // error because a previous error should have already been emitted.
2808 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2809 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002810 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002811 << TL.getType() << SS.getRange();
2812 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002813 return NestedNameSpecifierLoc();
2814 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002815 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002816
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002817 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002818 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002819 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002820 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002821
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002822 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002823 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002824 !getDerived().AlwaysRebuild())
2825 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002826
2827 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002828 // nested-name-specifier, do so.
2829 if (SS.location_size() == NNS.getDataLength() &&
2830 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2831 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2832
2833 // Allocate new nested-name-specifier location information.
2834 return SS.getWithLocInContext(SemaRef.Context);
2835}
2836
2837template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002838DeclarationNameInfo
2839TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002840::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002841 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002842 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002843 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002844
2845 switch (Name.getNameKind()) {
2846 case DeclarationName::Identifier:
2847 case DeclarationName::ObjCZeroArgSelector:
2848 case DeclarationName::ObjCOneArgSelector:
2849 case DeclarationName::ObjCMultiArgSelector:
2850 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002851 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002852 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002853 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002854
Douglas Gregor81499bb2009-09-03 22:13:48 +00002855 case DeclarationName::CXXConstructorName:
2856 case DeclarationName::CXXDestructorName:
2857 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002858 TypeSourceInfo *NewTInfo;
2859 CanQualType NewCanTy;
2860 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002861 NewTInfo = getDerived().TransformType(OldTInfo);
2862 if (!NewTInfo)
2863 return DeclarationNameInfo();
2864 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002865 }
2866 else {
2867 NewTInfo = 0;
2868 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002869 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002870 if (NewT.isNull())
2871 return DeclarationNameInfo();
2872 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2873 }
Mike Stump1eb44332009-09-09 15:08:12 +00002874
Abramo Bagnara25777432010-08-11 22:01:17 +00002875 DeclarationName NewName
2876 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2877 NewCanTy);
2878 DeclarationNameInfo NewNameInfo(NameInfo);
2879 NewNameInfo.setName(NewName);
2880 NewNameInfo.setNamedTypeInfo(NewTInfo);
2881 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002882 }
Mike Stump1eb44332009-09-09 15:08:12 +00002883 }
2884
David Blaikieb219cfc2011-09-23 05:06:16 +00002885 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002886}
2887
2888template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002889TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002890TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2891 TemplateName Name,
2892 SourceLocation NameLoc,
2893 QualType ObjectType,
2894 NamedDecl *FirstQualifierInScope) {
2895 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2896 TemplateDecl *Template = QTN->getTemplateDecl();
2897 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002898
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002899 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002900 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002901 Template));
2902 if (!TransTemplate)
2903 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002904
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002905 if (!getDerived().AlwaysRebuild() &&
2906 SS.getScopeRep() == QTN->getQualifier() &&
2907 TransTemplate == Template)
2908 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002909
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002910 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2911 TransTemplate);
2912 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002913
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002914 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2915 if (SS.getScopeRep()) {
2916 // These apply to the scope specifier, not the template.
2917 ObjectType = QualType();
2918 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002919 }
2920
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002921 if (!getDerived().AlwaysRebuild() &&
2922 SS.getScopeRep() == DTN->getQualifier() &&
2923 ObjectType.isNull())
2924 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002925
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002926 if (DTN->isIdentifier()) {
2927 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002928 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002929 NameLoc,
2930 ObjectType,
2931 FirstQualifierInScope);
2932 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002933
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002934 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2935 ObjectType);
2936 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002937
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002938 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2939 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002940 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002941 Template));
2942 if (!TransTemplate)
2943 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002944
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002945 if (!getDerived().AlwaysRebuild() &&
2946 TransTemplate == Template)
2947 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002948
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002949 return TemplateName(TransTemplate);
2950 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002951
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002952 if (SubstTemplateTemplateParmPackStorage *SubstPack
2953 = Name.getAsSubstTemplateTemplateParmPack()) {
2954 TemplateTemplateParmDecl *TransParam
2955 = cast_or_null<TemplateTemplateParmDecl>(
2956 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2957 if (!TransParam)
2958 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002959
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002960 if (!getDerived().AlwaysRebuild() &&
2961 TransParam == SubstPack->getParameterPack())
2962 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002963
2964 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002965 SubstPack->getArgumentPack());
2966 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002967
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002968 // These should be getting filtered out before they reach the AST.
2969 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002970}
2971
2972template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002973void TreeTransform<Derived>::InventTemplateArgumentLoc(
2974 const TemplateArgument &Arg,
2975 TemplateArgumentLoc &Output) {
2976 SourceLocation Loc = getDerived().getBaseLocation();
2977 switch (Arg.getKind()) {
2978 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002979 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002980 break;
2981
2982 case TemplateArgument::Type:
2983 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002984 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002985
John McCall833ca992009-10-29 08:12:44 +00002986 break;
2987
Douglas Gregor788cd062009-11-11 01:00:40 +00002988 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002989 case TemplateArgument::TemplateExpansion: {
2990 NestedNameSpecifierLocBuilder Builder;
2991 TemplateName Template = Arg.getAsTemplate();
2992 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2993 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2994 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2995 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002996
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002997 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002998 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002999 Builder.getWithLocInContext(SemaRef.Context),
3000 Loc);
3001 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003002 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003003 Builder.getWithLocInContext(SemaRef.Context),
3004 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003005
Douglas Gregor788cd062009-11-11 01:00:40 +00003006 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003007 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003008
John McCall833ca992009-10-29 08:12:44 +00003009 case TemplateArgument::Expression:
3010 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3011 break;
3012
3013 case TemplateArgument::Declaration:
3014 case TemplateArgument::Integral:
3015 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003016 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003017 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003018 break;
3019 }
3020}
3021
3022template<typename Derived>
3023bool TreeTransform<Derived>::TransformTemplateArgument(
3024 const TemplateArgumentLoc &Input,
3025 TemplateArgumentLoc &Output) {
3026 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003027 switch (Arg.getKind()) {
3028 case TemplateArgument::Null:
3029 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003030 case TemplateArgument::Pack:
3031 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003032 case TemplateArgument::NullPtr:
3033 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003034
Douglas Gregor670444e2009-08-04 22:27:00 +00003035 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003036 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003037 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003038 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003039
3040 DI = getDerived().TransformType(DI);
3041 if (!DI) return true;
3042
3043 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3044 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003045 }
Mike Stump1eb44332009-09-09 15:08:12 +00003046
Douglas Gregor788cd062009-11-11 01:00:40 +00003047 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003048 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3049 if (QualifierLoc) {
3050 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3051 if (!QualifierLoc)
3052 return true;
3053 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003054
Douglas Gregor1d752d72011-03-02 18:46:51 +00003055 CXXScopeSpec SS;
3056 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003057 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003058 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3059 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003060 if (Template.isNull())
3061 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003062
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003063 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003064 Input.getTemplateNameLoc());
3065 return false;
3066 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003067
3068 case TemplateArgument::TemplateExpansion:
3069 llvm_unreachable("Caller should expand pack expansions");
3070
Douglas Gregor670444e2009-08-04 22:27:00 +00003071 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003072 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003073 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003074 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003075
John McCall833ca992009-10-29 08:12:44 +00003076 Expr *InputExpr = Input.getSourceExpression();
3077 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3078
Chris Lattner223de242011-04-25 20:37:58 +00003079 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003080 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003081 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003082 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003083 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003084 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003085 }
Mike Stump1eb44332009-09-09 15:08:12 +00003086
Douglas Gregor670444e2009-08-04 22:27:00 +00003087 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003088 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003089}
3090
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003091/// \brief Iterator adaptor that invents template argument location information
3092/// for each of the template arguments in its underlying iterator.
3093template<typename Derived, typename InputIterator>
3094class TemplateArgumentLocInventIterator {
3095 TreeTransform<Derived> &Self;
3096 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003097
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003098public:
3099 typedef TemplateArgumentLoc value_type;
3100 typedef TemplateArgumentLoc reference;
3101 typedef typename std::iterator_traits<InputIterator>::difference_type
3102 difference_type;
3103 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003104
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003105 class pointer {
3106 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003107
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003108 public:
3109 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003110
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003111 const TemplateArgumentLoc *operator->() const { return &Arg; }
3112 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003113
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003114 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003115
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003116 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3117 InputIterator Iter)
3118 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003119
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003120 TemplateArgumentLocInventIterator &operator++() {
3121 ++Iter;
3122 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003123 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003124
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003125 TemplateArgumentLocInventIterator operator++(int) {
3126 TemplateArgumentLocInventIterator Old(*this);
3127 ++(*this);
3128 return Old;
3129 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003130
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003131 reference operator*() const {
3132 TemplateArgumentLoc Result;
3133 Self.InventTemplateArgumentLoc(*Iter, Result);
3134 return Result;
3135 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003136
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003137 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003138
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003139 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3140 const TemplateArgumentLocInventIterator &Y) {
3141 return X.Iter == Y.Iter;
3142 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003143
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003144 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3145 const TemplateArgumentLocInventIterator &Y) {
3146 return X.Iter != Y.Iter;
3147 }
3148};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003149
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003150template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003151template<typename InputIterator>
3152bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3153 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003154 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003155 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003156 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003157 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003158
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003159 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3160 // Unpack argument packs, which we translate them into separate
3161 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003162 // FIXME: We could do much better if we could guarantee that the
3163 // TemplateArgumentLocInfo for the pack expansion would be usable for
3164 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003165 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003166 TemplateArgument::pack_iterator>
3167 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003168 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003169 In.getArgument().pack_begin()),
3170 PackLocIterator(*this,
3171 In.getArgument().pack_end()),
3172 Outputs))
3173 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003174
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003175 continue;
3176 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003177
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003178 if (In.getArgument().isPackExpansion()) {
3179 // We have a pack expansion, for which we will be substituting into
3180 // the pattern.
3181 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003182 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003183 TemplateArgumentLoc Pattern
Chad Rosier4a9d7952012-08-08 18:46:20 +00003184 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
Douglas Gregorcded4f62011-01-14 17:04:44 +00003185 getSema().Context);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003186
Chris Lattner686775d2011-07-20 06:58:45 +00003187 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003188 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3189 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003190
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003191 // Determine whether the set of unexpanded parameter packs can and should
3192 // be expanded.
3193 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003194 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003195 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003196 if (getDerived().TryExpandParameterPacks(Ellipsis,
3197 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003198 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003199 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003200 RetainExpansion,
3201 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003202 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003203
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003204 if (!Expand) {
3205 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003206 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003207 // expansion.
3208 TemplateArgumentLoc OutPattern;
3209 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3210 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3211 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003212
Douglas Gregorcded4f62011-01-14 17:04:44 +00003213 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3214 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003215 if (Out.getArgument().isNull())
3216 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003217
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003218 Outputs.addArgument(Out);
3219 continue;
3220 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003221
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003222 // The transform has determined that we should perform an elementwise
3223 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003224 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003225 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3226
3227 if (getDerived().TransformTemplateArgument(Pattern, Out))
3228 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003229
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003230 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003231 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3232 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003233 if (Out.getArgument().isNull())
3234 return true;
3235 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003236
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003237 Outputs.addArgument(Out);
3238 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003239
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003240 // If we're supposed to retain a pack expansion, do so by temporarily
3241 // forgetting the partially-substituted parameter pack.
3242 if (RetainExpansion) {
3243 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003244
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003245 if (getDerived().TransformTemplateArgument(Pattern, Out))
3246 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003247
Douglas Gregorcded4f62011-01-14 17:04:44 +00003248 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3249 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003250 if (Out.getArgument().isNull())
3251 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003252
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003253 Outputs.addArgument(Out);
3254 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003255
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003256 continue;
3257 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003258
3259 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003260 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003261 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003262
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003263 Outputs.addArgument(Out);
3264 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003265
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003266 return false;
3267
3268}
3269
Douglas Gregor577f75a2009-08-04 16:50:30 +00003270//===----------------------------------------------------------------------===//
3271// Type transformation
3272//===----------------------------------------------------------------------===//
3273
3274template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003275QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003276 if (getDerived().AlreadyTransformed(T))
3277 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003278
John McCalla2becad2009-10-21 00:40:46 +00003279 // Temporary workaround. All of these transformations should
3280 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003281 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3282 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003283
John McCall43fed0d2010-11-12 08:19:04 +00003284 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003285
John McCalla2becad2009-10-21 00:40:46 +00003286 if (!NewDI)
3287 return QualType();
3288
3289 return NewDI->getType();
3290}
3291
3292template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003293TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003294 // Refine the base location to the type's location.
3295 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3296 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003297 if (getDerived().AlreadyTransformed(DI->getType()))
3298 return DI;
3299
3300 TypeLocBuilder TLB;
3301
3302 TypeLoc TL = DI->getTypeLoc();
3303 TLB.reserve(TL.getFullDataSize());
3304
John McCall43fed0d2010-11-12 08:19:04 +00003305 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003306 if (Result.isNull())
3307 return 0;
3308
John McCalla93c9342009-12-07 02:54:59 +00003309 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003310}
3311
3312template<typename Derived>
3313QualType
John McCall43fed0d2010-11-12 08:19:04 +00003314TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003315 switch (T.getTypeLocClass()) {
3316#define ABSTRACT_TYPELOC(CLASS, PARENT)
3317#define TYPELOC(CLASS, PARENT) \
3318 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003319 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003320#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003321 }
Mike Stump1eb44332009-09-09 15:08:12 +00003322
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003323 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003324}
3325
3326/// FIXME: By default, this routine adds type qualifiers only to types
3327/// that can have qualifiers, and silently suppresses those qualifiers
3328/// that are not permitted (e.g., qualifiers on reference or function
3329/// types). This is the right thing for template instantiation, but
3330/// probably not for other clients.
3331template<typename Derived>
3332QualType
3333TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003334 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003335 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003336
John McCall43fed0d2010-11-12 08:19:04 +00003337 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003338 if (Result.isNull())
3339 return QualType();
3340
3341 // Silently suppress qualifiers if the result type can't be qualified.
3342 // FIXME: this is the right thing for template instantiation, but
3343 // probably not for other clients.
3344 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003345 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003346
John McCallf85e1932011-06-15 23:02:42 +00003347 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003348 // resulting type.
3349 if (Quals.hasObjCLifetime()) {
3350 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3351 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003352 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003353 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003354 // A lifetime qualifier applied to a substituted template parameter
3355 // overrides the lifetime qualifier from the template argument.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003356 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003357 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3358 QualType Replacement = SubstTypeParam->getReplacementType();
3359 Qualifiers Qs = Replacement.getQualifiers();
3360 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003361 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003362 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3363 Qs);
3364 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003365 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003366 Replacement);
3367 TLB.TypeWasModifiedSafely(Result);
3368 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003369 // Otherwise, complain about the addition of a qualifier to an
3370 // already-qualified type.
3371 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003372 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003373 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003374
Douglas Gregore559ca12011-06-17 22:11:49 +00003375 Quals.removeObjCLifetime();
3376 }
3377 }
3378 }
John McCall28654742010-06-05 06:41:15 +00003379 if (!Quals.empty()) {
3380 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3381 TLB.push<QualifiedTypeLoc>(Result);
3382 // No location information to preserve.
3383 }
John McCalla2becad2009-10-21 00:40:46 +00003384
3385 return Result;
3386}
3387
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003388template<typename Derived>
3389TypeLoc
3390TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3391 QualType ObjectType,
3392 NamedDecl *UnqualLookup,
3393 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003394 QualType T = TL.getType();
3395 if (getDerived().AlreadyTransformed(T))
3396 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003397
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003398 TypeLocBuilder TLB;
3399 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003400
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003401 if (isa<TemplateSpecializationType>(T)) {
3402 TemplateSpecializationTypeLoc SpecTL
3403 = cast<TemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003404
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003405 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003406 getDerived().TransformTemplateName(SS,
3407 SpecTL.getTypePtr()->getTemplateName(),
3408 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003409 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003410 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003411 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003412
3413 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003414 Template);
3415 } else if (isa<DependentTemplateSpecializationType>(T)) {
3416 DependentTemplateSpecializationTypeLoc SpecTL
3417 = cast<DependentTemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003418
Douglas Gregora88f09f2011-02-28 17:23:35 +00003419 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003420 = getDerived().RebuildTemplateName(SS,
3421 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003422 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003423 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003424 if (Template.isNull())
3425 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003426
3427 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003428 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003429 Template,
3430 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003431 } else {
3432 // Nothing special needs to be done for these.
3433 Result = getDerived().TransformType(TLB, TL);
3434 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003435
3436 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003437 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003438
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003439 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3440}
3441
Douglas Gregorb71d8212011-03-02 18:32:08 +00003442template<typename Derived>
3443TypeSourceInfo *
3444TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3445 QualType ObjectType,
3446 NamedDecl *UnqualLookup,
3447 CXXScopeSpec &SS) {
3448 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003449
Douglas Gregorb71d8212011-03-02 18:32:08 +00003450 QualType T = TSInfo->getType();
3451 if (getDerived().AlreadyTransformed(T))
3452 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003453
Douglas Gregorb71d8212011-03-02 18:32:08 +00003454 TypeLocBuilder TLB;
3455 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003456
Douglas Gregorb71d8212011-03-02 18:32:08 +00003457 TypeLoc TL = TSInfo->getTypeLoc();
3458 if (isa<TemplateSpecializationType>(T)) {
3459 TemplateSpecializationTypeLoc SpecTL
3460 = cast<TemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003461
Douglas Gregorb71d8212011-03-02 18:32:08 +00003462 TemplateName Template
3463 = getDerived().TransformTemplateName(SS,
3464 SpecTL.getTypePtr()->getTemplateName(),
3465 SpecTL.getTemplateNameLoc(),
3466 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003467 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003468 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003469
3470 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003471 Template);
3472 } else if (isa<DependentTemplateSpecializationType>(T)) {
3473 DependentTemplateSpecializationTypeLoc SpecTL
3474 = cast<DependentTemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003475
Douglas Gregorb71d8212011-03-02 18:32:08 +00003476 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003477 = getDerived().RebuildTemplateName(SS,
3478 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003479 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003480 ObjectType, UnqualLookup);
3481 if (Template.isNull())
3482 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003483
3484 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003485 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003486 Template,
3487 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003488 } else {
3489 // Nothing special needs to be done for these.
3490 Result = getDerived().TransformType(TLB, TL);
3491 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003492
3493 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003494 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003495
Douglas Gregorb71d8212011-03-02 18:32:08 +00003496 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3497}
3498
John McCalla2becad2009-10-21 00:40:46 +00003499template <class TyLoc> static inline
3500QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3501 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3502 NewT.setNameLoc(T.getNameLoc());
3503 return T.getType();
3504}
3505
John McCalla2becad2009-10-21 00:40:46 +00003506template<typename Derived>
3507QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003508 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003509 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3510 NewT.setBuiltinLoc(T.getBuiltinLoc());
3511 if (T.needsExtraLocalData())
3512 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3513 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003514}
Mike Stump1eb44332009-09-09 15:08:12 +00003515
Douglas Gregor577f75a2009-08-04 16:50:30 +00003516template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003517QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003518 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003519 // FIXME: recurse?
3520 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003521}
Mike Stump1eb44332009-09-09 15:08:12 +00003522
Douglas Gregor577f75a2009-08-04 16:50:30 +00003523template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003524QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003525 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003526 QualType PointeeType
3527 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003528 if (PointeeType.isNull())
3529 return QualType();
3530
3531 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003532 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003533 // A dependent pointer type 'T *' has is being transformed such
3534 // that an Objective-C class type is being replaced for 'T'. The
3535 // resulting pointer type is an ObjCObjectPointerType, not a
3536 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003537 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003538
John McCallc12c5bb2010-05-15 11:32:37 +00003539 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3540 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003541 return Result;
3542 }
John McCall43fed0d2010-11-12 08:19:04 +00003543
Douglas Gregor92e986e2010-04-22 16:44:27 +00003544 if (getDerived().AlwaysRebuild() ||
3545 PointeeType != TL.getPointeeLoc().getType()) {
3546 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3547 if (Result.isNull())
3548 return QualType();
3549 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003550
John McCallf85e1932011-06-15 23:02:42 +00003551 // Objective-C ARC can add lifetime qualifiers to the type that we're
3552 // pointing to.
3553 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003554
Douglas Gregor92e986e2010-04-22 16:44:27 +00003555 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3556 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003557 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003558}
Mike Stump1eb44332009-09-09 15:08:12 +00003559
3560template<typename Derived>
3561QualType
John McCalla2becad2009-10-21 00:40:46 +00003562TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003563 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003564 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003565 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3566 if (PointeeType.isNull())
3567 return QualType();
3568
3569 QualType Result = TL.getType();
3570 if (getDerived().AlwaysRebuild() ||
3571 PointeeType != TL.getPointeeLoc().getType()) {
3572 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003573 TL.getSigilLoc());
3574 if (Result.isNull())
3575 return QualType();
3576 }
3577
Douglas Gregor39968ad2010-04-22 16:50:51 +00003578 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003579 NewT.setSigilLoc(TL.getSigilLoc());
3580 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003581}
3582
John McCall85737a72009-10-30 00:06:24 +00003583/// Transforms a reference type. Note that somewhat paradoxically we
3584/// don't care whether the type itself is an l-value type or an r-value
3585/// type; we only care if the type was *written* as an l-value type
3586/// or an r-value type.
3587template<typename Derived>
3588QualType
3589TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003590 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003591 const ReferenceType *T = TL.getTypePtr();
3592
3593 // Note that this works with the pointee-as-written.
3594 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3595 if (PointeeType.isNull())
3596 return QualType();
3597
3598 QualType Result = TL.getType();
3599 if (getDerived().AlwaysRebuild() ||
3600 PointeeType != T->getPointeeTypeAsWritten()) {
3601 Result = getDerived().RebuildReferenceType(PointeeType,
3602 T->isSpelledAsLValue(),
3603 TL.getSigilLoc());
3604 if (Result.isNull())
3605 return QualType();
3606 }
3607
John McCallf85e1932011-06-15 23:02:42 +00003608 // Objective-C ARC can add lifetime qualifiers to the type that we're
3609 // referring to.
3610 TLB.TypeWasModifiedSafely(
3611 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3612
John McCall85737a72009-10-30 00:06:24 +00003613 // r-value references can be rebuilt as l-value references.
3614 ReferenceTypeLoc NewTL;
3615 if (isa<LValueReferenceType>(Result))
3616 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3617 else
3618 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3619 NewTL.setSigilLoc(TL.getSigilLoc());
3620
3621 return Result;
3622}
3623
Mike Stump1eb44332009-09-09 15:08:12 +00003624template<typename Derived>
3625QualType
John McCalla2becad2009-10-21 00:40:46 +00003626TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003627 LValueReferenceTypeLoc TL) {
3628 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003629}
3630
Mike Stump1eb44332009-09-09 15:08:12 +00003631template<typename Derived>
3632QualType
John McCalla2becad2009-10-21 00:40:46 +00003633TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003634 RValueReferenceTypeLoc TL) {
3635 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003636}
Mike Stump1eb44332009-09-09 15:08:12 +00003637
Douglas Gregor577f75a2009-08-04 16:50:30 +00003638template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003639QualType
John McCalla2becad2009-10-21 00:40:46 +00003640TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003641 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003642 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003643 if (PointeeType.isNull())
3644 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003645
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003646 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3647 TypeSourceInfo* NewClsTInfo = 0;
3648 if (OldClsTInfo) {
3649 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3650 if (!NewClsTInfo)
3651 return QualType();
3652 }
3653
3654 const MemberPointerType *T = TL.getTypePtr();
3655 QualType OldClsType = QualType(T->getClass(), 0);
3656 QualType NewClsType;
3657 if (NewClsTInfo)
3658 NewClsType = NewClsTInfo->getType();
3659 else {
3660 NewClsType = getDerived().TransformType(OldClsType);
3661 if (NewClsType.isNull())
3662 return QualType();
3663 }
Mike Stump1eb44332009-09-09 15:08:12 +00003664
John McCalla2becad2009-10-21 00:40:46 +00003665 QualType Result = TL.getType();
3666 if (getDerived().AlwaysRebuild() ||
3667 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003668 NewClsType != OldClsType) {
3669 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003670 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003671 if (Result.isNull())
3672 return QualType();
3673 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003674
John McCalla2becad2009-10-21 00:40:46 +00003675 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3676 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003677 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003678
3679 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003680}
3681
Mike Stump1eb44332009-09-09 15:08:12 +00003682template<typename Derived>
3683QualType
John McCalla2becad2009-10-21 00:40:46 +00003684TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003685 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003686 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003687 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003688 if (ElementType.isNull())
3689 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003690
John McCalla2becad2009-10-21 00:40:46 +00003691 QualType Result = TL.getType();
3692 if (getDerived().AlwaysRebuild() ||
3693 ElementType != T->getElementType()) {
3694 Result = getDerived().RebuildConstantArrayType(ElementType,
3695 T->getSizeModifier(),
3696 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003697 T->getIndexTypeCVRQualifiers(),
3698 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003699 if (Result.isNull())
3700 return QualType();
3701 }
Eli Friedman457a3772012-01-25 22:19:07 +00003702
3703 // We might have either a ConstantArrayType or a VariableArrayType now:
3704 // a ConstantArrayType is allowed to have an element type which is a
3705 // VariableArrayType if the type is dependent. Fortunately, all array
3706 // types have the same location layout.
3707 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003708 NewTL.setLBracketLoc(TL.getLBracketLoc());
3709 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003710
John McCalla2becad2009-10-21 00:40:46 +00003711 Expr *Size = TL.getSizeExpr();
3712 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003713 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3714 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003715 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003716 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003717 }
3718 NewTL.setSizeExpr(Size);
3719
3720 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003721}
Mike Stump1eb44332009-09-09 15:08:12 +00003722
Douglas Gregor577f75a2009-08-04 16:50:30 +00003723template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003724QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003725 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003726 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003727 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003728 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003729 if (ElementType.isNull())
3730 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003731
John McCalla2becad2009-10-21 00:40:46 +00003732 QualType Result = TL.getType();
3733 if (getDerived().AlwaysRebuild() ||
3734 ElementType != T->getElementType()) {
3735 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003736 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003737 T->getIndexTypeCVRQualifiers(),
3738 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003739 if (Result.isNull())
3740 return QualType();
3741 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003742
John McCalla2becad2009-10-21 00:40:46 +00003743 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3744 NewTL.setLBracketLoc(TL.getLBracketLoc());
3745 NewTL.setRBracketLoc(TL.getRBracketLoc());
3746 NewTL.setSizeExpr(0);
3747
3748 return Result;
3749}
3750
3751template<typename Derived>
3752QualType
3753TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003754 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003755 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003756 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3757 if (ElementType.isNull())
3758 return QualType();
3759
John McCall60d7b3a2010-08-24 06:29:42 +00003760 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003761 = getDerived().TransformExpr(T->getSizeExpr());
3762 if (SizeResult.isInvalid())
3763 return QualType();
3764
John McCall9ae2f072010-08-23 23:25:46 +00003765 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003766
3767 QualType Result = TL.getType();
3768 if (getDerived().AlwaysRebuild() ||
3769 ElementType != T->getElementType() ||
3770 Size != T->getSizeExpr()) {
3771 Result = getDerived().RebuildVariableArrayType(ElementType,
3772 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003773 Size,
John McCalla2becad2009-10-21 00:40:46 +00003774 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003775 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003776 if (Result.isNull())
3777 return QualType();
3778 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003779
John McCalla2becad2009-10-21 00:40:46 +00003780 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3781 NewTL.setLBracketLoc(TL.getLBracketLoc());
3782 NewTL.setRBracketLoc(TL.getRBracketLoc());
3783 NewTL.setSizeExpr(Size);
3784
3785 return Result;
3786}
3787
3788template<typename Derived>
3789QualType
3790TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003791 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003792 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003793 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3794 if (ElementType.isNull())
3795 return QualType();
3796
Richard Smithf6702a32011-12-20 02:08:33 +00003797 // Array bounds are constant expressions.
3798 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3799 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003800
John McCall3b657512011-01-19 10:06:00 +00003801 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3802 Expr *origSize = TL.getSizeExpr();
3803 if (!origSize) origSize = T->getSizeExpr();
3804
3805 ExprResult sizeResult
3806 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003807 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003808 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003809 return QualType();
3810
John McCall3b657512011-01-19 10:06:00 +00003811 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003812
3813 QualType Result = TL.getType();
3814 if (getDerived().AlwaysRebuild() ||
3815 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003816 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003817 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3818 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003819 size,
John McCalla2becad2009-10-21 00:40:46 +00003820 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003821 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003822 if (Result.isNull())
3823 return QualType();
3824 }
John McCalla2becad2009-10-21 00:40:46 +00003825
3826 // We might have any sort of array type now, but fortunately they
3827 // all have the same location layout.
3828 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3829 NewTL.setLBracketLoc(TL.getLBracketLoc());
3830 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003831 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003832
3833 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003834}
Mike Stump1eb44332009-09-09 15:08:12 +00003835
3836template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003837QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003838 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003839 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003840 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003841
3842 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003843 QualType ElementType = getDerived().TransformType(T->getElementType());
3844 if (ElementType.isNull())
3845 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003846
Richard Smithf6702a32011-12-20 02:08:33 +00003847 // Vector sizes are constant expressions.
3848 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3849 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003850
John McCall60d7b3a2010-08-24 06:29:42 +00003851 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003852 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003853 if (Size.isInvalid())
3854 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003855
John McCalla2becad2009-10-21 00:40:46 +00003856 QualType Result = TL.getType();
3857 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003858 ElementType != T->getElementType() ||
3859 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003860 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003861 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003862 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003863 if (Result.isNull())
3864 return QualType();
3865 }
John McCalla2becad2009-10-21 00:40:46 +00003866
3867 // Result might be dependent or not.
3868 if (isa<DependentSizedExtVectorType>(Result)) {
3869 DependentSizedExtVectorTypeLoc NewTL
3870 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3871 NewTL.setNameLoc(TL.getNameLoc());
3872 } else {
3873 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3874 NewTL.setNameLoc(TL.getNameLoc());
3875 }
3876
3877 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003878}
Mike Stump1eb44332009-09-09 15:08:12 +00003879
3880template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003881QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003882 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003883 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003884 QualType ElementType = getDerived().TransformType(T->getElementType());
3885 if (ElementType.isNull())
3886 return QualType();
3887
John McCalla2becad2009-10-21 00:40:46 +00003888 QualType Result = TL.getType();
3889 if (getDerived().AlwaysRebuild() ||
3890 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003891 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003892 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003893 if (Result.isNull())
3894 return QualType();
3895 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003896
John McCalla2becad2009-10-21 00:40:46 +00003897 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3898 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003899
John McCalla2becad2009-10-21 00:40:46 +00003900 return Result;
3901}
3902
3903template<typename Derived>
3904QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003905 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003906 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003907 QualType ElementType = getDerived().TransformType(T->getElementType());
3908 if (ElementType.isNull())
3909 return QualType();
3910
3911 QualType Result = TL.getType();
3912 if (getDerived().AlwaysRebuild() ||
3913 ElementType != T->getElementType()) {
3914 Result = getDerived().RebuildExtVectorType(ElementType,
3915 T->getNumElements(),
3916 /*FIXME*/ SourceLocation());
3917 if (Result.isNull())
3918 return QualType();
3919 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003920
John McCalla2becad2009-10-21 00:40:46 +00003921 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3922 NewTL.setNameLoc(TL.getNameLoc());
3923
3924 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003925}
Mike Stump1eb44332009-09-09 15:08:12 +00003926
3927template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003928ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003929TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003930 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003931 llvm::Optional<unsigned> NumExpansions,
3932 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003933 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003934 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003935
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003936 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003937 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003938 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003939 TypeLoc OldTL = OldDI->getTypeLoc();
3940 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003941
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003942 TypeLocBuilder TLB;
3943 TypeLoc NewTL = OldDI->getTypeLoc();
3944 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003945
3946 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003947 OldExpansionTL.getPatternLoc());
3948 if (Result.isNull())
3949 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003950
3951 Result = RebuildPackExpansionType(Result,
3952 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003953 OldExpansionTL.getEllipsisLoc(),
3954 NumExpansions);
3955 if (Result.isNull())
3956 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003957
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003958 PackExpansionTypeLoc NewExpansionTL
3959 = TLB.push<PackExpansionTypeLoc>(Result);
3960 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3961 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3962 } else
3963 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003964 if (!NewDI)
3965 return 0;
3966
John McCallfb44de92011-05-01 22:35:37 +00003967 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003968 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003969
3970 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3971 OldParm->getDeclContext(),
3972 OldParm->getInnerLocStart(),
3973 OldParm->getLocation(),
3974 OldParm->getIdentifier(),
3975 NewDI->getType(),
3976 NewDI,
3977 OldParm->getStorageClass(),
3978 OldParm->getStorageClassAsWritten(),
3979 /* DefArg */ NULL);
3980 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3981 OldParm->getFunctionScopeIndex() + indexAdjustment);
3982 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003983}
3984
3985template<typename Derived>
3986bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003987 TransformFunctionTypeParams(SourceLocation Loc,
3988 ParmVarDecl **Params, unsigned NumParams,
3989 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003990 SmallVectorImpl<QualType> &OutParamTypes,
3991 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003992 int indexAdjustment = 0;
3993
Douglas Gregora009b592011-01-07 00:20:55 +00003994 for (unsigned i = 0; i != NumParams; ++i) {
3995 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003996 assert(OldParm->getFunctionScopeIndex() == i);
3997
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003998 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003999 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004000 if (OldParm->isParameterPack()) {
4001 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004002 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004003
Douglas Gregor603cfb42011-01-05 23:12:31 +00004004 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004005 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
4006 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
4007 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4008 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004009 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4010
Douglas Gregor603cfb42011-01-05 23:12:31 +00004011 // Determine whether we should expand the parameter packs.
4012 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004013 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004014 llvm::Optional<unsigned> OrigNumExpansions
4015 = ExpansionTL.getTypePtr()->getNumExpansions();
4016 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004017 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4018 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004019 Unexpanded,
4020 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004021 RetainExpansion,
4022 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004023 return true;
4024 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004025
Douglas Gregor603cfb42011-01-05 23:12:31 +00004026 if (ShouldExpand) {
4027 // Expand the function parameter pack into multiple, separate
4028 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004029 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004030 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004031 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004032 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004033 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004034 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004035 OrigNumExpansions,
4036 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004037 if (!NewParm)
4038 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004039
Douglas Gregora009b592011-01-07 00:20:55 +00004040 OutParamTypes.push_back(NewParm->getType());
4041 if (PVars)
4042 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004043 }
Douglas Gregord3731192011-01-10 07:32:04 +00004044
4045 // If we're supposed to retain a pack expansion, do so by temporarily
4046 // forgetting the partially-substituted parameter pack.
4047 if (RetainExpansion) {
4048 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004049 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004050 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004051 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004052 OrigNumExpansions,
4053 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004054 if (!NewParm)
4055 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004056
Douglas Gregord3731192011-01-10 07:32:04 +00004057 OutParamTypes.push_back(NewParm->getType());
4058 if (PVars)
4059 PVars->push_back(NewParm);
4060 }
4061
John McCallfb44de92011-05-01 22:35:37 +00004062 // The next parameter should have the same adjustment as the
4063 // last thing we pushed, but we post-incremented indexAdjustment
4064 // on every push. Also, if we push nothing, the adjustment should
4065 // go down by one.
4066 indexAdjustment--;
4067
Douglas Gregor603cfb42011-01-05 23:12:31 +00004068 // We're done with the pack expansion.
4069 continue;
4070 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004071
4072 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004073 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004074 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4075 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004076 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004077 NumExpansions,
4078 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004079 } else {
4080 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004081 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004082 llvm::Optional<unsigned>(),
4083 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004084 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004085
John McCall21ef0fa2010-03-11 09:03:00 +00004086 if (!NewParm)
4087 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004088
Douglas Gregora009b592011-01-07 00:20:55 +00004089 OutParamTypes.push_back(NewParm->getType());
4090 if (PVars)
4091 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004092 continue;
4093 }
John McCall21ef0fa2010-03-11 09:03:00 +00004094
4095 // Deal with the possibility that we don't have a parameter
4096 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004097 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004098 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004099 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004100 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004101 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004102 = dyn_cast<PackExpansionType>(OldType)) {
4103 // We have a function parameter pack that may need to be expanded.
4104 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004105 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004106 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004107
Douglas Gregor603cfb42011-01-05 23:12:31 +00004108 // Determine whether we should expand the parameter packs.
4109 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004110 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004111 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004112 Unexpanded,
4113 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004114 RetainExpansion,
4115 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004116 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004117 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004118
Douglas Gregor603cfb42011-01-05 23:12:31 +00004119 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004120 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004121 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004122 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004123 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4124 QualType NewType = getDerived().TransformType(Pattern);
4125 if (NewType.isNull())
4126 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004127
Douglas Gregora009b592011-01-07 00:20:55 +00004128 OutParamTypes.push_back(NewType);
4129 if (PVars)
4130 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004131 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004132
Douglas Gregor603cfb42011-01-05 23:12:31 +00004133 // We're done with the pack expansion.
4134 continue;
4135 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004136
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004137 // If we're supposed to retain a pack expansion, do so by temporarily
4138 // forgetting the partially-substituted parameter pack.
4139 if (RetainExpansion) {
4140 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4141 QualType NewType = getDerived().TransformType(Pattern);
4142 if (NewType.isNull())
4143 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004144
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004145 OutParamTypes.push_back(NewType);
4146 if (PVars)
4147 PVars->push_back(0);
4148 }
Douglas Gregord3731192011-01-10 07:32:04 +00004149
Chad Rosier4a9d7952012-08-08 18:46:20 +00004150 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004151 // expansion.
4152 OldType = Expansion->getPattern();
4153 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004154 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4155 NewType = getDerived().TransformType(OldType);
4156 } else {
4157 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004158 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004159
Douglas Gregor603cfb42011-01-05 23:12:31 +00004160 if (NewType.isNull())
4161 return true;
4162
4163 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004164 NewType = getSema().Context.getPackExpansionType(NewType,
4165 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004166
Douglas Gregora009b592011-01-07 00:20:55 +00004167 OutParamTypes.push_back(NewType);
4168 if (PVars)
4169 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004170 }
4171
John McCallfb44de92011-05-01 22:35:37 +00004172#ifndef NDEBUG
4173 if (PVars) {
4174 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4175 if (ParmVarDecl *parm = (*PVars)[i])
4176 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004177 }
John McCallfb44de92011-05-01 22:35:37 +00004178#endif
4179
4180 return false;
4181}
John McCall21ef0fa2010-03-11 09:03:00 +00004182
4183template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004184QualType
John McCalla2becad2009-10-21 00:40:46 +00004185TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004186 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004187 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4188}
4189
4190template<typename Derived>
4191QualType
4192TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4193 FunctionProtoTypeLoc TL,
4194 CXXRecordDecl *ThisContext,
4195 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004196 // Transform the parameters and return type.
4197 //
Richard Smithe6975e92012-04-17 00:58:00 +00004198 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004199 // When the function has a trailing return type, we instantiate the
4200 // parameters before the return type, since the return type can then refer
4201 // to the parameters themselves (via decltype, sizeof, etc.).
4202 //
Chris Lattner686775d2011-07-20 06:58:45 +00004203 SmallVector<QualType, 4> ParamTypes;
4204 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004205 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004206
Douglas Gregordab60ad2010-10-01 18:44:50 +00004207 QualType ResultType;
4208
Richard Smith9fbf3272012-08-14 22:51:13 +00004209 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004210 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004211 TL.getParmArray(),
4212 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004213 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004214 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004215 return QualType();
4216
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004217 {
4218 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004219 // If a declaration declares a member function or member function
4220 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004221 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004222 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004223 // declarator.
4224 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004225
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004226 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4227 if (ResultType.isNull())
4228 return QualType();
4229 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004230 }
4231 else {
4232 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4233 if (ResultType.isNull())
4234 return QualType();
4235
Chad Rosier4a9d7952012-08-08 18:46:20 +00004236 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004237 TL.getParmArray(),
4238 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004239 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004240 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004241 return QualType();
4242 }
4243
Richard Smithe6975e92012-04-17 00:58:00 +00004244 // FIXME: Need to transform the exception-specification too.
4245
John McCalla2becad2009-10-21 00:40:46 +00004246 QualType Result = TL.getType();
4247 if (getDerived().AlwaysRebuild() ||
4248 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004249 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004250 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4251 Result = getDerived().RebuildFunctionProtoType(ResultType,
4252 ParamTypes.data(),
4253 ParamTypes.size(),
4254 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004255 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004256 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004257 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004258 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004259 if (Result.isNull())
4260 return QualType();
4261 }
Mike Stump1eb44332009-09-09 15:08:12 +00004262
John McCalla2becad2009-10-21 00:40:46 +00004263 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004264 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004265 NewTL.setLParenLoc(TL.getLParenLoc());
4266 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004267 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004268 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4269 NewTL.setArg(i, ParamDecls[i]);
4270
4271 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004272}
Mike Stump1eb44332009-09-09 15:08:12 +00004273
Douglas Gregor577f75a2009-08-04 16:50:30 +00004274template<typename Derived>
4275QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004276 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004277 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004278 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004279 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4280 if (ResultType.isNull())
4281 return QualType();
4282
4283 QualType Result = TL.getType();
4284 if (getDerived().AlwaysRebuild() ||
4285 ResultType != T->getResultType())
4286 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4287
4288 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004289 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004290 NewTL.setLParenLoc(TL.getLParenLoc());
4291 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004292 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004293
4294 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004295}
Mike Stump1eb44332009-09-09 15:08:12 +00004296
John McCalled976492009-12-04 22:46:56 +00004297template<typename Derived> QualType
4298TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004299 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004300 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004301 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004302 if (!D)
4303 return QualType();
4304
4305 QualType Result = TL.getType();
4306 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4307 Result = getDerived().RebuildUnresolvedUsingType(D);
4308 if (Result.isNull())
4309 return QualType();
4310 }
4311
4312 // We might get an arbitrary type spec type back. We should at
4313 // least always get a type spec type, though.
4314 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4315 NewTL.setNameLoc(TL.getNameLoc());
4316
4317 return Result;
4318}
4319
Douglas Gregor577f75a2009-08-04 16:50:30 +00004320template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004321QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004322 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004323 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004324 TypedefNameDecl *Typedef
4325 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4326 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004327 if (!Typedef)
4328 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004329
John McCalla2becad2009-10-21 00:40:46 +00004330 QualType Result = TL.getType();
4331 if (getDerived().AlwaysRebuild() ||
4332 Typedef != T->getDecl()) {
4333 Result = getDerived().RebuildTypedefType(Typedef);
4334 if (Result.isNull())
4335 return QualType();
4336 }
Mike Stump1eb44332009-09-09 15:08:12 +00004337
John McCalla2becad2009-10-21 00:40:46 +00004338 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4339 NewTL.setNameLoc(TL.getNameLoc());
4340
4341 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004342}
Mike Stump1eb44332009-09-09 15:08:12 +00004343
Douglas Gregor577f75a2009-08-04 16:50:30 +00004344template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004345QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004346 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004347 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004348 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4349 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004350
John McCall60d7b3a2010-08-24 06:29:42 +00004351 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004352 if (E.isInvalid())
4353 return QualType();
4354
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004355 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4356 if (E.isInvalid())
4357 return QualType();
4358
John McCalla2becad2009-10-21 00:40:46 +00004359 QualType Result = TL.getType();
4360 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004361 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004362 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004363 if (Result.isNull())
4364 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004365 }
John McCalla2becad2009-10-21 00:40:46 +00004366 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004367
John McCalla2becad2009-10-21 00:40:46 +00004368 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004369 NewTL.setTypeofLoc(TL.getTypeofLoc());
4370 NewTL.setLParenLoc(TL.getLParenLoc());
4371 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004372
4373 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004374}
Mike Stump1eb44332009-09-09 15:08:12 +00004375
4376template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004377QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004378 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004379 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4380 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4381 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004382 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004383
John McCalla2becad2009-10-21 00:40:46 +00004384 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004385 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4386 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004387 if (Result.isNull())
4388 return QualType();
4389 }
Mike Stump1eb44332009-09-09 15:08:12 +00004390
John McCalla2becad2009-10-21 00:40:46 +00004391 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004392 NewTL.setTypeofLoc(TL.getTypeofLoc());
4393 NewTL.setLParenLoc(TL.getLParenLoc());
4394 NewTL.setRParenLoc(TL.getRParenLoc());
4395 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004396
4397 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004398}
Mike Stump1eb44332009-09-09 15:08:12 +00004399
4400template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004401QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004402 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004403 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004404
Douglas Gregor670444e2009-08-04 22:27:00 +00004405 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004406 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4407 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004408
John McCall60d7b3a2010-08-24 06:29:42 +00004409 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004410 if (E.isInvalid())
4411 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004412
Richard Smith76f3f692012-02-22 02:04:18 +00004413 E = getSema().ActOnDecltypeExpression(E.take());
4414 if (E.isInvalid())
4415 return QualType();
4416
John McCalla2becad2009-10-21 00:40:46 +00004417 QualType Result = TL.getType();
4418 if (getDerived().AlwaysRebuild() ||
4419 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004420 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004421 if (Result.isNull())
4422 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004423 }
John McCalla2becad2009-10-21 00:40:46 +00004424 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004425
John McCalla2becad2009-10-21 00:40:46 +00004426 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4427 NewTL.setNameLoc(TL.getNameLoc());
4428
4429 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004430}
4431
4432template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004433QualType TreeTransform<Derived>::TransformUnaryTransformType(
4434 TypeLocBuilder &TLB,
4435 UnaryTransformTypeLoc TL) {
4436 QualType Result = TL.getType();
4437 if (Result->isDependentType()) {
4438 const UnaryTransformType *T = TL.getTypePtr();
4439 QualType NewBase =
4440 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4441 Result = getDerived().RebuildUnaryTransformType(NewBase,
4442 T->getUTTKind(),
4443 TL.getKWLoc());
4444 if (Result.isNull())
4445 return QualType();
4446 }
4447
4448 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4449 NewTL.setKWLoc(TL.getKWLoc());
4450 NewTL.setParensRange(TL.getParensRange());
4451 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4452 return Result;
4453}
4454
4455template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004456QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4457 AutoTypeLoc TL) {
4458 const AutoType *T = TL.getTypePtr();
4459 QualType OldDeduced = T->getDeducedType();
4460 QualType NewDeduced;
4461 if (!OldDeduced.isNull()) {
4462 NewDeduced = getDerived().TransformType(OldDeduced);
4463 if (NewDeduced.isNull())
4464 return QualType();
4465 }
4466
4467 QualType Result = TL.getType();
4468 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4469 Result = getDerived().RebuildAutoType(NewDeduced);
4470 if (Result.isNull())
4471 return QualType();
4472 }
4473
4474 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4475 NewTL.setNameLoc(TL.getNameLoc());
4476
4477 return Result;
4478}
4479
4480template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004481QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004482 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004483 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004484 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004485 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4486 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004487 if (!Record)
4488 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004489
John McCalla2becad2009-10-21 00:40:46 +00004490 QualType Result = TL.getType();
4491 if (getDerived().AlwaysRebuild() ||
4492 Record != T->getDecl()) {
4493 Result = getDerived().RebuildRecordType(Record);
4494 if (Result.isNull())
4495 return QualType();
4496 }
Mike Stump1eb44332009-09-09 15:08:12 +00004497
John McCalla2becad2009-10-21 00:40:46 +00004498 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4499 NewTL.setNameLoc(TL.getNameLoc());
4500
4501 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004502}
Mike Stump1eb44332009-09-09 15:08:12 +00004503
4504template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004505QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004506 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004507 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004508 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004509 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4510 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004511 if (!Enum)
4512 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004513
John McCalla2becad2009-10-21 00:40:46 +00004514 QualType Result = TL.getType();
4515 if (getDerived().AlwaysRebuild() ||
4516 Enum != T->getDecl()) {
4517 Result = getDerived().RebuildEnumType(Enum);
4518 if (Result.isNull())
4519 return QualType();
4520 }
Mike Stump1eb44332009-09-09 15:08:12 +00004521
John McCalla2becad2009-10-21 00:40:46 +00004522 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4523 NewTL.setNameLoc(TL.getNameLoc());
4524
4525 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004526}
John McCall7da24312009-09-05 00:15:47 +00004527
John McCall3cb0ebd2010-03-10 03:28:59 +00004528template<typename Derived>
4529QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4530 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004531 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004532 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4533 TL.getTypePtr()->getDecl());
4534 if (!D) return QualType();
4535
4536 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4537 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4538 return T;
4539}
4540
Douglas Gregor577f75a2009-08-04 16:50:30 +00004541template<typename Derived>
4542QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004543 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004544 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004545 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004546}
4547
Mike Stump1eb44332009-09-09 15:08:12 +00004548template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004549QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004550 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004551 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004552 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004553
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004554 // Substitute into the replacement type, which itself might involve something
4555 // that needs to be transformed. This only tends to occur with default
4556 // template arguments of template template parameters.
4557 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4558 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4559 if (Replacement.isNull())
4560 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004561
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004562 // Always canonicalize the replacement type.
4563 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4564 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004565 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004566 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004567
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004568 // Propagate type-source information.
4569 SubstTemplateTypeParmTypeLoc NewTL
4570 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4571 NewTL.setNameLoc(TL.getNameLoc());
4572 return Result;
4573
John McCall49a832b2009-10-18 09:09:24 +00004574}
4575
4576template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004577QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4578 TypeLocBuilder &TLB,
4579 SubstTemplateTypeParmPackTypeLoc TL) {
4580 return TransformTypeSpecType(TLB, TL);
4581}
4582
4583template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004584QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004585 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004586 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004587 const TemplateSpecializationType *T = TL.getTypePtr();
4588
Douglas Gregor1d752d72011-03-02 18:46:51 +00004589 // The nested-name-specifier never matters in a TemplateSpecializationType,
4590 // because we can't have a dependent nested-name-specifier anyway.
4591 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004592 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004593 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4594 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004595 if (Template.isNull())
4596 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004597
John McCall43fed0d2010-11-12 08:19:04 +00004598 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4599}
4600
Eli Friedmanb001de72011-10-06 23:00:33 +00004601template<typename Derived>
4602QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4603 AtomicTypeLoc TL) {
4604 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4605 if (ValueType.isNull())
4606 return QualType();
4607
4608 QualType Result = TL.getType();
4609 if (getDerived().AlwaysRebuild() ||
4610 ValueType != TL.getValueLoc().getType()) {
4611 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4612 if (Result.isNull())
4613 return QualType();
4614 }
4615
4616 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4617 NewTL.setKWLoc(TL.getKWLoc());
4618 NewTL.setLParenLoc(TL.getLParenLoc());
4619 NewTL.setRParenLoc(TL.getRParenLoc());
4620
4621 return Result;
4622}
4623
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004624namespace {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004625 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004626 /// container that provides a \c getArgLoc() member function.
4627 ///
4628 /// This iterator is intended to be used with the iterator form of
4629 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4630 template<typename ArgLocContainer>
4631 class TemplateArgumentLocContainerIterator {
4632 ArgLocContainer *Container;
4633 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004634
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004635 public:
4636 typedef TemplateArgumentLoc value_type;
4637 typedef TemplateArgumentLoc reference;
4638 typedef int difference_type;
4639 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004640
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004641 class pointer {
4642 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004643
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004644 public:
4645 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004646
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004647 const TemplateArgumentLoc *operator->() const {
4648 return &Arg;
4649 }
4650 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004651
4652
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004653 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004654
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004655 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4656 unsigned Index)
4657 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004658
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004659 TemplateArgumentLocContainerIterator &operator++() {
4660 ++Index;
4661 return *this;
4662 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004663
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004664 TemplateArgumentLocContainerIterator operator++(int) {
4665 TemplateArgumentLocContainerIterator Old(*this);
4666 ++(*this);
4667 return Old;
4668 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004669
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004670 TemplateArgumentLoc operator*() const {
4671 return Container->getArgLoc(Index);
4672 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004673
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004674 pointer operator->() const {
4675 return pointer(Container->getArgLoc(Index));
4676 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004677
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004678 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004679 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004680 return X.Container == Y.Container && X.Index == Y.Index;
4681 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004682
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004683 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004684 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004685 return !(X == Y);
4686 }
4687 };
4688}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004689
4690
John McCall43fed0d2010-11-12 08:19:04 +00004691template <typename Derived>
4692QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4693 TypeLocBuilder &TLB,
4694 TemplateSpecializationTypeLoc TL,
4695 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004696 TemplateArgumentListInfo NewTemplateArgs;
4697 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4698 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004699 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4700 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004701 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004702 ArgIterator(TL, TL.getNumArgs()),
4703 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004704 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004705
John McCall833ca992009-10-29 08:12:44 +00004706 // FIXME: maybe don't rebuild if all the template arguments are the same.
4707
4708 QualType Result =
4709 getDerived().RebuildTemplateSpecializationType(Template,
4710 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004711 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004712
4713 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004714 // Specializations of template template parameters are represented as
4715 // TemplateSpecializationTypes, and substitution of type alias templates
4716 // within a dependent context can transform them into
4717 // DependentTemplateSpecializationTypes.
4718 if (isa<DependentTemplateSpecializationType>(Result)) {
4719 DependentTemplateSpecializationTypeLoc NewTL
4720 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004721 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004722 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004723 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004724 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004725 NewTL.setLAngleLoc(TL.getLAngleLoc());
4726 NewTL.setRAngleLoc(TL.getRAngleLoc());
4727 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4728 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4729 return Result;
4730 }
4731
John McCall833ca992009-10-29 08:12:44 +00004732 TemplateSpecializationTypeLoc NewTL
4733 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004734 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004735 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4736 NewTL.setLAngleLoc(TL.getLAngleLoc());
4737 NewTL.setRAngleLoc(TL.getRAngleLoc());
4738 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4739 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004740 }
Mike Stump1eb44332009-09-09 15:08:12 +00004741
John McCall833ca992009-10-29 08:12:44 +00004742 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004743}
Mike Stump1eb44332009-09-09 15:08:12 +00004744
Douglas Gregora88f09f2011-02-28 17:23:35 +00004745template <typename Derived>
4746QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4747 TypeLocBuilder &TLB,
4748 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004749 TemplateName Template,
4750 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004751 TemplateArgumentListInfo NewTemplateArgs;
4752 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4753 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4754 typedef TemplateArgumentLocContainerIterator<
4755 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004756 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004757 ArgIterator(TL, TL.getNumArgs()),
4758 NewTemplateArgs))
4759 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004760
Douglas Gregora88f09f2011-02-28 17:23:35 +00004761 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004762
Douglas Gregora88f09f2011-02-28 17:23:35 +00004763 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4764 QualType Result
4765 = getSema().Context.getDependentTemplateSpecializationType(
4766 TL.getTypePtr()->getKeyword(),
4767 DTN->getQualifier(),
4768 DTN->getIdentifier(),
4769 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004770
Douglas Gregora88f09f2011-02-28 17:23:35 +00004771 DependentTemplateSpecializationTypeLoc NewTL
4772 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004773 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004774 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004775 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004776 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004777 NewTL.setLAngleLoc(TL.getLAngleLoc());
4778 NewTL.setRAngleLoc(TL.getRAngleLoc());
4779 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4780 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4781 return Result;
4782 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004783
4784 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004785 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004786 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004787 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004788
Douglas Gregora88f09f2011-02-28 17:23:35 +00004789 if (!Result.isNull()) {
4790 /// FIXME: Wrap this in an elaborated-type-specifier?
4791 TemplateSpecializationTypeLoc NewTL
4792 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004793 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004794 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004795 NewTL.setLAngleLoc(TL.getLAngleLoc());
4796 NewTL.setRAngleLoc(TL.getRAngleLoc());
4797 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4798 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4799 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004800
Douglas Gregora88f09f2011-02-28 17:23:35 +00004801 return Result;
4802}
4803
Mike Stump1eb44332009-09-09 15:08:12 +00004804template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004805QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004806TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004807 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004808 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004809
Douglas Gregor9e876872011-03-01 18:12:44 +00004810 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004811 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004812 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004813 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004814 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4815 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004816 return QualType();
4817 }
Mike Stump1eb44332009-09-09 15:08:12 +00004818
John McCall43fed0d2010-11-12 08:19:04 +00004819 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4820 if (NamedT.isNull())
4821 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004822
Richard Smith3e4c6c42011-05-05 21:57:07 +00004823 // C++0x [dcl.type.elab]p2:
4824 // If the identifier resolves to a typedef-name or the simple-template-id
4825 // resolves to an alias template specialization, the
4826 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004827 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4828 if (const TemplateSpecializationType *TST =
4829 NamedT->getAs<TemplateSpecializationType>()) {
4830 TemplateName Template = TST->getTemplateName();
4831 if (TypeAliasTemplateDecl *TAT =
4832 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4833 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4834 diag::err_tag_reference_non_tag) << 4;
4835 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4836 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004837 }
4838 }
4839
John McCalla2becad2009-10-21 00:40:46 +00004840 QualType Result = TL.getType();
4841 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004842 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004843 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004844 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004845 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004846 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004847 if (Result.isNull())
4848 return QualType();
4849 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004850
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004851 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004852 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004853 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004854 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004855}
Mike Stump1eb44332009-09-09 15:08:12 +00004856
4857template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004858QualType TreeTransform<Derived>::TransformAttributedType(
4859 TypeLocBuilder &TLB,
4860 AttributedTypeLoc TL) {
4861 const AttributedType *oldType = TL.getTypePtr();
4862 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4863 if (modifiedType.isNull())
4864 return QualType();
4865
4866 QualType result = TL.getType();
4867
4868 // FIXME: dependent operand expressions?
4869 if (getDerived().AlwaysRebuild() ||
4870 modifiedType != oldType->getModifiedType()) {
4871 // TODO: this is really lame; we should really be rebuilding the
4872 // equivalent type from first principles.
4873 QualType equivalentType
4874 = getDerived().TransformType(oldType->getEquivalentType());
4875 if (equivalentType.isNull())
4876 return QualType();
4877 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4878 modifiedType,
4879 equivalentType);
4880 }
4881
4882 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4883 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4884 if (TL.hasAttrOperand())
4885 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4886 if (TL.hasAttrExprOperand())
4887 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4888 else if (TL.hasAttrEnumOperand())
4889 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4890
4891 return result;
4892}
4893
4894template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004895QualType
4896TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4897 ParenTypeLoc TL) {
4898 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4899 if (Inner.isNull())
4900 return QualType();
4901
4902 QualType Result = TL.getType();
4903 if (getDerived().AlwaysRebuild() ||
4904 Inner != TL.getInnerLoc().getType()) {
4905 Result = getDerived().RebuildParenType(Inner);
4906 if (Result.isNull())
4907 return QualType();
4908 }
4909
4910 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4911 NewTL.setLParenLoc(TL.getLParenLoc());
4912 NewTL.setRParenLoc(TL.getRParenLoc());
4913 return Result;
4914}
4915
4916template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004917QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004918 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004919 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004920
Douglas Gregor2494dd02011-03-01 01:34:45 +00004921 NestedNameSpecifierLoc QualifierLoc
4922 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4923 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004924 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004925
John McCall33500952010-06-11 00:33:02 +00004926 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004927 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004928 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004929 QualifierLoc,
4930 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004931 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004932 if (Result.isNull())
4933 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004934
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004935 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4936 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004937 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4938
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004939 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004940 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004941 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004942 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004943 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004944 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004945 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004946 NewTL.setNameLoc(TL.getNameLoc());
4947 }
John McCalla2becad2009-10-21 00:40:46 +00004948 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004949}
Mike Stump1eb44332009-09-09 15:08:12 +00004950
Douglas Gregor577f75a2009-08-04 16:50:30 +00004951template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004952QualType TreeTransform<Derived>::
4953 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004954 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004955 NestedNameSpecifierLoc QualifierLoc;
4956 if (TL.getQualifierLoc()) {
4957 QualifierLoc
4958 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4959 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004960 return QualType();
4961 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004962
John McCall43fed0d2010-11-12 08:19:04 +00004963 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004964 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004965}
4966
4967template<typename Derived>
4968QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004969TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4970 DependentTemplateSpecializationTypeLoc TL,
4971 NestedNameSpecifierLoc QualifierLoc) {
4972 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004973
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004974 TemplateArgumentListInfo NewTemplateArgs;
4975 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4976 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004977
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004978 typedef TemplateArgumentLocContainerIterator<
4979 DependentTemplateSpecializationTypeLoc> ArgIterator;
4980 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4981 ArgIterator(TL, TL.getNumArgs()),
4982 NewTemplateArgs))
4983 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004984
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004985 QualType Result
4986 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4987 QualifierLoc,
4988 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004989 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004990 NewTemplateArgs);
4991 if (Result.isNull())
4992 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004993
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004994 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4995 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004996
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004997 // Copy information relevant to the template specialization.
4998 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004999 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005000 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005001 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005002 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5003 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005004 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005005 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005006
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005007 // Copy information relevant to the elaborated type.
5008 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005009 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005010 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005011 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5012 DependentTemplateSpecializationTypeLoc SpecTL
5013 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005014 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005015 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005016 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005017 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005018 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5019 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005020 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005021 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005022 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005023 TemplateSpecializationTypeLoc SpecTL
5024 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005025 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005026 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005027 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5028 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005029 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005030 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005031 }
5032 return Result;
5033}
5034
5035template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005036QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5037 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005038 QualType Pattern
5039 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005040 if (Pattern.isNull())
5041 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005042
5043 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005044 if (getDerived().AlwaysRebuild() ||
5045 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005046 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005047 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005048 TL.getEllipsisLoc(),
5049 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005050 if (Result.isNull())
5051 return QualType();
5052 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005053
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005054 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5055 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5056 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005057}
5058
5059template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005060QualType
5061TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005062 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005063 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005064 TLB.pushFullCopy(TL);
5065 return TL.getType();
5066}
5067
5068template<typename Derived>
5069QualType
5070TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005071 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005072 // ObjCObjectType is never dependent.
5073 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005074 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005075}
Mike Stump1eb44332009-09-09 15:08:12 +00005076
5077template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005078QualType
5079TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005080 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005081 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005082 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005083 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005084}
5085
Douglas Gregor577f75a2009-08-04 16:50:30 +00005086//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005087// Statement transformation
5088//===----------------------------------------------------------------------===//
5089template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005090StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005091TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005092 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005093}
5094
5095template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005096StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005097TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5098 return getDerived().TransformCompoundStmt(S, false);
5099}
5100
5101template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005102StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005103TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005104 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005105 Sema::CompoundScopeRAII CompoundScope(getSema());
5106
John McCall7114cba2010-08-27 19:56:05 +00005107 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005108 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005109 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005110 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5111 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005112 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005113 if (Result.isInvalid()) {
5114 // Immediately fail if this was a DeclStmt, since it's very
5115 // likely that this will cause problems for future statements.
5116 if (isa<DeclStmt>(*B))
5117 return StmtError();
5118
5119 // Otherwise, just keep processing substatements and fail later.
5120 SubStmtInvalid = true;
5121 continue;
5122 }
Mike Stump1eb44332009-09-09 15:08:12 +00005123
Douglas Gregor43959a92009-08-20 07:17:43 +00005124 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5125 Statements.push_back(Result.takeAs<Stmt>());
5126 }
Mike Stump1eb44332009-09-09 15:08:12 +00005127
John McCall7114cba2010-08-27 19:56:05 +00005128 if (SubStmtInvalid)
5129 return StmtError();
5130
Douglas Gregor43959a92009-08-20 07:17:43 +00005131 if (!getDerived().AlwaysRebuild() &&
5132 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005133 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005134
5135 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005136 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005137 S->getRBracLoc(),
5138 IsStmtExpr);
5139}
Mike Stump1eb44332009-09-09 15:08:12 +00005140
Douglas Gregor43959a92009-08-20 07:17:43 +00005141template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005142StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005143TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005144 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005145 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005146 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5147 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005148
Eli Friedman264c1f82009-11-19 03:14:00 +00005149 // Transform the left-hand case value.
5150 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005151 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005152 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005153 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005154
Eli Friedman264c1f82009-11-19 03:14:00 +00005155 // Transform the right-hand case value (for the GNU case-range extension).
5156 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005157 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005158 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005159 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005160 }
Mike Stump1eb44332009-09-09 15:08:12 +00005161
Douglas Gregor43959a92009-08-20 07:17:43 +00005162 // Build the case statement.
5163 // Case statements are always rebuilt so that they will attached to their
5164 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005165 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005166 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005167 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005168 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005169 S->getColonLoc());
5170 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005171 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005172
Douglas Gregor43959a92009-08-20 07:17:43 +00005173 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005174 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005175 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005176 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005177
Douglas Gregor43959a92009-08-20 07:17:43 +00005178 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005179 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005180}
5181
5182template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005183StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005184TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005185 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005186 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005187 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005188 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005189
Douglas Gregor43959a92009-08-20 07:17:43 +00005190 // Default statements are always rebuilt
5191 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005192 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005193}
Mike Stump1eb44332009-09-09 15:08:12 +00005194
Douglas Gregor43959a92009-08-20 07:17:43 +00005195template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005196StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005197TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005198 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005199 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005200 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005201
Chris Lattner57ad3782011-02-17 20:34:02 +00005202 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5203 S->getDecl());
5204 if (!LD)
5205 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005206
5207
Douglas Gregor43959a92009-08-20 07:17:43 +00005208 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005209 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005210 cast<LabelDecl>(LD), SourceLocation(),
5211 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005212}
Mike Stump1eb44332009-09-09 15:08:12 +00005213
Douglas Gregor43959a92009-08-20 07:17:43 +00005214template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005215StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005216TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5217 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5218 if (SubStmt.isInvalid())
5219 return StmtError();
5220
5221 // TODO: transform attributes
5222 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5223 return S;
5224
5225 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5226 S->getAttrs(),
5227 SubStmt.get());
5228}
5229
5230template<typename Derived>
5231StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005232TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005233 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005234 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005235 VarDecl *ConditionVar = 0;
5236 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005237 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005238 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005239 getDerived().TransformDefinition(
5240 S->getConditionVariable()->getLocation(),
5241 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005242 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005243 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005244 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005245 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005246
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005247 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005248 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005249
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005250 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005251 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005252 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005253 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005254 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005255 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005256
John McCall9ae2f072010-08-23 23:25:46 +00005257 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005258 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005259 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005260
John McCall9ae2f072010-08-23 23:25:46 +00005261 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5262 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005263 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005264
Douglas Gregor43959a92009-08-20 07:17:43 +00005265 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005266 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005267 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005268 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005269
Douglas Gregor43959a92009-08-20 07:17:43 +00005270 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005271 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005272 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005273 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005274
Douglas Gregor43959a92009-08-20 07:17:43 +00005275 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005276 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005277 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005278 Then.get() == S->getThen() &&
5279 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005280 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005281
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005282 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005283 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005284 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005285}
5286
5287template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005288StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005289TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005290 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005291 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005292 VarDecl *ConditionVar = 0;
5293 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005294 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005295 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005296 getDerived().TransformDefinition(
5297 S->getConditionVariable()->getLocation(),
5298 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005299 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005300 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005301 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005302 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005303
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005304 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005305 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005306 }
Mike Stump1eb44332009-09-09 15:08:12 +00005307
Douglas Gregor43959a92009-08-20 07:17:43 +00005308 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005309 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005310 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005311 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005312 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005313 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005314
Douglas Gregor43959a92009-08-20 07:17:43 +00005315 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005316 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005317 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005318 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005319
Douglas Gregor43959a92009-08-20 07:17:43 +00005320 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005321 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5322 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005323}
Mike Stump1eb44332009-09-09 15:08:12 +00005324
Douglas Gregor43959a92009-08-20 07:17:43 +00005325template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005326StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005327TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005328 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005329 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005330 VarDecl *ConditionVar = 0;
5331 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005332 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005333 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005334 getDerived().TransformDefinition(
5335 S->getConditionVariable()->getLocation(),
5336 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005337 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005338 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005339 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005340 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005341
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005342 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005343 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005344
5345 if (S->getCond()) {
5346 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005347 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005348 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005349 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005350 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005351 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005352 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005353 }
Mike Stump1eb44332009-09-09 15:08:12 +00005354
John McCall9ae2f072010-08-23 23:25:46 +00005355 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5356 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005357 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005358
Douglas Gregor43959a92009-08-20 07:17:43 +00005359 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005360 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005361 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005362 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005363
Douglas Gregor43959a92009-08-20 07:17:43 +00005364 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005365 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005366 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005367 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005368 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005369
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005370 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005371 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005372}
Mike Stump1eb44332009-09-09 15:08:12 +00005373
Douglas Gregor43959a92009-08-20 07:17:43 +00005374template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005375StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005376TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005377 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005378 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005379 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005380 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005381
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005382 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005383 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005384 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005385 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005386
Douglas Gregor43959a92009-08-20 07:17:43 +00005387 if (!getDerived().AlwaysRebuild() &&
5388 Cond.get() == S->getCond() &&
5389 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005390 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005391
John McCall9ae2f072010-08-23 23:25:46 +00005392 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5393 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005394 S->getRParenLoc());
5395}
Mike Stump1eb44332009-09-09 15:08:12 +00005396
Douglas Gregor43959a92009-08-20 07:17:43 +00005397template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005398StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005399TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005400 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005401 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005402 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005403 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005404
Douglas Gregor43959a92009-08-20 07:17:43 +00005405 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005406 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005407 VarDecl *ConditionVar = 0;
5408 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005409 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005410 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005411 getDerived().TransformDefinition(
5412 S->getConditionVariable()->getLocation(),
5413 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005414 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005415 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005416 } else {
5417 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005418
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005419 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005420 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005421
5422 if (S->getCond()) {
5423 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005424 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005425 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005426 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005427 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005428
John McCall9ae2f072010-08-23 23:25:46 +00005429 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005430 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005431 }
Mike Stump1eb44332009-09-09 15:08:12 +00005432
Chad Rosier4a9d7952012-08-08 18:46:20 +00005433 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005434 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005435 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005436
Douglas Gregor43959a92009-08-20 07:17:43 +00005437 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005438 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005439 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005440 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005441
John McCall9ae2f072010-08-23 23:25:46 +00005442 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5443 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005444 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005445
Douglas Gregor43959a92009-08-20 07:17:43 +00005446 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005447 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005448 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005449 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005450
Douglas Gregor43959a92009-08-20 07:17:43 +00005451 if (!getDerived().AlwaysRebuild() &&
5452 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005453 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005454 Inc.get() == S->getInc() &&
5455 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005456 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005457
Douglas Gregor43959a92009-08-20 07:17:43 +00005458 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005459 Init.get(), FullCond, ConditionVar,
5460 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005461}
5462
5463template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005464StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005465TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005466 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5467 S->getLabel());
5468 if (!LD)
5469 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005470
Douglas Gregor43959a92009-08-20 07:17:43 +00005471 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005472 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005473 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005474}
5475
5476template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005477StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005478TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005479 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005480 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005481 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005482 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005483
Douglas Gregor43959a92009-08-20 07:17:43 +00005484 if (!getDerived().AlwaysRebuild() &&
5485 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005486 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005487
5488 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005489 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005490}
5491
5492template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005493StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005494TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005495 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005496}
Mike Stump1eb44332009-09-09 15:08:12 +00005497
Douglas Gregor43959a92009-08-20 07:17:43 +00005498template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005499StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005500TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005501 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005502}
Mike Stump1eb44332009-09-09 15:08:12 +00005503
Douglas Gregor43959a92009-08-20 07:17:43 +00005504template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005505StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005506TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005507 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005508 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005509 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005510
Mike Stump1eb44332009-09-09 15:08:12 +00005511 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005512 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005513 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005514}
Mike Stump1eb44332009-09-09 15:08:12 +00005515
Douglas Gregor43959a92009-08-20 07:17:43 +00005516template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005517StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005518TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005519 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005520 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005521 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5522 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005523 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5524 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005525 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005526 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005527
Douglas Gregor43959a92009-08-20 07:17:43 +00005528 if (Transformed != *D)
5529 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005530
Douglas Gregor43959a92009-08-20 07:17:43 +00005531 Decls.push_back(Transformed);
5532 }
Mike Stump1eb44332009-09-09 15:08:12 +00005533
Douglas Gregor43959a92009-08-20 07:17:43 +00005534 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005535 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005536
5537 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005538 S->getStartLoc(), S->getEndLoc());
5539}
Mike Stump1eb44332009-09-09 15:08:12 +00005540
Douglas Gregor43959a92009-08-20 07:17:43 +00005541template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005542StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005543TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005544
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005545 SmallVector<Expr*, 8> Constraints;
5546 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005547 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005548
John McCall60d7b3a2010-08-24 06:29:42 +00005549 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005550 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005551
5552 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005553
Anders Carlsson703e3942010-01-24 05:50:09 +00005554 // Go through the outputs.
5555 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005556 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005557
Anders Carlsson703e3942010-01-24 05:50:09 +00005558 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005559 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005560
Anders Carlsson703e3942010-01-24 05:50:09 +00005561 // Transform the output expr.
5562 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005563 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005564 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005565 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005566
Anders Carlsson703e3942010-01-24 05:50:09 +00005567 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005568
John McCall9ae2f072010-08-23 23:25:46 +00005569 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005570 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005571
Anders Carlsson703e3942010-01-24 05:50:09 +00005572 // Go through the inputs.
5573 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005574 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005575
Anders Carlsson703e3942010-01-24 05:50:09 +00005576 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005577 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005578
Anders Carlsson703e3942010-01-24 05:50:09 +00005579 // Transform the input expr.
5580 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005581 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005582 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005583 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005584
Anders Carlsson703e3942010-01-24 05:50:09 +00005585 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005586
John McCall9ae2f072010-08-23 23:25:46 +00005587 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005588 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005589
Anders Carlsson703e3942010-01-24 05:50:09 +00005590 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005591 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005592
5593 // Go through the clobbers.
5594 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005595 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005596
5597 // No need to transform the asm string literal.
5598 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005599 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5600 S->isVolatile(), S->getNumOutputs(),
5601 S->getNumInputs(), Names.data(),
5602 Constraints, Exprs, AsmString.get(),
5603 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005604}
5605
Chad Rosier8cd64b42012-06-11 20:47:18 +00005606template<typename Derived>
5607StmtResult
5608TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005609 ArrayRef<Token> AsmToks =
5610 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005611
Chad Rosier7bd092b2012-08-15 16:53:30 +00005612 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
5613 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;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005626 SmallVector<Stmt*, 8> CatchStmts;
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(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005653 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(),
John McCall9ae2f072010-08-23 23:25:46 +00005804 Element.get(),
5805 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005806 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005807 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005808}
5809
5810
5811template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005812StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005813TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5814 // Transform the exception declaration, if any.
5815 VarDecl *Var = 0;
5816 if (S->getExceptionDecl()) {
5817 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005818 TypeSourceInfo *T = getDerived().TransformType(
5819 ExceptionDecl->getTypeSourceInfo());
5820 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005821 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005822
Douglas Gregor83cb9422010-09-09 17:09:21 +00005823 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005824 ExceptionDecl->getInnerLocStart(),
5825 ExceptionDecl->getLocation(),
5826 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005827 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005828 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005829 }
Mike Stump1eb44332009-09-09 15:08:12 +00005830
Douglas Gregor43959a92009-08-20 07:17:43 +00005831 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005832 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005833 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005834 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005835
Douglas Gregor43959a92009-08-20 07:17:43 +00005836 if (!getDerived().AlwaysRebuild() &&
5837 !Var &&
5838 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005839 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005840
5841 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5842 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005843 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005844}
Mike Stump1eb44332009-09-09 15:08:12 +00005845
Douglas Gregor43959a92009-08-20 07:17:43 +00005846template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005847StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005848TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5849 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005850 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005851 = getDerived().TransformCompoundStmt(S->getTryBlock());
5852 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005853 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005854
Douglas Gregor43959a92009-08-20 07:17:43 +00005855 // Transform the handlers.
5856 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005857 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00005858 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005859 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005860 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5861 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005862 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005863
Douglas Gregor43959a92009-08-20 07:17:43 +00005864 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5865 Handlers.push_back(Handler.takeAs<Stmt>());
5866 }
Mike Stump1eb44332009-09-09 15:08:12 +00005867
Douglas Gregor43959a92009-08-20 07:17:43 +00005868 if (!getDerived().AlwaysRebuild() &&
5869 TryBlock.get() == S->getTryBlock() &&
5870 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005871 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005872
John McCall9ae2f072010-08-23 23:25:46 +00005873 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005874 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00005875}
Mike Stump1eb44332009-09-09 15:08:12 +00005876
Richard Smithad762fc2011-04-14 22:09:26 +00005877template<typename Derived>
5878StmtResult
5879TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5880 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5881 if (Range.isInvalid())
5882 return StmtError();
5883
5884 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5885 if (BeginEnd.isInvalid())
5886 return StmtError();
5887
5888 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5889 if (Cond.isInvalid())
5890 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005891 if (Cond.get())
5892 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5893 if (Cond.isInvalid())
5894 return StmtError();
5895 if (Cond.get())
5896 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005897
5898 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5899 if (Inc.isInvalid())
5900 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005901 if (Inc.get())
5902 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005903
5904 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5905 if (LoopVar.isInvalid())
5906 return StmtError();
5907
5908 StmtResult NewStmt = S;
5909 if (getDerived().AlwaysRebuild() ||
5910 Range.get() != S->getRangeStmt() ||
5911 BeginEnd.get() != S->getBeginEndStmt() ||
5912 Cond.get() != S->getCond() ||
5913 Inc.get() != S->getInc() ||
5914 LoopVar.get() != S->getLoopVarStmt())
5915 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5916 S->getColonLoc(), Range.get(),
5917 BeginEnd.get(), Cond.get(),
5918 Inc.get(), LoopVar.get(),
5919 S->getRParenLoc());
5920
5921 StmtResult Body = getDerived().TransformStmt(S->getBody());
5922 if (Body.isInvalid())
5923 return StmtError();
5924
5925 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5926 // it now so we have a new statement to attach the body to.
5927 if (Body.get() != S->getBody() && NewStmt.get() == S)
5928 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5929 S->getColonLoc(), Range.get(),
5930 BeginEnd.get(), Cond.get(),
5931 Inc.get(), LoopVar.get(),
5932 S->getRParenLoc());
5933
5934 if (NewStmt.get() == S)
5935 return SemaRef.Owned(S);
5936
5937 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5938}
5939
John Wiegley28bbe4b2011-04-28 01:08:34 +00005940template<typename Derived>
5941StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005942TreeTransform<Derived>::TransformMSDependentExistsStmt(
5943 MSDependentExistsStmt *S) {
5944 // Transform the nested-name-specifier, if any.
5945 NestedNameSpecifierLoc QualifierLoc;
5946 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005947 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00005948 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5949 if (!QualifierLoc)
5950 return StmtError();
5951 }
5952
5953 // Transform the declaration name.
5954 DeclarationNameInfo NameInfo = S->getNameInfo();
5955 if (NameInfo.getName()) {
5956 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5957 if (!NameInfo.getName())
5958 return StmtError();
5959 }
5960
5961 // Check whether anything changed.
5962 if (!getDerived().AlwaysRebuild() &&
5963 QualifierLoc == S->getQualifierLoc() &&
5964 NameInfo.getName() == S->getNameInfo().getName())
5965 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005966
Douglas Gregorba0513d2011-10-25 01:33:02 +00005967 // Determine whether this name exists, if we can.
5968 CXXScopeSpec SS;
5969 SS.Adopt(QualifierLoc);
5970 bool Dependent = false;
5971 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5972 case Sema::IER_Exists:
5973 if (S->isIfExists())
5974 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005975
Douglas Gregorba0513d2011-10-25 01:33:02 +00005976 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5977
5978 case Sema::IER_DoesNotExist:
5979 if (S->isIfNotExists())
5980 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005981
Douglas Gregorba0513d2011-10-25 01:33:02 +00005982 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005983
Douglas Gregorba0513d2011-10-25 01:33:02 +00005984 case Sema::IER_Dependent:
5985 Dependent = true;
5986 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005987
Douglas Gregor65019ac2011-10-25 03:44:56 +00005988 case Sema::IER_Error:
5989 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005990 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005991
Douglas Gregorba0513d2011-10-25 01:33:02 +00005992 // We need to continue with the instantiation, so do so now.
5993 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5994 if (SubStmt.isInvalid())
5995 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005996
Douglas Gregorba0513d2011-10-25 01:33:02 +00005997 // If we have resolved the name, just transform to the substatement.
5998 if (!Dependent)
5999 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006000
Douglas Gregorba0513d2011-10-25 01:33:02 +00006001 // The name is still dependent, so build a dependent expression again.
6002 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6003 S->isIfExists(),
6004 QualifierLoc,
6005 NameInfo,
6006 SubStmt.get());
6007}
6008
6009template<typename Derived>
6010StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006011TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6012 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6013 if(TryBlock.isInvalid()) return StmtError();
6014
6015 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6016 if(!getDerived().AlwaysRebuild() &&
6017 TryBlock.get() == S->getTryBlock() &&
6018 Handler.get() == S->getHandler())
6019 return SemaRef.Owned(S);
6020
6021 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6022 S->getTryLoc(),
6023 TryBlock.take(),
6024 Handler.take());
6025}
6026
6027template<typename Derived>
6028StmtResult
6029TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6030 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6031 if(Block.isInvalid()) return StmtError();
6032
6033 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6034 Block.take());
6035}
6036
6037template<typename Derived>
6038StmtResult
6039TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6040 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6041 if(FilterExpr.isInvalid()) return StmtError();
6042
6043 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6044 if(Block.isInvalid()) return StmtError();
6045
6046 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6047 FilterExpr.take(),
6048 Block.take());
6049}
6050
6051template<typename Derived>
6052StmtResult
6053TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6054 if(isa<SEHFinallyStmt>(Handler))
6055 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6056 else
6057 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6058}
6059
Douglas Gregor43959a92009-08-20 07:17:43 +00006060//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006061// Expression transformation
6062//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006063template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006064ExprResult
John McCall454feb92009-12-08 09:21:05 +00006065TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006066 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006067}
Mike Stump1eb44332009-09-09 15:08:12 +00006068
6069template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006070ExprResult
John McCall454feb92009-12-08 09:21:05 +00006071TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006072 NestedNameSpecifierLoc QualifierLoc;
6073 if (E->getQualifierLoc()) {
6074 QualifierLoc
6075 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6076 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006077 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006078 }
John McCalldbd872f2009-12-08 09:08:17 +00006079
6080 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006081 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6082 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006083 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006084 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006085
John McCallec8045d2010-08-17 21:27:17 +00006086 DeclarationNameInfo NameInfo = E->getNameInfo();
6087 if (NameInfo.getName()) {
6088 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6089 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006090 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006091 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006092
6093 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006094 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006095 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006096 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006097 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006098
6099 // Mark it referenced in the new context regardless.
6100 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006101 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006102
John McCall3fa5cae2010-10-26 07:05:15 +00006103 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006104 }
John McCalldbd872f2009-12-08 09:08:17 +00006105
6106 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006107 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006108 TemplateArgs = &TransArgs;
6109 TransArgs.setLAngleLoc(E->getLAngleLoc());
6110 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006111 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6112 E->getNumTemplateArgs(),
6113 TransArgs))
6114 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006115 }
6116
Chad Rosier4a9d7952012-08-08 18:46:20 +00006117 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006118 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006119}
Mike Stump1eb44332009-09-09 15:08:12 +00006120
Douglas Gregorb98b1992009-08-11 05:31:07 +00006121template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006122ExprResult
John McCall454feb92009-12-08 09:21:05 +00006123TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006124 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006125}
Mike Stump1eb44332009-09-09 15:08:12 +00006126
Douglas Gregorb98b1992009-08-11 05:31:07 +00006127template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006128ExprResult
John McCall454feb92009-12-08 09:21:05 +00006129TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006130 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006131}
Mike Stump1eb44332009-09-09 15:08:12 +00006132
Douglas Gregorb98b1992009-08-11 05:31:07 +00006133template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006134ExprResult
John McCall454feb92009-12-08 09:21:05 +00006135TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006136 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006137}
Mike Stump1eb44332009-09-09 15:08:12 +00006138
Douglas Gregorb98b1992009-08-11 05:31:07 +00006139template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006140ExprResult
John McCall454feb92009-12-08 09:21:05 +00006141TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006142 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006143}
Mike Stump1eb44332009-09-09 15:08:12 +00006144
Douglas Gregorb98b1992009-08-11 05:31:07 +00006145template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006146ExprResult
John McCall454feb92009-12-08 09:21:05 +00006147TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006148 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006149}
6150
6151template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006152ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006153TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6154 return SemaRef.MaybeBindToTemporary(E);
6155}
6156
6157template<typename Derived>
6158ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006159TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6160 ExprResult ControllingExpr =
6161 getDerived().TransformExpr(E->getControllingExpr());
6162 if (ControllingExpr.isInvalid())
6163 return ExprError();
6164
Chris Lattner686775d2011-07-20 06:58:45 +00006165 SmallVector<Expr *, 4> AssocExprs;
6166 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006167 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6168 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6169 if (TS) {
6170 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6171 if (!AssocType)
6172 return ExprError();
6173 AssocTypes.push_back(AssocType);
6174 } else {
6175 AssocTypes.push_back(0);
6176 }
6177
6178 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6179 if (AssocExpr.isInvalid())
6180 return ExprError();
6181 AssocExprs.push_back(AssocExpr.release());
6182 }
6183
6184 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6185 E->getDefaultLoc(),
6186 E->getRParenLoc(),
6187 ControllingExpr.release(),
6188 AssocTypes.data(),
6189 AssocExprs.data(),
6190 E->getNumAssocs());
6191}
6192
6193template<typename Derived>
6194ExprResult
John McCall454feb92009-12-08 09:21:05 +00006195TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006196 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006197 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006198 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006199
Douglas Gregorb98b1992009-08-11 05:31:07 +00006200 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006201 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006202
John McCall9ae2f072010-08-23 23:25:46 +00006203 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006204 E->getRParen());
6205}
6206
Richard Smithefeeccf2012-10-21 03:28:35 +00006207/// \brief The operand of a unary address-of operator has special rules: it's
6208/// allowed to refer to a non-static member of a class even if there's no 'this'
6209/// object available.
6210template<typename Derived>
6211ExprResult
6212TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6213 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6214 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6215 else
6216 return getDerived().TransformExpr(E);
6217}
6218
Mike Stump1eb44332009-09-09 15:08:12 +00006219template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006220ExprResult
John McCall454feb92009-12-08 09:21:05 +00006221TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00006222 ExprResult SubExpr = TransformAddressOfOperand(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006223 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006224 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006225
Douglas Gregorb98b1992009-08-11 05:31:07 +00006226 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006227 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006228
Douglas Gregorb98b1992009-08-11 05:31:07 +00006229 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6230 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006231 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006232}
Mike Stump1eb44332009-09-09 15:08:12 +00006233
Douglas Gregorb98b1992009-08-11 05:31:07 +00006234template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006235ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006236TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6237 // Transform the type.
6238 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6239 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006240 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006241
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006242 // Transform all of the components into components similar to what the
6243 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006244 // FIXME: It would be slightly more efficient in the non-dependent case to
6245 // just map FieldDecls, rather than requiring the rebuilder to look for
6246 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006247 // template code that we don't care.
6248 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006249 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006250 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006251 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006252 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6253 const Node &ON = E->getComponent(I);
6254 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006255 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006256 Comp.LocStart = ON.getSourceRange().getBegin();
6257 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006258 switch (ON.getKind()) {
6259 case Node::Array: {
6260 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006261 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006262 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006263 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006264
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006265 ExprChanged = ExprChanged || Index.get() != FromIndex;
6266 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006267 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006268 break;
6269 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006270
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006271 case Node::Field:
6272 case Node::Identifier:
6273 Comp.isBrackets = false;
6274 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006275 if (!Comp.U.IdentInfo)
6276 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006277
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006278 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006279
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006280 case Node::Base:
6281 // Will be recomputed during the rebuild.
6282 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006283 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006284
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006285 Components.push_back(Comp);
6286 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006287
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006288 // If nothing changed, retain the existing expression.
6289 if (!getDerived().AlwaysRebuild() &&
6290 Type == E->getTypeSourceInfo() &&
6291 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006292 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006293
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006294 // Build a new offsetof expression.
6295 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6296 Components.data(), Components.size(),
6297 E->getRParenLoc());
6298}
6299
6300template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006301ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006302TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6303 assert(getDerived().AlreadyTransformed(E->getType()) &&
6304 "opaque value expression requires transformation");
6305 return SemaRef.Owned(E);
6306}
6307
6308template<typename Derived>
6309ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006310TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006311 // Rebuild the syntactic form. The original syntactic form has
6312 // opaque-value expressions in it, so strip those away and rebuild
6313 // the result. This is a really awful way of doing this, but the
6314 // better solution (rebuilding the semantic expressions and
6315 // rebinding OVEs as necessary) doesn't work; we'd need
6316 // TreeTransform to not strip away implicit conversions.
6317 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6318 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006319 if (result.isInvalid()) return ExprError();
6320
6321 // If that gives us a pseudo-object result back, the pseudo-object
6322 // expression must have been an lvalue-to-rvalue conversion which we
6323 // should reapply.
6324 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6325 result = SemaRef.checkPseudoObjectRValue(result.take());
6326
6327 return result;
6328}
6329
6330template<typename Derived>
6331ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006332TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6333 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006334 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006335 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006336
John McCalla93c9342009-12-07 02:54:59 +00006337 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006338 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006339 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006340
John McCall5ab75172009-11-04 07:28:41 +00006341 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006342 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006343
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006344 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6345 E->getKind(),
6346 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006347 }
Mike Stump1eb44332009-09-09 15:08:12 +00006348
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006349 // C++0x [expr.sizeof]p1:
6350 // The operand is either an expression, which is an unevaluated operand
6351 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006352 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6353 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006354
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006355 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6356 if (SubExpr.isInvalid())
6357 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006358
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006359 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6360 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006361
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006362 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6363 E->getOperatorLoc(),
6364 E->getKind(),
6365 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006366}
Mike Stump1eb44332009-09-09 15:08:12 +00006367
Douglas Gregorb98b1992009-08-11 05:31:07 +00006368template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006369ExprResult
John McCall454feb92009-12-08 09:21:05 +00006370TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006371 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006372 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006373 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006374
John McCall60d7b3a2010-08-24 06:29:42 +00006375 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006376 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006377 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006378
6379
Douglas Gregorb98b1992009-08-11 05:31:07 +00006380 if (!getDerived().AlwaysRebuild() &&
6381 LHS.get() == E->getLHS() &&
6382 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006383 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006384
John McCall9ae2f072010-08-23 23:25:46 +00006385 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006386 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006387 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006388 E->getRBracketLoc());
6389}
Mike Stump1eb44332009-09-09 15:08:12 +00006390
6391template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006392ExprResult
John McCall454feb92009-12-08 09:21:05 +00006393TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006394 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006395 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006396 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006397 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006398
6399 // Transform arguments.
6400 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006401 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006402 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006403 &ArgChanged))
6404 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006405
Douglas Gregorb98b1992009-08-11 05:31:07 +00006406 if (!getDerived().AlwaysRebuild() &&
6407 Callee.get() == E->getCallee() &&
6408 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006409 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006410
Douglas Gregorb98b1992009-08-11 05:31:07 +00006411 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006412 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006413 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006414 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006415 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006416 E->getRParenLoc());
6417}
Mike Stump1eb44332009-09-09 15:08:12 +00006418
6419template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006420ExprResult
John McCall454feb92009-12-08 09:21:05 +00006421TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006422 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006423 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006424 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006425
Douglas Gregor40d96a62011-02-28 21:54:11 +00006426 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006427 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006428 QualifierLoc
6429 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006430
Douglas Gregor40d96a62011-02-28 21:54:11 +00006431 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006432 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006433 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006434 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006435
Eli Friedmanf595cc42009-12-04 06:40:45 +00006436 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006437 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6438 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006439 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006440 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006441
John McCall6bb80172010-03-30 21:47:33 +00006442 NamedDecl *FoundDecl = E->getFoundDecl();
6443 if (FoundDecl == E->getMemberDecl()) {
6444 FoundDecl = Member;
6445 } else {
6446 FoundDecl = cast_or_null<NamedDecl>(
6447 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6448 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006449 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006450 }
6451
Douglas Gregorb98b1992009-08-11 05:31:07 +00006452 if (!getDerived().AlwaysRebuild() &&
6453 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006454 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006455 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006456 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006457 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006458
Anders Carlsson1f240322009-12-22 05:24:09 +00006459 // Mark it referenced in the new context regardless.
6460 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006461 SemaRef.MarkMemberReferenced(E);
6462
John McCall3fa5cae2010-10-26 07:05:15 +00006463 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006464 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006465
John McCalld5532b62009-11-23 01:53:49 +00006466 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006467 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006468 TransArgs.setLAngleLoc(E->getLAngleLoc());
6469 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006470 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6471 E->getNumTemplateArgs(),
6472 TransArgs))
6473 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006474 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006475
Douglas Gregorb98b1992009-08-11 05:31:07 +00006476 // FIXME: Bogus source location for the operator
6477 SourceLocation FakeOperatorLoc
6478 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6479
John McCallc2233c52010-01-15 08:34:02 +00006480 // FIXME: to do this check properly, we will need to preserve the
6481 // first-qualifier-in-scope here, just in case we had a dependent
6482 // base (and therefore couldn't do the check) and a
6483 // nested-name-qualifier (and therefore could do the lookup).
6484 NamedDecl *FirstQualifierInScope = 0;
6485
John McCall9ae2f072010-08-23 23:25:46 +00006486 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006487 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006488 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006489 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006490 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006491 Member,
John McCall6bb80172010-03-30 21:47:33 +00006492 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006493 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006494 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006495 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006496}
Mike Stump1eb44332009-09-09 15:08:12 +00006497
Douglas Gregorb98b1992009-08-11 05:31:07 +00006498template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006499ExprResult
John McCall454feb92009-12-08 09:21:05 +00006500TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006501 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006502 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006503 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006504
John McCall60d7b3a2010-08-24 06:29:42 +00006505 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006506 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006507 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006508
Douglas Gregorb98b1992009-08-11 05:31:07 +00006509 if (!getDerived().AlwaysRebuild() &&
6510 LHS.get() == E->getLHS() &&
6511 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006512 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006513
Lang Hamesbe9af122012-10-02 04:45:10 +00006514 Sema::FPContractStateRAII FPContractState(getSema());
6515 getSema().FPFeatures.fp_contract = E->isFPContractable();
6516
Douglas Gregorb98b1992009-08-11 05:31:07 +00006517 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006518 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006519}
6520
Mike Stump1eb44332009-09-09 15:08:12 +00006521template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006522ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006523TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006524 CompoundAssignOperator *E) {
6525 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006526}
Mike Stump1eb44332009-09-09 15:08:12 +00006527
Douglas Gregorb98b1992009-08-11 05:31:07 +00006528template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006529ExprResult TreeTransform<Derived>::
6530TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6531 // Just rebuild the common and RHS expressions and see whether we
6532 // get any changes.
6533
6534 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6535 if (commonExpr.isInvalid())
6536 return ExprError();
6537
6538 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6539 if (rhs.isInvalid())
6540 return ExprError();
6541
6542 if (!getDerived().AlwaysRebuild() &&
6543 commonExpr.get() == e->getCommon() &&
6544 rhs.get() == e->getFalseExpr())
6545 return SemaRef.Owned(e);
6546
6547 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6548 e->getQuestionLoc(),
6549 0,
6550 e->getColonLoc(),
6551 rhs.get());
6552}
6553
6554template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006555ExprResult
John McCall454feb92009-12-08 09:21:05 +00006556TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006557 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006558 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006559 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006560
John McCall60d7b3a2010-08-24 06:29:42 +00006561 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006562 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006563 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006564
John McCall60d7b3a2010-08-24 06:29:42 +00006565 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006566 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006567 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006568
Douglas Gregorb98b1992009-08-11 05:31:07 +00006569 if (!getDerived().AlwaysRebuild() &&
6570 Cond.get() == E->getCond() &&
6571 LHS.get() == E->getLHS() &&
6572 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006573 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006574
John McCall9ae2f072010-08-23 23:25:46 +00006575 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006576 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006577 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006578 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006579 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006580}
Mike Stump1eb44332009-09-09 15:08:12 +00006581
6582template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006583ExprResult
John McCall454feb92009-12-08 09:21:05 +00006584TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006585 // Implicit casts are eliminated during transformation, since they
6586 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006587 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006588}
Mike Stump1eb44332009-09-09 15:08:12 +00006589
Douglas Gregorb98b1992009-08-11 05:31:07 +00006590template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006591ExprResult
John McCall454feb92009-12-08 09:21:05 +00006592TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006593 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6594 if (!Type)
6595 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006596
John McCall60d7b3a2010-08-24 06:29:42 +00006597 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006598 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006599 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006600 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006601
Douglas Gregorb98b1992009-08-11 05:31:07 +00006602 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006603 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006604 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006605 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006606
John McCall9d125032010-01-15 18:39:57 +00006607 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006608 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006609 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006610 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006611}
Mike Stump1eb44332009-09-09 15:08:12 +00006612
Douglas Gregorb98b1992009-08-11 05:31:07 +00006613template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006614ExprResult
John McCall454feb92009-12-08 09:21:05 +00006615TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006616 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6617 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6618 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006619 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006620
John McCall60d7b3a2010-08-24 06:29:42 +00006621 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006622 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006623 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006624
Douglas Gregorb98b1992009-08-11 05:31:07 +00006625 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006626 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006627 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006628 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006629
John McCall1d7d8d62010-01-19 22:33:45 +00006630 // Note: the expression type doesn't necessarily match the
6631 // type-as-written, but that's okay, because it should always be
6632 // derivable from the initializer.
6633
John McCall42f56b52010-01-18 19:35:47 +00006634 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006636 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006637}
Mike Stump1eb44332009-09-09 15:08:12 +00006638
Douglas Gregorb98b1992009-08-11 05:31:07 +00006639template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006640ExprResult
John McCall454feb92009-12-08 09:21:05 +00006641TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006642 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006643 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006644 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006645
Douglas Gregorb98b1992009-08-11 05:31:07 +00006646 if (!getDerived().AlwaysRebuild() &&
6647 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006648 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006649
Douglas Gregorb98b1992009-08-11 05:31:07 +00006650 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006651 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006652 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006653 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006654 E->getAccessorLoc(),
6655 E->getAccessor());
6656}
Mike Stump1eb44332009-09-09 15:08:12 +00006657
Douglas Gregorb98b1992009-08-11 05:31:07 +00006658template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006659ExprResult
John McCall454feb92009-12-08 09:21:05 +00006660TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006661 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006662
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006663 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006664 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006665 Inits, &InitChanged))
6666 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006667
Douglas Gregorb98b1992009-08-11 05:31:07 +00006668 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006669 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006670
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006671 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006672 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006673}
Mike Stump1eb44332009-09-09 15:08:12 +00006674
Douglas Gregorb98b1992009-08-11 05:31:07 +00006675template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006676ExprResult
John McCall454feb92009-12-08 09:21:05 +00006677TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006678 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006679
Douglas Gregor43959a92009-08-20 07:17:43 +00006680 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006681 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006682 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006683 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006684
Douglas Gregor43959a92009-08-20 07:17:43 +00006685 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006686 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006687 bool ExprChanged = false;
6688 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6689 DEnd = E->designators_end();
6690 D != DEnd; ++D) {
6691 if (D->isFieldDesignator()) {
6692 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6693 D->getDotLoc(),
6694 D->getFieldLoc()));
6695 continue;
6696 }
Mike Stump1eb44332009-09-09 15:08:12 +00006697
Douglas Gregorb98b1992009-08-11 05:31:07 +00006698 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006699 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006700 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006701 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006702
6703 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006704 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006705
Douglas Gregorb98b1992009-08-11 05:31:07 +00006706 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6707 ArrayExprs.push_back(Index.release());
6708 continue;
6709 }
Mike Stump1eb44332009-09-09 15:08:12 +00006710
Douglas Gregorb98b1992009-08-11 05:31:07 +00006711 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006712 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006713 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6714 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006715 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006716
John McCall60d7b3a2010-08-24 06:29:42 +00006717 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006718 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006719 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006720
6721 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006722 End.get(),
6723 D->getLBracketLoc(),
6724 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006725
Douglas Gregorb98b1992009-08-11 05:31:07 +00006726 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6727 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006728
Douglas Gregorb98b1992009-08-11 05:31:07 +00006729 ArrayExprs.push_back(Start.release());
6730 ArrayExprs.push_back(End.release());
6731 }
Mike Stump1eb44332009-09-09 15:08:12 +00006732
Douglas Gregorb98b1992009-08-11 05:31:07 +00006733 if (!getDerived().AlwaysRebuild() &&
6734 Init.get() == E->getInit() &&
6735 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006736 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006737
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006738 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006739 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006740 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006741}
Mike Stump1eb44332009-09-09 15:08:12 +00006742
Douglas Gregorb98b1992009-08-11 05:31:07 +00006743template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006744ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006745TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006746 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006747 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006748
Douglas Gregor5557b252009-10-28 00:29:27 +00006749 // FIXME: Will we ever have proper type location here? Will we actually
6750 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006751 QualType T = getDerived().TransformType(E->getType());
6752 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006753 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006754
Douglas Gregorb98b1992009-08-11 05:31:07 +00006755 if (!getDerived().AlwaysRebuild() &&
6756 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006757 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006758
Douglas Gregorb98b1992009-08-11 05:31:07 +00006759 return getDerived().RebuildImplicitValueInitExpr(T);
6760}
Mike Stump1eb44332009-09-09 15:08:12 +00006761
Douglas Gregorb98b1992009-08-11 05:31:07 +00006762template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006763ExprResult
John McCall454feb92009-12-08 09:21:05 +00006764TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006765 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6766 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006767 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006768
John McCall60d7b3a2010-08-24 06:29:42 +00006769 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006770 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006771 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006772
Douglas Gregorb98b1992009-08-11 05:31:07 +00006773 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006774 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006775 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006776 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006777
John McCall9ae2f072010-08-23 23:25:46 +00006778 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006779 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006780}
6781
6782template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006783ExprResult
John McCall454feb92009-12-08 09:21:05 +00006784TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006785 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006786 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00006787 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6788 &ArgumentChanged))
6789 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006790
Douglas Gregorb98b1992009-08-11 05:31:07 +00006791 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006792 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006793 E->getRParenLoc());
6794}
Mike Stump1eb44332009-09-09 15:08:12 +00006795
Douglas Gregorb98b1992009-08-11 05:31:07 +00006796/// \brief Transform an address-of-label expression.
6797///
6798/// By default, the transformation of an address-of-label expression always
6799/// rebuilds the expression, so that the label identifier can be resolved to
6800/// the corresponding label statement by semantic analysis.
6801template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006802ExprResult
John McCall454feb92009-12-08 09:21:05 +00006803TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006804 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6805 E->getLabel());
6806 if (!LD)
6807 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006808
Douglas Gregorb98b1992009-08-11 05:31:07 +00006809 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006810 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006811}
Mike Stump1eb44332009-09-09 15:08:12 +00006812
6813template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006814ExprResult
John McCall454feb92009-12-08 09:21:05 +00006815TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006816 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006817 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006818 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006819 if (SubStmt.isInvalid()) {
6820 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006821 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006822 }
Mike Stump1eb44332009-09-09 15:08:12 +00006823
Douglas Gregorb98b1992009-08-11 05:31:07 +00006824 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006825 SubStmt.get() == E->getSubStmt()) {
6826 // Calling this an 'error' is unintuitive, but it does the right thing.
6827 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006828 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006829 }
Mike Stump1eb44332009-09-09 15:08:12 +00006830
6831 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006832 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006833 E->getRParenLoc());
6834}
Mike Stump1eb44332009-09-09 15:08:12 +00006835
Douglas Gregorb98b1992009-08-11 05:31:07 +00006836template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006837ExprResult
John McCall454feb92009-12-08 09:21:05 +00006838TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006839 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006840 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006841 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006842
John McCall60d7b3a2010-08-24 06:29:42 +00006843 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006844 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006845 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006846
John McCall60d7b3a2010-08-24 06:29:42 +00006847 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006848 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006849 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006850
Douglas Gregorb98b1992009-08-11 05:31:07 +00006851 if (!getDerived().AlwaysRebuild() &&
6852 Cond.get() == E->getCond() &&
6853 LHS.get() == E->getLHS() &&
6854 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006855 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006856
Douglas Gregorb98b1992009-08-11 05:31:07 +00006857 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006858 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006859 E->getRParenLoc());
6860}
Mike Stump1eb44332009-09-09 15:08:12 +00006861
Douglas Gregorb98b1992009-08-11 05:31:07 +00006862template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006863ExprResult
John McCall454feb92009-12-08 09:21:05 +00006864TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006865 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006866}
6867
6868template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006869ExprResult
John McCall454feb92009-12-08 09:21:05 +00006870TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006871 switch (E->getOperator()) {
6872 case OO_New:
6873 case OO_Delete:
6874 case OO_Array_New:
6875 case OO_Array_Delete:
6876 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006877
Douglas Gregor668d6d92009-12-13 20:44:55 +00006878 case OO_Call: {
6879 // This is a call to an object's operator().
6880 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6881
6882 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006883 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006884 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006885 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006886
6887 // FIXME: Poor location information
6888 SourceLocation FakeLParenLoc
6889 = SemaRef.PP.getLocForEndOfToken(
6890 static_cast<Expr *>(Object.get())->getLocEnd());
6891
6892 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006893 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006894 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006895 Args))
6896 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006897
John McCall9ae2f072010-08-23 23:25:46 +00006898 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006899 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006900 E->getLocEnd());
6901 }
6902
6903#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6904 case OO_##Name:
6905#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6906#include "clang/Basic/OperatorKinds.def"
6907 case OO_Subscript:
6908 // Handled below.
6909 break;
6910
6911 case OO_Conditional:
6912 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006913
6914 case OO_None:
6915 case NUM_OVERLOADED_OPERATORS:
6916 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006917 }
6918
John McCall60d7b3a2010-08-24 06:29:42 +00006919 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006920 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006921 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006922
Richard Smithefeeccf2012-10-21 03:28:35 +00006923 ExprResult First;
6924 if (E->getOperator() == OO_Amp)
6925 First = getDerived().TransformAddressOfOperand(E->getArg(0));
6926 else
6927 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006928 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006929 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006930
John McCall60d7b3a2010-08-24 06:29:42 +00006931 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006932 if (E->getNumArgs() == 2) {
6933 Second = getDerived().TransformExpr(E->getArg(1));
6934 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006935 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006936 }
Mike Stump1eb44332009-09-09 15:08:12 +00006937
Douglas Gregorb98b1992009-08-11 05:31:07 +00006938 if (!getDerived().AlwaysRebuild() &&
6939 Callee.get() == E->getCallee() &&
6940 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006941 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006942 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006943
Lang Hamesbe9af122012-10-02 04:45:10 +00006944 Sema::FPContractStateRAII FPContractState(getSema());
6945 getSema().FPFeatures.fp_contract = E->isFPContractable();
6946
Douglas Gregorb98b1992009-08-11 05:31:07 +00006947 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6948 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006949 Callee.get(),
6950 First.get(),
6951 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006952}
Mike Stump1eb44332009-09-09 15:08:12 +00006953
Douglas Gregorb98b1992009-08-11 05:31:07 +00006954template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006955ExprResult
John McCall454feb92009-12-08 09:21:05 +00006956TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6957 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006958}
Mike Stump1eb44332009-09-09 15:08:12 +00006959
Douglas Gregorb98b1992009-08-11 05:31:07 +00006960template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006961ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006962TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6963 // Transform the callee.
6964 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6965 if (Callee.isInvalid())
6966 return ExprError();
6967
6968 // Transform exec config.
6969 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6970 if (EC.isInvalid())
6971 return ExprError();
6972
6973 // Transform arguments.
6974 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006975 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006976 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006977 &ArgChanged))
6978 return ExprError();
6979
6980 if (!getDerived().AlwaysRebuild() &&
6981 Callee.get() == E->getCallee() &&
6982 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006983 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006984
6985 // FIXME: Wrong source location information for the '('.
6986 SourceLocation FakeLParenLoc
6987 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6988 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006989 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006990 E->getRParenLoc(), EC.get());
6991}
6992
6993template<typename Derived>
6994ExprResult
John McCall454feb92009-12-08 09:21:05 +00006995TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006996 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6997 if (!Type)
6998 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006999
John McCall60d7b3a2010-08-24 06:29:42 +00007000 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007001 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007002 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007003 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007004
Douglas Gregorb98b1992009-08-11 05:31:07 +00007005 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007006 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007007 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007008 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007009
Douglas Gregorb98b1992009-08-11 05:31:07 +00007010 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00007011 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007012 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
7013 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007014 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007015 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007016 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007017 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007018 FakeRAngleLoc,
7019 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007020 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007021 E->getRParenLoc());
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>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7027 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007028}
Mike Stump1eb44332009-09-09 15:08:12 +00007029
7030template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007031ExprResult
John McCall454feb92009-12-08 09:21:05 +00007032TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7033 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007034}
7035
Douglas Gregorb98b1992009-08-11 05:31:07 +00007036template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007037ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007038TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007039 CXXReinterpretCastExpr *E) {
7040 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007041}
Mike Stump1eb44332009-09-09 15:08:12 +00007042
Douglas Gregorb98b1992009-08-11 05:31:07 +00007043template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007044ExprResult
John McCall454feb92009-12-08 09:21:05 +00007045TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7046 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007047}
Mike Stump1eb44332009-09-09 15:08:12 +00007048
Douglas Gregorb98b1992009-08-11 05:31:07 +00007049template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007050ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007051TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007052 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007053 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7054 if (!Type)
7055 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007056
John McCall60d7b3a2010-08-24 06:29:42 +00007057 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007058 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007059 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007060 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007061
Douglas Gregorb98b1992009-08-11 05:31:07 +00007062 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007063 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007064 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007065 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007066
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007067 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007068 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007069 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007070 E->getRParenLoc());
7071}
Mike Stump1eb44332009-09-09 15:08:12 +00007072
Douglas Gregorb98b1992009-08-11 05:31:07 +00007073template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007074ExprResult
John McCall454feb92009-12-08 09:21:05 +00007075TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007076 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007077 TypeSourceInfo *TInfo
7078 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7079 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007080 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007081
Douglas Gregorb98b1992009-08-11 05:31:07 +00007082 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007083 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007084 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007085
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007086 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7087 E->getLocStart(),
7088 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007089 E->getLocEnd());
7090 }
Mike Stump1eb44332009-09-09 15:08:12 +00007091
Eli Friedmanef331b72012-01-20 01:26:23 +00007092 // We don't know whether the subexpression is potentially evaluated until
7093 // after we perform semantic analysis. We speculatively assume it is
7094 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007095 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007096 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7097 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007098
John McCall60d7b3a2010-08-24 06:29:42 +00007099 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007100 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007101 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007102
Douglas Gregorb98b1992009-08-11 05:31:07 +00007103 if (!getDerived().AlwaysRebuild() &&
7104 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007105 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007106
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007107 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7108 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007109 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007110 E->getLocEnd());
7111}
7112
7113template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007114ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007115TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7116 if (E->isTypeOperand()) {
7117 TypeSourceInfo *TInfo
7118 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7119 if (!TInfo)
7120 return ExprError();
7121
7122 if (!getDerived().AlwaysRebuild() &&
7123 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007124 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007125
Douglas Gregor3c52a212011-03-06 17:40:41 +00007126 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007127 E->getLocStart(),
7128 TInfo,
7129 E->getLocEnd());
7130 }
7131
Francois Pichet01b7c302010-09-08 12:20:18 +00007132 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7133
7134 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7135 if (SubExpr.isInvalid())
7136 return ExprError();
7137
7138 if (!getDerived().AlwaysRebuild() &&
7139 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007140 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007141
7142 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7143 E->getLocStart(),
7144 SubExpr.get(),
7145 E->getLocEnd());
7146}
7147
7148template<typename Derived>
7149ExprResult
John McCall454feb92009-12-08 09:21:05 +00007150TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007151 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007152}
Mike Stump1eb44332009-09-09 15:08:12 +00007153
Douglas Gregorb98b1992009-08-11 05:31:07 +00007154template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007155ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007156TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007157 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007158 return SemaRef.Owned(E);
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>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007164 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007165 QualType T;
7166 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7167 T = MD->getThisType(getSema().Context);
7168 else
7169 T = getSema().Context.getPointerType(
7170 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007171
Douglas Gregorec79d872012-02-24 17:41:38 +00007172 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7173 // Make sure that we capture 'this'.
7174 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007175 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007176 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007177
Douglas Gregor828a1972010-01-07 23:12:05 +00007178 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007179}
Mike Stump1eb44332009-09-09 15:08:12 +00007180
Douglas Gregorb98b1992009-08-11 05:31:07 +00007181template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007182ExprResult
John McCall454feb92009-12-08 09:21:05 +00007183TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007184 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007185 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007186 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007187
Douglas Gregorb98b1992009-08-11 05:31:07 +00007188 if (!getDerived().AlwaysRebuild() &&
7189 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007190 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007191
Douglas Gregorbca01b42011-07-06 22:04:06 +00007192 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7193 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007194}
Mike Stump1eb44332009-09-09 15:08:12 +00007195
Douglas Gregorb98b1992009-08-11 05:31:07 +00007196template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007197ExprResult
John McCall454feb92009-12-08 09:21:05 +00007198TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007199 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007200 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7201 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007202 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007203 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007204
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007205 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007206 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007207 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007208
Douglas Gregor036aed12009-12-23 23:03:06 +00007209 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007210}
Mike Stump1eb44332009-09-09 15:08:12 +00007211
Douglas Gregorb98b1992009-08-11 05:31:07 +00007212template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007213ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007214TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7215 CXXScalarValueInitExpr *E) {
7216 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7217 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007218 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007219
Douglas Gregorb98b1992009-08-11 05:31:07 +00007220 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007221 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007222 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007223
Chad Rosier4a9d7952012-08-08 18:46:20 +00007224 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007225 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007226 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007227}
Mike Stump1eb44332009-09-09 15:08:12 +00007228
Douglas Gregorb98b1992009-08-11 05:31:07 +00007229template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007230ExprResult
John McCall454feb92009-12-08 09:21:05 +00007231TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007232 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007233 TypeSourceInfo *AllocTypeInfo
7234 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7235 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007236 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007237
Douglas Gregorb98b1992009-08-11 05:31:07 +00007238 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007239 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007240 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007241 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007242
Douglas Gregorb98b1992009-08-11 05:31:07 +00007243 // Transform the placement arguments (if any).
7244 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007245 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007246 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007247 E->getNumPlacementArgs(), true,
7248 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007249 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007250
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007251 // Transform the initializer (if any).
7252 Expr *OldInit = E->getInitializer();
7253 ExprResult NewInit;
7254 if (OldInit)
7255 NewInit = getDerived().TransformExpr(OldInit);
7256 if (NewInit.isInvalid())
7257 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007258
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007259 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007260 FunctionDecl *OperatorNew = 0;
7261 if (E->getOperatorNew()) {
7262 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007263 getDerived().TransformDecl(E->getLocStart(),
7264 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007265 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007266 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007267 }
7268
7269 FunctionDecl *OperatorDelete = 0;
7270 if (E->getOperatorDelete()) {
7271 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007272 getDerived().TransformDecl(E->getLocStart(),
7273 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007274 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007275 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007276 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007277
Douglas Gregorb98b1992009-08-11 05:31:07 +00007278 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007279 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007280 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007281 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007282 OperatorNew == E->getOperatorNew() &&
7283 OperatorDelete == E->getOperatorDelete() &&
7284 !ArgumentChanged) {
7285 // Mark any declarations we need as referenced.
7286 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007287 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007288 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007289 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007290 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007291
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007292 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007293 QualType ElementType
7294 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7295 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7296 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7297 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007298 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007299 }
7300 }
7301 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007302
John McCall3fa5cae2010-10-26 07:05:15 +00007303 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007304 }
Mike Stump1eb44332009-09-09 15:08:12 +00007305
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007306 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007307 if (!ArraySize.get()) {
7308 // If no array size was specified, but the new expression was
7309 // instantiated with an array type (e.g., "new T" where T is
7310 // instantiated with "int[4]"), extract the outer bound from the
7311 // array type as our array size. We do this with constant and
7312 // dependently-sized array types.
7313 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7314 if (!ArrayT) {
7315 // Do nothing
7316 } else if (const ConstantArrayType *ConsArrayT
7317 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007318 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007319 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007320 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007321 SemaRef.Context.getSizeType(),
7322 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007323 AllocType = ConsArrayT->getElementType();
7324 } else if (const DependentSizedArrayType *DepArrayT
7325 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7326 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007327 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007328 AllocType = DepArrayT->getElementType();
7329 }
7330 }
7331 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007332
Douglas Gregorb98b1992009-08-11 05:31:07 +00007333 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7334 E->isGlobalNew(),
7335 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007336 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007337 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007338 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007339 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007340 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007341 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007342 E->getDirectInitRange(),
7343 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007344}
Mike Stump1eb44332009-09-09 15:08:12 +00007345
Douglas Gregorb98b1992009-08-11 05:31:07 +00007346template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007347ExprResult
John McCall454feb92009-12-08 09:21:05 +00007348TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007349 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007350 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007351 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007352
Douglas Gregor1af74512010-02-26 00:38:10 +00007353 // Transform the delete operator, if known.
7354 FunctionDecl *OperatorDelete = 0;
7355 if (E->getOperatorDelete()) {
7356 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007357 getDerived().TransformDecl(E->getLocStart(),
7358 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007359 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007360 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007361 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007362
Douglas Gregorb98b1992009-08-11 05:31:07 +00007363 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007364 Operand.get() == E->getArgument() &&
7365 OperatorDelete == E->getOperatorDelete()) {
7366 // Mark any declarations we need as referenced.
7367 // FIXME: instantiation-specific.
7368 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007369 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007370
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007371 if (!E->getArgument()->isTypeDependent()) {
7372 QualType Destroyed = SemaRef.Context.getBaseElementType(
7373 E->getDestroyedType());
7374 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7375 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007376 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007377 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007378 }
7379 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007380
John McCall3fa5cae2010-10-26 07:05:15 +00007381 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007382 }
Mike Stump1eb44332009-09-09 15:08:12 +00007383
Douglas Gregorb98b1992009-08-11 05:31:07 +00007384 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7385 E->isGlobalDelete(),
7386 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007387 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007388}
Mike Stump1eb44332009-09-09 15:08:12 +00007389
Douglas Gregorb98b1992009-08-11 05:31:07 +00007390template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007391ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007392TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007393 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007394 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007395 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007396 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007397
John McCallb3d87482010-08-24 05:47:05 +00007398 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007399 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007400 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007401 E->getOperatorLoc(),
7402 E->isArrow()? tok::arrow : tok::period,
7403 ObjectTypePtr,
7404 MayBePseudoDestructor);
7405 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007406 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007407
John McCallb3d87482010-08-24 05:47:05 +00007408 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007409 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7410 if (QualifierLoc) {
7411 QualifierLoc
7412 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7413 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007414 return ExprError();
7415 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007416 CXXScopeSpec SS;
7417 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007418
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007419 PseudoDestructorTypeStorage Destroyed;
7420 if (E->getDestroyedTypeInfo()) {
7421 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007422 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007423 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007424 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007425 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007426 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007427 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007428 // We aren't likely to be able to resolve the identifier down to a type
7429 // now anyway, so just retain the identifier.
7430 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7431 E->getDestroyedTypeLoc());
7432 } else {
7433 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007434 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007435 *E->getDestroyedTypeIdentifier(),
7436 E->getDestroyedTypeLoc(),
7437 /*Scope=*/0,
7438 SS, ObjectTypePtr,
7439 false);
7440 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007441 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007442
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007443 Destroyed
7444 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7445 E->getDestroyedTypeLoc());
7446 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007447
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007448 TypeSourceInfo *ScopeTypeInfo = 0;
7449 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007450 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007451 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007452 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007453 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007454
John McCall9ae2f072010-08-23 23:25:46 +00007455 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007456 E->getOperatorLoc(),
7457 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007458 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007459 ScopeTypeInfo,
7460 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007461 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007462 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007463}
Mike Stump1eb44332009-09-09 15:08:12 +00007464
Douglas Gregora71d8192009-09-04 17:36:40 +00007465template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007466ExprResult
John McCallba135432009-11-21 08:51:07 +00007467TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007468 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007469 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7470 Sema::LookupOrdinaryName);
7471
7472 // Transform all the decls.
7473 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7474 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007475 NamedDecl *InstD = static_cast<NamedDecl*>(
7476 getDerived().TransformDecl(Old->getNameLoc(),
7477 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007478 if (!InstD) {
7479 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7480 // This can happen because of dependent hiding.
7481 if (isa<UsingShadowDecl>(*I))
7482 continue;
7483 else
John McCallf312b1e2010-08-26 23:41:50 +00007484 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007485 }
John McCallf7a1a742009-11-24 19:00:30 +00007486
7487 // Expand using declarations.
7488 if (isa<UsingDecl>(InstD)) {
7489 UsingDecl *UD = cast<UsingDecl>(InstD);
7490 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7491 E = UD->shadow_end(); I != E; ++I)
7492 R.addDecl(*I);
7493 continue;
7494 }
7495
7496 R.addDecl(InstD);
7497 }
7498
7499 // Resolve a kind, but don't do any further analysis. If it's
7500 // ambiguous, the callee needs to deal with it.
7501 R.resolveKind();
7502
7503 // Rebuild the nested-name qualifier, if present.
7504 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007505 if (Old->getQualifierLoc()) {
7506 NestedNameSpecifierLoc QualifierLoc
7507 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7508 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007509 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007510
Douglas Gregor4c9be892011-02-28 20:01:57 +00007511 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007512 }
7513
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007514 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007515 CXXRecordDecl *NamingClass
7516 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7517 Old->getNameLoc(),
7518 Old->getNamingClass()));
7519 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007520 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007521
Douglas Gregor66c45152010-04-27 16:10:10 +00007522 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007523 }
7524
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007525 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7526
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007527 // If we have neither explicit template arguments, nor the template keyword,
7528 // it's a normal declaration name.
7529 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007530 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7531
7532 // If we have template arguments, rebuild them, then rebuild the
7533 // templateid expression.
7534 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007535 if (Old->hasExplicitTemplateArgs() &&
7536 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007537 Old->getNumTemplateArgs(),
7538 TransArgs))
7539 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007540
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007541 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007542 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007543}
Mike Stump1eb44332009-09-09 15:08:12 +00007544
Douglas Gregorb98b1992009-08-11 05:31:07 +00007545template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007546ExprResult
John McCall454feb92009-12-08 09:21:05 +00007547TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007548 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7549 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007550 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007551
Douglas Gregorb98b1992009-08-11 05:31:07 +00007552 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007553 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007554 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007555
Mike Stump1eb44332009-09-09 15:08:12 +00007556 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007557 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007558 T,
7559 E->getLocEnd());
7560}
Mike Stump1eb44332009-09-09 15:08:12 +00007561
Douglas Gregorb98b1992009-08-11 05:31:07 +00007562template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007563ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007564TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7565 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7566 if (!LhsT)
7567 return ExprError();
7568
7569 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7570 if (!RhsT)
7571 return ExprError();
7572
7573 if (!getDerived().AlwaysRebuild() &&
7574 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7575 return SemaRef.Owned(E);
7576
7577 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7578 E->getLocStart(),
7579 LhsT, RhsT,
7580 E->getLocEnd());
7581}
7582
7583template<typename Derived>
7584ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007585TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7586 bool ArgChanged = false;
7587 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7588 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7589 TypeSourceInfo *From = E->getArg(I);
7590 TypeLoc FromTL = From->getTypeLoc();
7591 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7592 TypeLocBuilder TLB;
7593 TLB.reserve(FromTL.getFullDataSize());
7594 QualType To = getDerived().TransformType(TLB, FromTL);
7595 if (To.isNull())
7596 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007597
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007598 if (To == From->getType())
7599 Args.push_back(From);
7600 else {
7601 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7602 ArgChanged = true;
7603 }
7604 continue;
7605 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007606
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007607 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007608
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007609 // We have a pack expansion. Instantiate it.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007610 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007611 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7612 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7613 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007614
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007615 // Determine whether the set of unexpanded parameter packs can and should
7616 // be expanded.
7617 bool Expand = true;
7618 bool RetainExpansion = false;
7619 llvm::Optional<unsigned> OrigNumExpansions
7620 = ExpansionTL.getTypePtr()->getNumExpansions();
7621 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7622 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7623 PatternTL.getSourceRange(),
7624 Unexpanded,
7625 Expand, RetainExpansion,
7626 NumExpansions))
7627 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007628
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007629 if (!Expand) {
7630 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007631 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007632 // expansion.
7633 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007634
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007635 TypeLocBuilder TLB;
7636 TLB.reserve(From->getTypeLoc().getFullDataSize());
7637
7638 QualType To = getDerived().TransformType(TLB, PatternTL);
7639 if (To.isNull())
7640 return ExprError();
7641
Chad Rosier4a9d7952012-08-08 18:46:20 +00007642 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007643 PatternTL.getSourceRange(),
7644 ExpansionTL.getEllipsisLoc(),
7645 NumExpansions);
7646 if (To.isNull())
7647 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007648
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007649 PackExpansionTypeLoc ToExpansionTL
7650 = TLB.push<PackExpansionTypeLoc>(To);
7651 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7652 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7653 continue;
7654 }
7655
7656 // Expand the pack expansion by substituting for each argument in the
7657 // pack(s).
7658 for (unsigned I = 0; I != *NumExpansions; ++I) {
7659 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7660 TypeLocBuilder TLB;
7661 TLB.reserve(PatternTL.getFullDataSize());
7662 QualType To = getDerived().TransformType(TLB, PatternTL);
7663 if (To.isNull())
7664 return ExprError();
7665
7666 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7667 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007668
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007669 if (!RetainExpansion)
7670 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007671
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007672 // If we're supposed to retain a pack expansion, do so by temporarily
7673 // forgetting the partially-substituted parameter pack.
7674 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7675
7676 TypeLocBuilder TLB;
7677 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007678
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007679 QualType To = getDerived().TransformType(TLB, PatternTL);
7680 if (To.isNull())
7681 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007682
7683 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007684 PatternTL.getSourceRange(),
7685 ExpansionTL.getEllipsisLoc(),
7686 NumExpansions);
7687 if (To.isNull())
7688 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007689
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007690 PackExpansionTypeLoc ToExpansionTL
7691 = TLB.push<PackExpansionTypeLoc>(To);
7692 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7693 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7694 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007695
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007696 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7697 return SemaRef.Owned(E);
7698
7699 return getDerived().RebuildTypeTrait(E->getTrait(),
7700 E->getLocStart(),
7701 Args,
7702 E->getLocEnd());
7703}
7704
7705template<typename Derived>
7706ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007707TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7708 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7709 if (!T)
7710 return ExprError();
7711
7712 if (!getDerived().AlwaysRebuild() &&
7713 T == E->getQueriedTypeSourceInfo())
7714 return SemaRef.Owned(E);
7715
7716 ExprResult SubExpr;
7717 {
7718 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7719 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7720 if (SubExpr.isInvalid())
7721 return ExprError();
7722
7723 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7724 return SemaRef.Owned(E);
7725 }
7726
7727 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7728 E->getLocStart(),
7729 T,
7730 SubExpr.get(),
7731 E->getLocEnd());
7732}
7733
7734template<typename Derived>
7735ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007736TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7737 ExprResult SubExpr;
7738 {
7739 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7740 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7741 if (SubExpr.isInvalid())
7742 return ExprError();
7743
7744 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7745 return SemaRef.Owned(E);
7746 }
7747
7748 return getDerived().RebuildExpressionTrait(
7749 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7750}
7751
7752template<typename Derived>
7753ExprResult
John McCall865d4472009-11-19 22:55:06 +00007754TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007755 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00007756 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
7757}
7758
7759template<typename Derived>
7760ExprResult
7761TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
7762 DependentScopeDeclRefExpr *E,
7763 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007764 NestedNameSpecifierLoc QualifierLoc
7765 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7766 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007767 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007768 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007769
John McCall43fed0d2010-11-12 08:19:04 +00007770 // TODO: If this is a conversion-function-id, verify that the
7771 // destination type name (if present) resolves the same way after
7772 // instantiation as it did in the local scope.
7773
Abramo Bagnara25777432010-08-11 22:01:17 +00007774 DeclarationNameInfo NameInfo
7775 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7776 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007777 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007778
John McCallf7a1a742009-11-24 19:00:30 +00007779 if (!E->hasExplicitTemplateArgs()) {
7780 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007781 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007782 // Note: it is sufficient to compare the Name component of NameInfo:
7783 // if name has not changed, DNLoc has not changed either.
7784 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007785 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007786
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007787 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007788 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007789 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007790 /*TemplateArgs*/ 0,
7791 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007792 }
John McCalld5532b62009-11-23 01:53:49 +00007793
7794 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007795 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7796 E->getNumTemplateArgs(),
7797 TransArgs))
7798 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007799
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007800 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007801 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007802 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007803 &TransArgs,
7804 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007805}
7806
7807template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007808ExprResult
John McCall454feb92009-12-08 09:21:05 +00007809TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00007810 // CXXConstructExprs other than for list-initialization and
7811 // CXXTemporaryObjectExpr are always implicit, so when we have
7812 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00007813 if ((E->getNumArgs() == 1 ||
7814 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00007815 (!getDerived().DropCallArgument(E->getArg(0))) &&
7816 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00007817 return getDerived().TransformExpr(E->getArg(0));
7818
Douglas Gregorb98b1992009-08-11 05:31:07 +00007819 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7820
7821 QualType T = getDerived().TransformType(E->getType());
7822 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007823 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007824
7825 CXXConstructorDecl *Constructor
7826 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007827 getDerived().TransformDecl(E->getLocStart(),
7828 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007829 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007830 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007831
Douglas Gregorb98b1992009-08-11 05:31:07 +00007832 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007833 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007834 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007835 &ArgumentChanged))
7836 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007837
Douglas Gregorb98b1992009-08-11 05:31:07 +00007838 if (!getDerived().AlwaysRebuild() &&
7839 T == E->getType() &&
7840 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007841 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007842 // Mark the constructor as referenced.
7843 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007844 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007845 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007846 }
Mike Stump1eb44332009-09-09 15:08:12 +00007847
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007848 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7849 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007850 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007851 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00007852 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007853 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007854 E->getConstructionKind(),
7855 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007856}
Mike Stump1eb44332009-09-09 15:08:12 +00007857
Douglas Gregorb98b1992009-08-11 05:31:07 +00007858/// \brief Transform a C++ temporary-binding expression.
7859///
Douglas Gregor51326552009-12-24 18:51:59 +00007860/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7861/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007862template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007863ExprResult
John McCall454feb92009-12-08 09:21:05 +00007864TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007865 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007866}
Mike Stump1eb44332009-09-09 15:08:12 +00007867
John McCall4765fa02010-12-06 08:20:24 +00007868/// \brief Transform a C++ expression that contains cleanups that should
7869/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007870///
John McCall4765fa02010-12-06 08:20:24 +00007871/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007872/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007873template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007874ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007875TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007876 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007877}
Mike Stump1eb44332009-09-09 15:08:12 +00007878
Douglas Gregorb98b1992009-08-11 05:31:07 +00007879template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007880ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007881TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007882 CXXTemporaryObjectExpr *E) {
7883 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7884 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007885 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007886
Douglas Gregorb98b1992009-08-11 05:31:07 +00007887 CXXConstructorDecl *Constructor
7888 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00007889 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007890 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007891 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007892 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007893
Douglas Gregorb98b1992009-08-11 05:31:07 +00007894 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007895 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007896 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007897 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007898 &ArgumentChanged))
7899 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007900
Douglas Gregorb98b1992009-08-11 05:31:07 +00007901 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007902 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007903 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007904 !ArgumentChanged) {
7905 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007906 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007907 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007908 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007909
Richard Smithc83c2302012-12-19 01:39:02 +00007910 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00007911 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7912 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007913 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007914 E->getLocEnd());
7915}
Mike Stump1eb44332009-09-09 15:08:12 +00007916
Douglas Gregorb98b1992009-08-11 05:31:07 +00007917template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007918ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007919TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007920 // Transform the type of the lambda parameters and start the definition of
7921 // the lambda itself.
7922 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00007923 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00007924 if (!MethodTy)
7925 return ExprError();
7926
Eli Friedman8da8a662012-09-19 01:18:11 +00007927 // Create the local class that will describe the lambda.
7928 CXXRecordDecl *Class
7929 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7930 MethodTy,
7931 /*KnownDependent=*/false);
7932 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7933
Douglas Gregorc6889e72012-02-14 22:28:59 +00007934 // Transform lambda parameters.
Douglas Gregorc6889e72012-02-14 22:28:59 +00007935 llvm::SmallVector<QualType, 4> ParamTypes;
7936 llvm::SmallVector<ParmVarDecl *, 4> Params;
7937 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7938 E->getCallOperator()->param_begin(),
7939 E->getCallOperator()->param_size(),
7940 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00007941 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00007942
Douglas Gregordfca6f52012-02-13 22:00:16 +00007943 // Build the call operator.
7944 CXXMethodDecl *CallOperator
7945 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007946 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007947 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007948 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007949 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00007950
Richard Smith612409e2012-07-25 03:56:55 +00007951 return getDerived().TransformLambdaScope(E, CallOperator);
7952}
7953
7954template<typename Derived>
7955ExprResult
7956TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
7957 CXXMethodDecl *CallOperator) {
Douglas Gregord5387e82012-02-14 00:00:48 +00007958 // Introduce the context of the call operator.
7959 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7960
Douglas Gregordfca6f52012-02-13 22:00:16 +00007961 // Enter the scope of the lambda.
7962 sema::LambdaScopeInfo *LSI
7963 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7964 E->getCaptureDefault(),
7965 E->hasExplicitParameters(),
7966 E->hasExplicitResultType(),
7967 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007968
Douglas Gregordfca6f52012-02-13 22:00:16 +00007969 // Transform captures.
Richard Smith612409e2012-07-25 03:56:55 +00007970 bool Invalid = false;
Douglas Gregordfca6f52012-02-13 22:00:16 +00007971 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007972 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007973 CEnd = E->capture_end();
7974 C != CEnd; ++C) {
7975 // When we hit the first implicit capture, tell Sema that we've finished
7976 // the list of explicit captures.
7977 if (!FinishedExplicitCaptures && C->isImplicit()) {
7978 getSema().finishLambdaExplicitCaptures(LSI);
7979 FinishedExplicitCaptures = true;
7980 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007981
Douglas Gregordfca6f52012-02-13 22:00:16 +00007982 // Capturing 'this' is trivial.
7983 if (C->capturesThis()) {
7984 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7985 continue;
7986 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007987
Douglas Gregora7365242012-02-14 19:27:52 +00007988 // Determine the capture kind for Sema.
7989 Sema::TryCaptureKind Kind
7990 = C->isImplicit()? Sema::TryCapture_Implicit
7991 : C->getCaptureKind() == LCK_ByCopy
7992 ? Sema::TryCapture_ExplicitByVal
7993 : Sema::TryCapture_ExplicitByRef;
7994 SourceLocation EllipsisLoc;
7995 if (C->isPackExpansion()) {
7996 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7997 bool ShouldExpand = false;
7998 bool RetainExpansion = false;
7999 llvm::Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008000 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8001 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008002 Unexpanded,
8003 ShouldExpand, RetainExpansion,
8004 NumExpansions))
8005 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008006
Douglas Gregora7365242012-02-14 19:27:52 +00008007 if (ShouldExpand) {
8008 // The transform has determined that we should perform an expansion;
8009 // transform and capture each of the arguments.
8010 // expansion of the pattern. Do so.
8011 VarDecl *Pack = C->getCapturedVar();
8012 for (unsigned I = 0; I != *NumExpansions; ++I) {
8013 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8014 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008015 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008016 Pack));
8017 if (!CapturedVar) {
8018 Invalid = true;
8019 continue;
8020 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008021
Douglas Gregora7365242012-02-14 19:27:52 +00008022 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008023 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8024 }
Douglas Gregora7365242012-02-14 19:27:52 +00008025 continue;
8026 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008027
Douglas Gregora7365242012-02-14 19:27:52 +00008028 EllipsisLoc = C->getEllipsisLoc();
8029 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008030
Douglas Gregordfca6f52012-02-13 22:00:16 +00008031 // Transform the captured variable.
8032 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008033 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008034 C->getCapturedVar()));
8035 if (!CapturedVar) {
8036 Invalid = true;
8037 continue;
8038 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008039
Douglas Gregordfca6f52012-02-13 22:00:16 +00008040 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008041 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008042 }
8043 if (!FinishedExplicitCaptures)
8044 getSema().finishLambdaExplicitCaptures(LSI);
8045
Douglas Gregordfca6f52012-02-13 22:00:16 +00008046
8047 // Enter a new evaluation context to insulate the lambda from any
8048 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008049 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008050
8051 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008052 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008053 /*IsInstantiation=*/true);
8054 return ExprError();
8055 }
8056
8057 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008058 StmtResult Body = getDerived().TransformStmt(E->getBody());
8059 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008060 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008061 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008062 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008063 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008064
Chad Rosier4a9d7952012-08-08 18:46:20 +00008065 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008066 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008067}
8068
8069template<typename Derived>
8070ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008071TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008072 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008073 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8074 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008075 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008076
Douglas Gregorb98b1992009-08-11 05:31:07 +00008077 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008078 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008079 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008080 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008081 &ArgumentChanged))
8082 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008083
Douglas Gregorb98b1992009-08-11 05:31:07 +00008084 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008085 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008086 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008087 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008088
Douglas Gregorb98b1992009-08-11 05:31:07 +00008089 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008090 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008091 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008092 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008093 E->getRParenLoc());
8094}
Mike Stump1eb44332009-09-09 15:08:12 +00008095
Douglas Gregorb98b1992009-08-11 05:31:07 +00008096template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008097ExprResult
John McCall865d4472009-11-19 22:55:06 +00008098TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008099 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008100 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008101 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008102 Expr *OldBase;
8103 QualType BaseType;
8104 QualType ObjectType;
8105 if (!E->isImplicitAccess()) {
8106 OldBase = E->getBase();
8107 Base = getDerived().TransformExpr(OldBase);
8108 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008109 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008110
John McCallaa81e162009-12-01 22:10:20 +00008111 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008112 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008113 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008114 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008115 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008116 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008117 ObjectTy,
8118 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008119 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008120 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008121
John McCallb3d87482010-08-24 05:47:05 +00008122 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008123 BaseType = ((Expr*) Base.get())->getType();
8124 } else {
8125 OldBase = 0;
8126 BaseType = getDerived().TransformType(E->getBaseType());
8127 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8128 }
Mike Stump1eb44332009-09-09 15:08:12 +00008129
Douglas Gregor6cd21982009-10-20 05:58:46 +00008130 // Transform the first part of the nested-name-specifier that qualifies
8131 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008132 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008133 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008134 E->getFirstQualifierFoundInScope(),
8135 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008136
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008137 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008138 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008139 QualifierLoc
8140 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8141 ObjectType,
8142 FirstQualifierInScope);
8143 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008144 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008145 }
Mike Stump1eb44332009-09-09 15:08:12 +00008146
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008147 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8148
John McCall43fed0d2010-11-12 08:19:04 +00008149 // TODO: If this is a conversion-function-id, verify that the
8150 // destination type name (if present) resolves the same way after
8151 // instantiation as it did in the local scope.
8152
Abramo Bagnara25777432010-08-11 22:01:17 +00008153 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008154 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008155 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008156 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008157
John McCallaa81e162009-12-01 22:10:20 +00008158 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008159 // This is a reference to a member without an explicitly-specified
8160 // template argument list. Optimize for this common case.
8161 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008162 Base.get() == OldBase &&
8163 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008164 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008165 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008166 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008167 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008168
John McCall9ae2f072010-08-23 23:25:46 +00008169 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008170 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008171 E->isArrow(),
8172 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008173 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008174 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008175 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008176 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008177 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008178 }
8179
John McCalld5532b62009-11-23 01:53:49 +00008180 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008181 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8182 E->getNumTemplateArgs(),
8183 TransArgs))
8184 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008185
John McCall9ae2f072010-08-23 23:25:46 +00008186 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008187 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008188 E->isArrow(),
8189 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008190 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008191 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008192 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008193 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008194 &TransArgs);
8195}
8196
8197template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008198ExprResult
John McCall454feb92009-12-08 09:21:05 +00008199TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008200 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008201 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008202 QualType BaseType;
8203 if (!Old->isImplicitAccess()) {
8204 Base = getDerived().TransformExpr(Old->getBase());
8205 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008206 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008207 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8208 Old->isArrow());
8209 if (Base.isInvalid())
8210 return ExprError();
8211 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008212 } else {
8213 BaseType = getDerived().TransformType(Old->getBaseType());
8214 }
John McCall129e2df2009-11-30 22:42:35 +00008215
Douglas Gregor4c9be892011-02-28 20:01:57 +00008216 NestedNameSpecifierLoc QualifierLoc;
8217 if (Old->getQualifierLoc()) {
8218 QualifierLoc
8219 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8220 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008221 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008222 }
8223
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008224 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8225
Abramo Bagnara25777432010-08-11 22:01:17 +00008226 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008227 Sema::LookupOrdinaryName);
8228
8229 // Transform all the decls.
8230 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8231 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008232 NamedDecl *InstD = static_cast<NamedDecl*>(
8233 getDerived().TransformDecl(Old->getMemberLoc(),
8234 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008235 if (!InstD) {
8236 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8237 // This can happen because of dependent hiding.
8238 if (isa<UsingShadowDecl>(*I))
8239 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008240 else {
8241 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008242 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008243 }
John McCall9f54ad42009-12-10 09:41:52 +00008244 }
John McCall129e2df2009-11-30 22:42:35 +00008245
8246 // Expand using declarations.
8247 if (isa<UsingDecl>(InstD)) {
8248 UsingDecl *UD = cast<UsingDecl>(InstD);
8249 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8250 E = UD->shadow_end(); I != E; ++I)
8251 R.addDecl(*I);
8252 continue;
8253 }
8254
8255 R.addDecl(InstD);
8256 }
8257
8258 R.resolveKind();
8259
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008260 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008261 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008262 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008263 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008264 Old->getMemberLoc(),
8265 Old->getNamingClass()));
8266 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008267 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008268
Douglas Gregor66c45152010-04-27 16:10:10 +00008269 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008270 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008271
John McCall129e2df2009-11-30 22:42:35 +00008272 TemplateArgumentListInfo TransArgs;
8273 if (Old->hasExplicitTemplateArgs()) {
8274 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8275 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008276 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8277 Old->getNumTemplateArgs(),
8278 TransArgs))
8279 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008280 }
John McCallc2233c52010-01-15 08:34:02 +00008281
8282 // FIXME: to do this check properly, we will need to preserve the
8283 // first-qualifier-in-scope here, just in case we had a dependent
8284 // base (and therefore couldn't do the check) and a
8285 // nested-name-qualifier (and therefore could do the lookup).
8286 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008287
John McCall9ae2f072010-08-23 23:25:46 +00008288 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008289 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008290 Old->getOperatorLoc(),
8291 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008292 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008293 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008294 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008295 R,
8296 (Old->hasExplicitTemplateArgs()
8297 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008298}
8299
8300template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008301ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008302TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008303 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008304 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8305 if (SubExpr.isInvalid())
8306 return ExprError();
8307
8308 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008309 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008310
8311 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8312}
8313
8314template<typename Derived>
8315ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008316TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008317 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8318 if (Pattern.isInvalid())
8319 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008320
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008321 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8322 return SemaRef.Owned(E);
8323
Douglas Gregor67fd1252011-01-14 21:20:45 +00008324 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8325 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008326}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008327
8328template<typename Derived>
8329ExprResult
8330TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8331 // If E is not value-dependent, then nothing will change when we transform it.
8332 // Note: This is an instantiation-centric view.
8333 if (!E->isValueDependent())
8334 return SemaRef.Owned(E);
8335
8336 // Note: None of the implementations of TryExpandParameterPacks can ever
8337 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008338 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008339 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8340 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008341 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008342 llvm::Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008343 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008344 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008345 ShouldExpand, RetainExpansion,
8346 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008347 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008348
Douglas Gregor089e8932011-10-10 18:59:29 +00008349 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008350 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008351
Douglas Gregor089e8932011-10-10 18:59:29 +00008352 NamedDecl *Pack = E->getPack();
8353 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008354 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008355 Pack));
8356 if (!Pack)
8357 return ExprError();
8358 }
8359
Chad Rosier4a9d7952012-08-08 18:46:20 +00008360
Douglas Gregoree8aff02011-01-04 17:33:58 +00008361 // We now know the length of the parameter pack, so build a new expression
8362 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008363 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8364 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008365 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008366}
8367
Douglas Gregorbe230c32011-01-03 17:17:50 +00008368template<typename Derived>
8369ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008370TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8371 SubstNonTypeTemplateParmPackExpr *E) {
8372 // Default behavior is to do nothing with this transformation.
8373 return SemaRef.Owned(E);
8374}
8375
8376template<typename Derived>
8377ExprResult
John McCall91a57552011-07-15 05:09:51 +00008378TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8379 SubstNonTypeTemplateParmExpr *E) {
8380 // Default behavior is to do nothing with this transformation.
8381 return SemaRef.Owned(E);
8382}
8383
8384template<typename Derived>
8385ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008386TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8387 // Default behavior is to do nothing with this transformation.
8388 return SemaRef.Owned(E);
8389}
8390
8391template<typename Derived>
8392ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008393TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8394 MaterializeTemporaryExpr *E) {
8395 return getDerived().TransformExpr(E->GetTemporaryExpr());
8396}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008397
Douglas Gregor03e80032011-06-21 17:03:29 +00008398template<typename Derived>
8399ExprResult
John McCall454feb92009-12-08 09:21:05 +00008400TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008401 return SemaRef.MaybeBindToTemporary(E);
8402}
8403
8404template<typename Derived>
8405ExprResult
8406TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008407 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008408}
8409
8410template<typename Derived>
8411ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008412TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8413 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8414 if (SubExpr.isInvalid())
8415 return ExprError();
8416
8417 if (!getDerived().AlwaysRebuild() &&
8418 SubExpr.get() == E->getSubExpr())
8419 return SemaRef.Owned(E);
8420
8421 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008422}
8423
8424template<typename Derived>
8425ExprResult
8426TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8427 // Transform each of the elements.
8428 llvm::SmallVector<Expr *, 8> Elements;
8429 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008430 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008431 /*IsCall=*/false, Elements, &ArgChanged))
8432 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008433
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008434 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8435 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008436
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008437 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8438 Elements.data(),
8439 Elements.size());
8440}
8441
8442template<typename Derived>
8443ExprResult
8444TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008445 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008446 // Transform each of the elements.
8447 llvm::SmallVector<ObjCDictionaryElement, 8> Elements;
8448 bool ArgChanged = false;
8449 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8450 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008451
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008452 if (OrigElement.isPackExpansion()) {
8453 // This key/value element is a pack expansion.
8454 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8455 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8456 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8457 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8458
8459 // Determine whether the set of unexpanded parameter packs can
8460 // and should be expanded.
8461 bool Expand = true;
8462 bool RetainExpansion = false;
8463 llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8464 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
8465 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8466 OrigElement.Value->getLocEnd());
8467 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8468 PatternRange,
8469 Unexpanded,
8470 Expand, RetainExpansion,
8471 NumExpansions))
8472 return ExprError();
8473
8474 if (!Expand) {
8475 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008476 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008477 // expansion.
8478 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8479 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8480 if (Key.isInvalid())
8481 return ExprError();
8482
8483 if (Key.get() != OrigElement.Key)
8484 ArgChanged = true;
8485
8486 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8487 if (Value.isInvalid())
8488 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008489
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008490 if (Value.get() != OrigElement.Value)
8491 ArgChanged = true;
8492
Chad Rosier4a9d7952012-08-08 18:46:20 +00008493 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008494 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8495 };
8496 Elements.push_back(Expansion);
8497 continue;
8498 }
8499
8500 // Record right away that the argument was changed. This needs
8501 // to happen even if the array expands to nothing.
8502 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008503
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008504 // The transform has determined that we should perform an elementwise
8505 // expansion of the pattern. Do so.
8506 for (unsigned I = 0; I != *NumExpansions; ++I) {
8507 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8508 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8509 if (Key.isInvalid())
8510 return ExprError();
8511
8512 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8513 if (Value.isInvalid())
8514 return ExprError();
8515
Chad Rosier4a9d7952012-08-08 18:46:20 +00008516 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008517 Key.get(), Value.get(), SourceLocation(), NumExpansions
8518 };
8519
8520 // If any unexpanded parameter packs remain, we still have a
8521 // pack expansion.
8522 if (Key.get()->containsUnexpandedParameterPack() ||
8523 Value.get()->containsUnexpandedParameterPack())
8524 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008525
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008526 Elements.push_back(Element);
8527 }
8528
8529 // We've finished with this pack expansion.
8530 continue;
8531 }
8532
8533 // Transform and check key.
8534 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8535 if (Key.isInvalid())
8536 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008537
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008538 if (Key.get() != OrigElement.Key)
8539 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008540
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008541 // Transform and check value.
8542 ExprResult Value
8543 = getDerived().TransformExpr(OrigElement.Value);
8544 if (Value.isInvalid())
8545 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008546
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008547 if (Value.get() != OrigElement.Value)
8548 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008549
8550 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008551 Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8552 };
8553 Elements.push_back(Element);
8554 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008555
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008556 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8557 return SemaRef.MaybeBindToTemporary(E);
8558
8559 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8560 Elements.data(),
8561 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008562}
8563
Mike Stump1eb44332009-09-09 15:08:12 +00008564template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008565ExprResult
John McCall454feb92009-12-08 09:21:05 +00008566TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008567 TypeSourceInfo *EncodedTypeInfo
8568 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8569 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008570 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008571
Douglas Gregorb98b1992009-08-11 05:31:07 +00008572 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008573 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008574 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008575
8576 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008577 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008578 E->getRParenLoc());
8579}
Mike Stump1eb44332009-09-09 15:08:12 +00008580
Douglas Gregorb98b1992009-08-11 05:31:07 +00008581template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008582ExprResult TreeTransform<Derived>::
8583TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8584 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8585 if (result.isInvalid()) return ExprError();
8586 Expr *subExpr = result.take();
8587
8588 if (!getDerived().AlwaysRebuild() &&
8589 subExpr == E->getSubExpr())
8590 return SemaRef.Owned(E);
8591
8592 return SemaRef.Owned(new(SemaRef.Context)
8593 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8594}
8595
8596template<typename Derived>
8597ExprResult TreeTransform<Derived>::
8598TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008599 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008600 = getDerived().TransformType(E->getTypeInfoAsWritten());
8601 if (!TSInfo)
8602 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008603
John McCallf85e1932011-06-15 23:02:42 +00008604 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008605 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008606 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008607
John McCallf85e1932011-06-15 23:02:42 +00008608 if (!getDerived().AlwaysRebuild() &&
8609 TSInfo == E->getTypeInfoAsWritten() &&
8610 Result.get() == E->getSubExpr())
8611 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008612
John McCallf85e1932011-06-15 23:02:42 +00008613 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008614 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008615 Result.get());
8616}
8617
8618template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008619ExprResult
John McCall454feb92009-12-08 09:21:05 +00008620TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008621 // Transform arguments.
8622 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008623 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008624 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008625 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008626 &ArgChanged))
8627 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008628
Douglas Gregor92e986e2010-04-22 16:44:27 +00008629 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8630 // Class message: transform the receiver type.
8631 TypeSourceInfo *ReceiverTypeInfo
8632 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8633 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008634 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008635
Douglas Gregor92e986e2010-04-22 16:44:27 +00008636 // If nothing changed, just retain the existing message send.
8637 if (!getDerived().AlwaysRebuild() &&
8638 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008639 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008640
8641 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008642 SmallVector<SourceLocation, 16> SelLocs;
8643 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008644 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8645 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008646 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008647 E->getMethodDecl(),
8648 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008649 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008650 E->getRightLoc());
8651 }
8652
8653 // Instance message: transform the receiver
8654 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8655 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008656 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008657 = getDerived().TransformExpr(E->getInstanceReceiver());
8658 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008659 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008660
8661 // If nothing changed, just retain the existing message send.
8662 if (!getDerived().AlwaysRebuild() &&
8663 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008664 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008665
Douglas Gregor92e986e2010-04-22 16:44:27 +00008666 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008667 SmallVector<SourceLocation, 16> SelLocs;
8668 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008669 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008670 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008671 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008672 E->getMethodDecl(),
8673 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008674 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008675 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008676}
8677
Mike Stump1eb44332009-09-09 15:08:12 +00008678template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008679ExprResult
John McCall454feb92009-12-08 09:21:05 +00008680TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008681 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008682}
8683
Mike Stump1eb44332009-09-09 15:08:12 +00008684template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008685ExprResult
John McCall454feb92009-12-08 09:21:05 +00008686TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008687 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008688}
8689
Mike Stump1eb44332009-09-09 15:08:12 +00008690template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008691ExprResult
John McCall454feb92009-12-08 09:21:05 +00008692TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008693 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008694 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008695 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008696 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008697
8698 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008699
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008700 // If nothing changed, just retain the existing expression.
8701 if (!getDerived().AlwaysRebuild() &&
8702 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008703 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008704
John McCall9ae2f072010-08-23 23:25:46 +00008705 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008706 E->getLocation(),
8707 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008708}
8709
Mike Stump1eb44332009-09-09 15:08:12 +00008710template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008711ExprResult
John McCall454feb92009-12-08 09:21:05 +00008712TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008713 // 'super' and types never change. Property never changes. Just
8714 // retain the existing expression.
8715 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008716 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008717
Douglas Gregore3303542010-04-26 20:47:02 +00008718 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008719 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008720 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008721 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008722
Douglas Gregore3303542010-04-26 20:47:02 +00008723 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008724
Douglas Gregore3303542010-04-26 20:47:02 +00008725 // If nothing changed, just retain the existing expression.
8726 if (!getDerived().AlwaysRebuild() &&
8727 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008728 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008729
John McCall12f78a62010-12-02 01:19:52 +00008730 if (E->isExplicitProperty())
8731 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8732 E->getExplicitProperty(),
8733 E->getLocation());
8734
8735 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008736 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008737 E->getImplicitPropertyGetter(),
8738 E->getImplicitPropertySetter(),
8739 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008740}
8741
Mike Stump1eb44332009-09-09 15:08:12 +00008742template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008743ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008744TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8745 // Transform the base expression.
8746 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8747 if (Base.isInvalid())
8748 return ExprError();
8749
8750 // Transform the key expression.
8751 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8752 if (Key.isInvalid())
8753 return ExprError();
8754
8755 // If nothing changed, just retain the existing expression.
8756 if (!getDerived().AlwaysRebuild() &&
8757 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8758 return SemaRef.Owned(E);
8759
Chad Rosier4a9d7952012-08-08 18:46:20 +00008760 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008761 Base.get(), Key.get(),
8762 E->getAtIndexMethodDecl(),
8763 E->setAtIndexMethodDecl());
8764}
8765
8766template<typename Derived>
8767ExprResult
John McCall454feb92009-12-08 09:21:05 +00008768TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008769 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008770 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008771 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008772 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008773
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008774 // If nothing changed, just retain the existing expression.
8775 if (!getDerived().AlwaysRebuild() &&
8776 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008777 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008778
John McCall9ae2f072010-08-23 23:25:46 +00008779 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008780 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008781}
8782
Mike Stump1eb44332009-09-09 15:08:12 +00008783template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008784ExprResult
John McCall454feb92009-12-08 09:21:05 +00008785TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008786 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008787 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008788 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008789 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008790 SubExprs, &ArgumentChanged))
8791 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008792
Douglas Gregorb98b1992009-08-11 05:31:07 +00008793 if (!getDerived().AlwaysRebuild() &&
8794 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008795 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008796
Douglas Gregorb98b1992009-08-11 05:31:07 +00008797 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008798 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008799 E->getRParenLoc());
8800}
8801
Mike Stump1eb44332009-09-09 15:08:12 +00008802template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008803ExprResult
John McCall454feb92009-12-08 09:21:05 +00008804TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008805 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008806
John McCallc6ac9c32011-02-04 18:33:18 +00008807 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8808 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8809
8810 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008811 blockScope->TheDecl->setBlockMissingReturnType(
8812 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008813
Chris Lattner686775d2011-07-20 06:58:45 +00008814 SmallVector<ParmVarDecl*, 4> params;
8815 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008816
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008817 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008818 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8819 oldBlock->param_begin(),
8820 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008821 0, paramTypes, &params)) {
8822 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008823 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008824 }
John McCallc6ac9c32011-02-04 18:33:18 +00008825
8826 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008827 QualType exprResultType =
8828 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008829
8830 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008831 if (exprResultType->isObjCObjectType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008832 getSema().Diag(E->getCaretLocation(),
8833 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008834 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008835 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008836 return ExprError();
8837 }
John McCall711c52b2011-01-05 12:14:39 +00008838
John McCallc6ac9c32011-02-04 18:33:18 +00008839 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008840 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008841 paramTypes.data(),
8842 paramTypes.size(),
8843 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008844 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008845 exprFunctionType->getExtInfo());
8846 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008847
8848 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008849 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008850 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008851
8852 if (!oldBlock->blockMissingReturnType()) {
8853 blockScope->HasImplicitReturnType = false;
8854 blockScope->ReturnType = exprResultType;
8855 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008856
John McCall711c52b2011-01-05 12:14:39 +00008857 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008858 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008859 if (body.isInvalid()) {
8860 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008861 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008862 }
John McCall711c52b2011-01-05 12:14:39 +00008863
John McCallc6ac9c32011-02-04 18:33:18 +00008864#ifndef NDEBUG
8865 // In builds with assertions, make sure that we captured everything we
8866 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008867 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8868 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8869 e = oldBlock->capture_end(); i != e; ++i) {
8870 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008871
Douglas Gregorfc921372011-05-20 15:32:55 +00008872 // Ignore parameter packs.
8873 if (isa<ParmVarDecl>(oldCapture) &&
8874 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8875 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008876
Douglas Gregorfc921372011-05-20 15:32:55 +00008877 VarDecl *newCapture =
8878 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8879 oldCapture));
8880 assert(blockScope->CaptureMap.count(newCapture));
8881 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008882 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008883 }
8884#endif
8885
8886 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8887 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008888}
8889
Mike Stump1eb44332009-09-09 15:08:12 +00008890template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008891ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008892TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008893 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008894}
Eli Friedman276b0612011-10-11 02:20:01 +00008895
8896template<typename Derived>
8897ExprResult
8898TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008899 QualType RetTy = getDerived().TransformType(E->getType());
8900 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008901 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008902 SubExprs.reserve(E->getNumSubExprs());
8903 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8904 SubExprs, &ArgumentChanged))
8905 return ExprError();
8906
8907 if (!getDerived().AlwaysRebuild() &&
8908 !ArgumentChanged)
8909 return SemaRef.Owned(E);
8910
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008911 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008912 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008913}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008914
Douglas Gregorb98b1992009-08-11 05:31:07 +00008915//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008916// Type reconstruction
8917//===----------------------------------------------------------------------===//
8918
Mike Stump1eb44332009-09-09 15:08:12 +00008919template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008920QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8921 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008922 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008923 getDerived().getBaseEntity());
8924}
8925
Mike Stump1eb44332009-09-09 15:08:12 +00008926template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008927QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8928 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008929 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008930 getDerived().getBaseEntity());
8931}
8932
Mike Stump1eb44332009-09-09 15:08:12 +00008933template<typename Derived>
8934QualType
John McCall85737a72009-10-30 00:06:24 +00008935TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8936 bool WrittenAsLValue,
8937 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008938 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008939 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008940}
8941
8942template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008943QualType
John McCall85737a72009-10-30 00:06:24 +00008944TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8945 QualType ClassType,
8946 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008947 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008948 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008949}
8950
8951template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008952QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008953TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8954 ArrayType::ArraySizeModifier SizeMod,
8955 const llvm::APInt *Size,
8956 Expr *SizeExpr,
8957 unsigned IndexTypeQuals,
8958 SourceRange BracketsRange) {
8959 if (SizeExpr || !Size)
8960 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8961 IndexTypeQuals, BracketsRange,
8962 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008963
8964 QualType Types[] = {
8965 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8966 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8967 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008968 };
8969 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8970 QualType SizeType;
8971 for (unsigned I = 0; I != NumTypes; ++I)
8972 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8973 SizeType = Types[I];
8974 break;
8975 }
Mike Stump1eb44332009-09-09 15:08:12 +00008976
Eli Friedman01f276d2012-01-25 23:20:27 +00008977 // Note that we can return a VariableArrayType here in the case where
8978 // the element type was a dependent VariableArrayType.
8979 IntegerLiteral *ArraySize
8980 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8981 /*FIXME*/BracketsRange.getBegin());
8982 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008983 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008984 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008985}
Mike Stump1eb44332009-09-09 15:08:12 +00008986
Douglas Gregor577f75a2009-08-04 16:50:30 +00008987template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008988QualType
8989TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008990 ArrayType::ArraySizeModifier SizeMod,
8991 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008992 unsigned IndexTypeQuals,
8993 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008994 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008995 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008996}
8997
8998template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008999QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009000TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009001 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009002 unsigned IndexTypeQuals,
9003 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009004 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009005 IndexTypeQuals, BracketsRange);
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>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009011 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009012 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009013 unsigned IndexTypeQuals,
9014 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009015 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009016 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009017 IndexTypeQuals, BracketsRange);
9018}
9019
9020template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009021QualType
9022TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009023 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009024 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009025 unsigned IndexTypeQuals,
9026 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009027 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009028 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009029 IndexTypeQuals, BracketsRange);
9030}
9031
9032template<typename Derived>
9033QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009034 unsigned NumElements,
9035 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009036 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009037 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009038}
Mike Stump1eb44332009-09-09 15:08:12 +00009039
Douglas Gregor577f75a2009-08-04 16:50:30 +00009040template<typename Derived>
9041QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9042 unsigned NumElements,
9043 SourceLocation AttributeLoc) {
9044 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9045 NumElements, true);
9046 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009047 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9048 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009049 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009050}
Mike Stump1eb44332009-09-09 15:08:12 +00009051
Douglas Gregor577f75a2009-08-04 16:50:30 +00009052template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009053QualType
9054TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009055 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009056 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009057 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009058}
Mike Stump1eb44332009-09-09 15:08:12 +00009059
Douglas Gregor577f75a2009-08-04 16:50:30 +00009060template<typename Derived>
9061QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00009062 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009063 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00009064 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009065 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00009066 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00009067 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00009068 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00009069 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009070 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009071 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009072 getDerived().getBaseEntity(),
9073 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009074}
Mike Stump1eb44332009-09-09 15:08:12 +00009075
Douglas Gregor577f75a2009-08-04 16:50:30 +00009076template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009077QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9078 return SemaRef.Context.getFunctionNoProtoType(T);
9079}
9080
9081template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009082QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9083 assert(D && "no decl found");
9084 if (D->isInvalidDecl()) return QualType();
9085
Douglas Gregor92e986e2010-04-22 16:44:27 +00009086 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009087 TypeDecl *Ty;
9088 if (isa<UsingDecl>(D)) {
9089 UsingDecl *Using = cast<UsingDecl>(D);
9090 assert(Using->isTypeName() &&
9091 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9092
9093 // A valid resolved using typename decl points to exactly one type decl.
9094 assert(++Using->shadow_begin() == Using->shadow_end());
9095 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009096
John McCalled976492009-12-04 22:46:56 +00009097 } else {
9098 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9099 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9100 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9101 }
9102
9103 return SemaRef.Context.getTypeDeclType(Ty);
9104}
9105
9106template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009107QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9108 SourceLocation Loc) {
9109 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009110}
9111
9112template<typename Derived>
9113QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9114 return SemaRef.Context.getTypeOfType(Underlying);
9115}
9116
9117template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009118QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9119 SourceLocation Loc) {
9120 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009121}
9122
9123template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009124QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9125 UnaryTransformType::UTTKind UKind,
9126 SourceLocation Loc) {
9127 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9128}
9129
9130template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009131QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009132 TemplateName Template,
9133 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009134 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009135 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009136}
Mike Stump1eb44332009-09-09 15:08:12 +00009137
Douglas Gregordcee1a12009-08-06 05:28:30 +00009138template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009139QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9140 SourceLocation KWLoc) {
9141 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9142}
9143
9144template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009145TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009146TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009147 bool TemplateKW,
9148 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009149 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009150 Template);
9151}
9152
9153template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009154TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009155TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9156 const IdentifierInfo &Name,
9157 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009158 QualType ObjectType,
9159 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009160 UnqualifiedId TemplateName;
9161 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009162 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009163 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009164 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009165 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009166 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009167 /*EnteringContext=*/false,
9168 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009169 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009170}
Mike Stump1eb44332009-09-09 15:08:12 +00009171
Douglas Gregorb98b1992009-08-11 05:31:07 +00009172template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009173TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009174TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009175 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009176 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009177 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009178 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009179 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009180 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009181 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009182 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009183 Sema::TemplateTy Template;
9184 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009185 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009186 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009187 /*EnteringContext=*/false,
9188 Template);
9189 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009190}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009191
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009192template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009193ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009194TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9195 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009196 Expr *OrigCallee,
9197 Expr *First,
9198 Expr *Second) {
9199 Expr *Callee = OrigCallee->IgnoreParenCasts();
9200 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009201
Douglas Gregorb98b1992009-08-11 05:31:07 +00009202 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009203 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009204 if (!First->getType()->isOverloadableType() &&
9205 !Second->getType()->isOverloadableType())
9206 return getSema().CreateBuiltinArraySubscriptExpr(First,
9207 Callee->getLocStart(),
9208 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009209 } else if (Op == OO_Arrow) {
9210 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009211 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9212 } else if (Second == 0 || isPostIncDec) {
9213 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009214 // The argument is not of overloadable type, so try to create a
9215 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009216 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009217 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009218
John McCall9ae2f072010-08-23 23:25:46 +00009219 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009220 }
9221 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009222 if (!First->getType()->isOverloadableType() &&
9223 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009224 // Neither of the arguments is an overloadable type, so try to
9225 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009226 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009227 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009228 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009229 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009230 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009231
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009232 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009233 }
9234 }
Mike Stump1eb44332009-09-09 15:08:12 +00009235
9236 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009237 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009238 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009239
John McCall9ae2f072010-08-23 23:25:46 +00009240 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009241 assert(ULE->requiresADL());
9242
9243 // FIXME: Do we have to check
9244 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009245 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009246 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009247 // If we've resolved this to a particular non-member function, just call
9248 // that function. If we resolved it to a member function,
9249 // CreateOverloaded* will find that function for us.
9250 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9251 if (!isa<CXXMethodDecl>(ND))
9252 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009253 }
Mike Stump1eb44332009-09-09 15:08:12 +00009254
Douglas Gregorb98b1992009-08-11 05:31:07 +00009255 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009256 Expr *Args[2] = { First, Second };
9257 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009258
Douglas Gregorb98b1992009-08-11 05:31:07 +00009259 // Create the overloaded operator invocation for unary operators.
9260 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009261 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009262 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009263 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009264 }
Mike Stump1eb44332009-09-09 15:08:12 +00009265
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009266 if (Op == OO_Subscript) {
9267 SourceLocation LBrace;
9268 SourceLocation RBrace;
9269
9270 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9271 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9272 LBrace = SourceLocation::getFromRawEncoding(
9273 NameLoc.CXXOperatorName.BeginOpNameLoc);
9274 RBrace = SourceLocation::getFromRawEncoding(
9275 NameLoc.CXXOperatorName.EndOpNameLoc);
9276 } else {
9277 LBrace = Callee->getLocStart();
9278 RBrace = OpLoc;
9279 }
9280
9281 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9282 First, Second);
9283 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009284
Douglas Gregorb98b1992009-08-11 05:31:07 +00009285 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009286 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009287 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009288 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9289 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009290 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009291
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009292 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009293}
Mike Stump1eb44332009-09-09 15:08:12 +00009294
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009295template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009296ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009297TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009298 SourceLocation OperatorLoc,
9299 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009300 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009301 TypeSourceInfo *ScopeType,
9302 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009303 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009304 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009305 QualType BaseType = Base->getType();
9306 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009307 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009308 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009309 !BaseType->getAs<PointerType>()->getPointeeType()
9310 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009311 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009312 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009313 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009314 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009315 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009316 /*FIXME?*/true);
9317 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009318
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009319 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009320 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9321 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9322 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9323 NameInfo.setNamedTypeInfo(DestroyedType);
9324
Richard Smith6314db92012-05-15 06:15:11 +00009325 // The scope type is now known to be a valid nested name specifier
9326 // component. Tack it on to the end of the nested name specifier.
9327 if (ScopeType)
9328 SS.Extend(SemaRef.Context, SourceLocation(),
9329 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009330
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009331 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009332 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009333 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009334 SS, TemplateKWLoc,
9335 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009336 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009337 /*TemplateArgs*/ 0);
9338}
9339
Douglas Gregor577f75a2009-08-04 16:50:30 +00009340} // end namespace clang
9341
9342#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H