blob: 753b74efa31a649e23b498f08a21158766fd43ed [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
Richard Smith5cf15892012-12-21 08:13:35 +00002605 // If this is not a direct-initializer, we only need to reconstruct
2606 // InitListExprs. Other forms of copy-initialization will be a no-op if
2607 // the initializer is already the right type.
2608 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2609 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2610 return getDerived().TransformExpr(Init);
2611
2612 // Revert value-initialization back to empty parens.
2613 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2614 SourceRange Parens = VIE->getSourceRange();
2615 return getDerived().RebuildParenListExpr(Parens.getBegin(), MultiExprArg(),
2616 Parens.getEnd());
2617 }
2618
2619 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2620 if (isa<ImplicitValueInitExpr>(Init))
2621 return getDerived().RebuildParenListExpr(SourceLocation(), MultiExprArg(),
2622 SourceLocation());
2623
2624 // Revert initialization by constructor back to a parenthesized or braced list
2625 // of expressions. Any other form of initializer can just be reused directly.
2626 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002627 return getDerived().TransformExpr(Init);
2628
2629 SmallVector<Expr*, 8> NewArgs;
2630 bool ArgChanged = false;
2631 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2632 /*IsCall*/true, NewArgs, &ArgChanged))
2633 return ExprError();
2634
2635 // If this was list initialization, revert to list form.
2636 if (Construct->isListInitialization())
2637 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2638 Construct->getLocEnd(),
2639 Construct->getType());
2640
Richard Smithc83c2302012-12-19 01:39:02 +00002641 // Build a ParenListExpr to represent anything else.
2642 SourceRange Parens = Construct->getParenRange();
2643 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2644 Parens.getEnd());
2645}
2646
2647template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002648bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2649 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002650 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002651 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002652 bool *ArgChanged) {
2653 for (unsigned I = 0; I != NumInputs; ++I) {
2654 // If requested, drop call arguments that need to be dropped.
2655 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2656 if (ArgChanged)
2657 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002658
Douglas Gregoraa165f82011-01-03 19:04:46 +00002659 break;
2660 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002661
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002662 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2663 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002664
Chris Lattner686775d2011-07-20 06:58:45 +00002665 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002666 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2667 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002668
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002669 // Determine whether the set of unexpanded parameter packs can and should
2670 // be expanded.
2671 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002672 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002673 llvm::Optional<unsigned> OrigNumExpansions
2674 = Expansion->getNumExpansions();
2675 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002676 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2677 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002678 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002679 Expand, RetainExpansion,
2680 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002681 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002682
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002683 if (!Expand) {
2684 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002685 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002686 // expansion.
2687 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2688 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2689 if (OutPattern.isInvalid())
2690 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002691
2692 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002693 Expansion->getEllipsisLoc(),
2694 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002695 if (Out.isInvalid())
2696 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002697
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002698 if (ArgChanged)
2699 *ArgChanged = true;
2700 Outputs.push_back(Out.get());
2701 continue;
2702 }
John McCallc8fc90a2011-07-06 07:30:07 +00002703
2704 // Record right away that the argument was changed. This needs
2705 // to happen even if the array expands to nothing.
2706 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002707
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002708 // The transform has determined that we should perform an elementwise
2709 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002710 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002711 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2712 ExprResult Out = getDerived().TransformExpr(Pattern);
2713 if (Out.isInvalid())
2714 return true;
2715
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002716 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002717 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2718 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002719 if (Out.isInvalid())
2720 return true;
2721 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002722
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002723 Outputs.push_back(Out.get());
2724 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002725
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002726 continue;
2727 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002728
Richard Smithc83c2302012-12-19 01:39:02 +00002729 ExprResult Result =
2730 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2731 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002732 if (Result.isInvalid())
2733 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002734
Douglas Gregoraa165f82011-01-03 19:04:46 +00002735 if (Result.get() != Inputs[I] && ArgChanged)
2736 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002737
2738 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002739 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002740
Douglas Gregoraa165f82011-01-03 19:04:46 +00002741 return false;
2742}
2743
2744template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002745NestedNameSpecifierLoc
2746TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2747 NestedNameSpecifierLoc NNS,
2748 QualType ObjectType,
2749 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002750 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002751 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002752 Qualifier = Qualifier.getPrefix())
2753 Qualifiers.push_back(Qualifier);
2754
2755 CXXScopeSpec SS;
2756 while (!Qualifiers.empty()) {
2757 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2758 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002759
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002760 switch (QNNS->getKind()) {
2761 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002762 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002763 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002764 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002765 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002766 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002767 FirstQualifierInScope, false))
2768 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002769
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002770 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002771
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002772 case NestedNameSpecifier::Namespace: {
2773 NamespaceDecl *NS
2774 = cast_or_null<NamespaceDecl>(
2775 getDerived().TransformDecl(
2776 Q.getLocalBeginLoc(),
2777 QNNS->getAsNamespace()));
2778 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2779 break;
2780 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002781
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002782 case NestedNameSpecifier::NamespaceAlias: {
2783 NamespaceAliasDecl *Alias
2784 = cast_or_null<NamespaceAliasDecl>(
2785 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2786 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002787 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002788 Q.getLocalEndLoc());
2789 break;
2790 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002791
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002792 case NestedNameSpecifier::Global:
2793 // There is no meaningful transformation that one could perform on the
2794 // global scope.
2795 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2796 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002797
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002798 case NestedNameSpecifier::TypeSpecWithTemplate:
2799 case NestedNameSpecifier::TypeSpec: {
2800 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2801 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002802
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002803 if (!TL)
2804 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002805
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002806 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002807 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002808 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002809 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002810 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002811 if (TL.getType()->isEnumeralType())
2812 SemaRef.Diag(TL.getBeginLoc(),
2813 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002814 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2815 Q.getLocalEndLoc());
2816 break;
2817 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002818 // If the nested-name-specifier is an invalid type def, don't emit an
2819 // error because a previous error should have already been emitted.
2820 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2821 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002822 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002823 << TL.getType() << SS.getRange();
2824 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002825 return NestedNameSpecifierLoc();
2826 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002827 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002828
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002829 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002830 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002831 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002832 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002833
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002834 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002835 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002836 !getDerived().AlwaysRebuild())
2837 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002838
2839 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002840 // nested-name-specifier, do so.
2841 if (SS.location_size() == NNS.getDataLength() &&
2842 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2843 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2844
2845 // Allocate new nested-name-specifier location information.
2846 return SS.getWithLocInContext(SemaRef.Context);
2847}
2848
2849template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002850DeclarationNameInfo
2851TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002852::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002853 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002854 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002855 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002856
2857 switch (Name.getNameKind()) {
2858 case DeclarationName::Identifier:
2859 case DeclarationName::ObjCZeroArgSelector:
2860 case DeclarationName::ObjCOneArgSelector:
2861 case DeclarationName::ObjCMultiArgSelector:
2862 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002863 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002864 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002865 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002866
Douglas Gregor81499bb2009-09-03 22:13:48 +00002867 case DeclarationName::CXXConstructorName:
2868 case DeclarationName::CXXDestructorName:
2869 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002870 TypeSourceInfo *NewTInfo;
2871 CanQualType NewCanTy;
2872 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002873 NewTInfo = getDerived().TransformType(OldTInfo);
2874 if (!NewTInfo)
2875 return DeclarationNameInfo();
2876 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002877 }
2878 else {
2879 NewTInfo = 0;
2880 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002881 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002882 if (NewT.isNull())
2883 return DeclarationNameInfo();
2884 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2885 }
Mike Stump1eb44332009-09-09 15:08:12 +00002886
Abramo Bagnara25777432010-08-11 22:01:17 +00002887 DeclarationName NewName
2888 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2889 NewCanTy);
2890 DeclarationNameInfo NewNameInfo(NameInfo);
2891 NewNameInfo.setName(NewName);
2892 NewNameInfo.setNamedTypeInfo(NewTInfo);
2893 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002894 }
Mike Stump1eb44332009-09-09 15:08:12 +00002895 }
2896
David Blaikieb219cfc2011-09-23 05:06:16 +00002897 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002898}
2899
2900template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002901TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002902TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2903 TemplateName Name,
2904 SourceLocation NameLoc,
2905 QualType ObjectType,
2906 NamedDecl *FirstQualifierInScope) {
2907 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2908 TemplateDecl *Template = QTN->getTemplateDecl();
2909 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002910
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002911 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002912 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002913 Template));
2914 if (!TransTemplate)
2915 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002916
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002917 if (!getDerived().AlwaysRebuild() &&
2918 SS.getScopeRep() == QTN->getQualifier() &&
2919 TransTemplate == Template)
2920 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002921
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002922 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2923 TransTemplate);
2924 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002925
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002926 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2927 if (SS.getScopeRep()) {
2928 // These apply to the scope specifier, not the template.
2929 ObjectType = QualType();
2930 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002931 }
2932
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002933 if (!getDerived().AlwaysRebuild() &&
2934 SS.getScopeRep() == DTN->getQualifier() &&
2935 ObjectType.isNull())
2936 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002937
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002938 if (DTN->isIdentifier()) {
2939 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002940 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002941 NameLoc,
2942 ObjectType,
2943 FirstQualifierInScope);
2944 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002945
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002946 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2947 ObjectType);
2948 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002949
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002950 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2951 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002952 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002953 Template));
2954 if (!TransTemplate)
2955 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002956
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002957 if (!getDerived().AlwaysRebuild() &&
2958 TransTemplate == Template)
2959 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002960
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002961 return TemplateName(TransTemplate);
2962 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002963
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002964 if (SubstTemplateTemplateParmPackStorage *SubstPack
2965 = Name.getAsSubstTemplateTemplateParmPack()) {
2966 TemplateTemplateParmDecl *TransParam
2967 = cast_or_null<TemplateTemplateParmDecl>(
2968 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2969 if (!TransParam)
2970 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002971
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002972 if (!getDerived().AlwaysRebuild() &&
2973 TransParam == SubstPack->getParameterPack())
2974 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002975
2976 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002977 SubstPack->getArgumentPack());
2978 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002979
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002980 // These should be getting filtered out before they reach the AST.
2981 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002982}
2983
2984template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002985void TreeTransform<Derived>::InventTemplateArgumentLoc(
2986 const TemplateArgument &Arg,
2987 TemplateArgumentLoc &Output) {
2988 SourceLocation Loc = getDerived().getBaseLocation();
2989 switch (Arg.getKind()) {
2990 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002991 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002992 break;
2993
2994 case TemplateArgument::Type:
2995 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002996 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002997
John McCall833ca992009-10-29 08:12:44 +00002998 break;
2999
Douglas Gregor788cd062009-11-11 01:00:40 +00003000 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003001 case TemplateArgument::TemplateExpansion: {
3002 NestedNameSpecifierLocBuilder Builder;
3003 TemplateName Template = Arg.getAsTemplate();
3004 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3005 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3006 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3007 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003008
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003009 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003010 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003011 Builder.getWithLocInContext(SemaRef.Context),
3012 Loc);
3013 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003014 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003015 Builder.getWithLocInContext(SemaRef.Context),
3016 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003017
Douglas Gregor788cd062009-11-11 01:00:40 +00003018 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003019 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003020
John McCall833ca992009-10-29 08:12:44 +00003021 case TemplateArgument::Expression:
3022 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3023 break;
3024
3025 case TemplateArgument::Declaration:
3026 case TemplateArgument::Integral:
3027 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003028 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003029 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003030 break;
3031 }
3032}
3033
3034template<typename Derived>
3035bool TreeTransform<Derived>::TransformTemplateArgument(
3036 const TemplateArgumentLoc &Input,
3037 TemplateArgumentLoc &Output) {
3038 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003039 switch (Arg.getKind()) {
3040 case TemplateArgument::Null:
3041 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003042 case TemplateArgument::Pack:
3043 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003044 case TemplateArgument::NullPtr:
3045 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003046
Douglas Gregor670444e2009-08-04 22:27:00 +00003047 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003048 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003049 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003050 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003051
3052 DI = getDerived().TransformType(DI);
3053 if (!DI) return true;
3054
3055 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3056 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003057 }
Mike Stump1eb44332009-09-09 15:08:12 +00003058
Douglas Gregor788cd062009-11-11 01:00:40 +00003059 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003060 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3061 if (QualifierLoc) {
3062 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3063 if (!QualifierLoc)
3064 return true;
3065 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003066
Douglas Gregor1d752d72011-03-02 18:46:51 +00003067 CXXScopeSpec SS;
3068 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003069 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003070 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3071 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003072 if (Template.isNull())
3073 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003074
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003075 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003076 Input.getTemplateNameLoc());
3077 return false;
3078 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003079
3080 case TemplateArgument::TemplateExpansion:
3081 llvm_unreachable("Caller should expand pack expansions");
3082
Douglas Gregor670444e2009-08-04 22:27:00 +00003083 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003084 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003085 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003086 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003087
John McCall833ca992009-10-29 08:12:44 +00003088 Expr *InputExpr = Input.getSourceExpression();
3089 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3090
Chris Lattner223de242011-04-25 20:37:58 +00003091 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003092 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003093 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003094 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003095 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003096 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003097 }
Mike Stump1eb44332009-09-09 15:08:12 +00003098
Douglas Gregor670444e2009-08-04 22:27:00 +00003099 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003100 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003101}
3102
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003103/// \brief Iterator adaptor that invents template argument location information
3104/// for each of the template arguments in its underlying iterator.
3105template<typename Derived, typename InputIterator>
3106class TemplateArgumentLocInventIterator {
3107 TreeTransform<Derived> &Self;
3108 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003109
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003110public:
3111 typedef TemplateArgumentLoc value_type;
3112 typedef TemplateArgumentLoc reference;
3113 typedef typename std::iterator_traits<InputIterator>::difference_type
3114 difference_type;
3115 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003116
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003117 class pointer {
3118 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003119
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003120 public:
3121 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003122
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003123 const TemplateArgumentLoc *operator->() const { return &Arg; }
3124 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003125
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003126 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003127
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003128 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3129 InputIterator Iter)
3130 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003131
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003132 TemplateArgumentLocInventIterator &operator++() {
3133 ++Iter;
3134 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003135 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003136
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003137 TemplateArgumentLocInventIterator operator++(int) {
3138 TemplateArgumentLocInventIterator Old(*this);
3139 ++(*this);
3140 return Old;
3141 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003142
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003143 reference operator*() const {
3144 TemplateArgumentLoc Result;
3145 Self.InventTemplateArgumentLoc(*Iter, Result);
3146 return Result;
3147 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003148
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003149 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003150
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003151 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3152 const TemplateArgumentLocInventIterator &Y) {
3153 return X.Iter == Y.Iter;
3154 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003155
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003156 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3157 const TemplateArgumentLocInventIterator &Y) {
3158 return X.Iter != Y.Iter;
3159 }
3160};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003161
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003162template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003163template<typename InputIterator>
3164bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3165 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003166 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003167 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003168 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003169 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003170
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003171 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3172 // Unpack argument packs, which we translate them into separate
3173 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003174 // FIXME: We could do much better if we could guarantee that the
3175 // TemplateArgumentLocInfo for the pack expansion would be usable for
3176 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003177 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003178 TemplateArgument::pack_iterator>
3179 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003180 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003181 In.getArgument().pack_begin()),
3182 PackLocIterator(*this,
3183 In.getArgument().pack_end()),
3184 Outputs))
3185 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003186
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003187 continue;
3188 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003189
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003190 if (In.getArgument().isPackExpansion()) {
3191 // We have a pack expansion, for which we will be substituting into
3192 // the pattern.
3193 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003194 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003195 TemplateArgumentLoc Pattern
Chad Rosier4a9d7952012-08-08 18:46:20 +00003196 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
Douglas Gregorcded4f62011-01-14 17:04:44 +00003197 getSema().Context);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003198
Chris Lattner686775d2011-07-20 06:58:45 +00003199 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003200 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3201 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003202
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003203 // Determine whether the set of unexpanded parameter packs can and should
3204 // be expanded.
3205 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003206 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003207 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003208 if (getDerived().TryExpandParameterPacks(Ellipsis,
3209 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003210 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003211 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003212 RetainExpansion,
3213 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003214 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003215
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003216 if (!Expand) {
3217 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003218 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003219 // expansion.
3220 TemplateArgumentLoc OutPattern;
3221 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3222 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3223 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003224
Douglas Gregorcded4f62011-01-14 17:04:44 +00003225 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3226 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003227 if (Out.getArgument().isNull())
3228 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003229
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003230 Outputs.addArgument(Out);
3231 continue;
3232 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003233
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003234 // The transform has determined that we should perform an elementwise
3235 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003236 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003237 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3238
3239 if (getDerived().TransformTemplateArgument(Pattern, Out))
3240 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003241
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003242 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003243 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3244 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003245 if (Out.getArgument().isNull())
3246 return true;
3247 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003248
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003249 Outputs.addArgument(Out);
3250 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003251
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003252 // If we're supposed to retain a pack expansion, do so by temporarily
3253 // forgetting the partially-substituted parameter pack.
3254 if (RetainExpansion) {
3255 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003256
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003257 if (getDerived().TransformTemplateArgument(Pattern, Out))
3258 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003259
Douglas Gregorcded4f62011-01-14 17:04:44 +00003260 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3261 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003262 if (Out.getArgument().isNull())
3263 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003264
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003265 Outputs.addArgument(Out);
3266 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003267
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003268 continue;
3269 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003270
3271 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003272 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003273 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003274
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003275 Outputs.addArgument(Out);
3276 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003277
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003278 return false;
3279
3280}
3281
Douglas Gregor577f75a2009-08-04 16:50:30 +00003282//===----------------------------------------------------------------------===//
3283// Type transformation
3284//===----------------------------------------------------------------------===//
3285
3286template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003287QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003288 if (getDerived().AlreadyTransformed(T))
3289 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003290
John McCalla2becad2009-10-21 00:40:46 +00003291 // Temporary workaround. All of these transformations should
3292 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003293 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3294 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003295
John McCall43fed0d2010-11-12 08:19:04 +00003296 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003297
John McCalla2becad2009-10-21 00:40:46 +00003298 if (!NewDI)
3299 return QualType();
3300
3301 return NewDI->getType();
3302}
3303
3304template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003305TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003306 // Refine the base location to the type's location.
3307 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3308 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003309 if (getDerived().AlreadyTransformed(DI->getType()))
3310 return DI;
3311
3312 TypeLocBuilder TLB;
3313
3314 TypeLoc TL = DI->getTypeLoc();
3315 TLB.reserve(TL.getFullDataSize());
3316
John McCall43fed0d2010-11-12 08:19:04 +00003317 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003318 if (Result.isNull())
3319 return 0;
3320
John McCalla93c9342009-12-07 02:54:59 +00003321 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003322}
3323
3324template<typename Derived>
3325QualType
John McCall43fed0d2010-11-12 08:19:04 +00003326TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003327 switch (T.getTypeLocClass()) {
3328#define ABSTRACT_TYPELOC(CLASS, PARENT)
3329#define TYPELOC(CLASS, PARENT) \
3330 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003331 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003332#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003333 }
Mike Stump1eb44332009-09-09 15:08:12 +00003334
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003335 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003336}
3337
3338/// FIXME: By default, this routine adds type qualifiers only to types
3339/// that can have qualifiers, and silently suppresses those qualifiers
3340/// that are not permitted (e.g., qualifiers on reference or function
3341/// types). This is the right thing for template instantiation, but
3342/// probably not for other clients.
3343template<typename Derived>
3344QualType
3345TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003346 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003347 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003348
John McCall43fed0d2010-11-12 08:19:04 +00003349 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003350 if (Result.isNull())
3351 return QualType();
3352
3353 // Silently suppress qualifiers if the result type can't be qualified.
3354 // FIXME: this is the right thing for template instantiation, but
3355 // probably not for other clients.
3356 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003357 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003358
John McCallf85e1932011-06-15 23:02:42 +00003359 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003360 // resulting type.
3361 if (Quals.hasObjCLifetime()) {
3362 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3363 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003364 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003365 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003366 // A lifetime qualifier applied to a substituted template parameter
3367 // overrides the lifetime qualifier from the template argument.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003368 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003369 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3370 QualType Replacement = SubstTypeParam->getReplacementType();
3371 Qualifiers Qs = Replacement.getQualifiers();
3372 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003373 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003374 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3375 Qs);
3376 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003377 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003378 Replacement);
3379 TLB.TypeWasModifiedSafely(Result);
3380 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003381 // Otherwise, complain about the addition of a qualifier to an
3382 // already-qualified type.
3383 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003384 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003385 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003386
Douglas Gregore559ca12011-06-17 22:11:49 +00003387 Quals.removeObjCLifetime();
3388 }
3389 }
3390 }
John McCall28654742010-06-05 06:41:15 +00003391 if (!Quals.empty()) {
3392 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3393 TLB.push<QualifiedTypeLoc>(Result);
3394 // No location information to preserve.
3395 }
John McCalla2becad2009-10-21 00:40:46 +00003396
3397 return Result;
3398}
3399
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003400template<typename Derived>
3401TypeLoc
3402TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3403 QualType ObjectType,
3404 NamedDecl *UnqualLookup,
3405 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003406 QualType T = TL.getType();
3407 if (getDerived().AlreadyTransformed(T))
3408 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003409
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003410 TypeLocBuilder TLB;
3411 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003412
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003413 if (isa<TemplateSpecializationType>(T)) {
3414 TemplateSpecializationTypeLoc SpecTL
3415 = cast<TemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003416
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003417 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003418 getDerived().TransformTemplateName(SS,
3419 SpecTL.getTypePtr()->getTemplateName(),
3420 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003421 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003422 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003423 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003424
3425 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003426 Template);
3427 } else if (isa<DependentTemplateSpecializationType>(T)) {
3428 DependentTemplateSpecializationTypeLoc SpecTL
3429 = cast<DependentTemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003430
Douglas Gregora88f09f2011-02-28 17:23:35 +00003431 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003432 = getDerived().RebuildTemplateName(SS,
3433 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003434 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003435 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003436 if (Template.isNull())
3437 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003438
3439 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003440 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003441 Template,
3442 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003443 } else {
3444 // Nothing special needs to be done for these.
3445 Result = getDerived().TransformType(TLB, TL);
3446 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003447
3448 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003449 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003450
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003451 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3452}
3453
Douglas Gregorb71d8212011-03-02 18:32:08 +00003454template<typename Derived>
3455TypeSourceInfo *
3456TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3457 QualType ObjectType,
3458 NamedDecl *UnqualLookup,
3459 CXXScopeSpec &SS) {
3460 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003461
Douglas Gregorb71d8212011-03-02 18:32:08 +00003462 QualType T = TSInfo->getType();
3463 if (getDerived().AlreadyTransformed(T))
3464 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003465
Douglas Gregorb71d8212011-03-02 18:32:08 +00003466 TypeLocBuilder TLB;
3467 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003468
Douglas Gregorb71d8212011-03-02 18:32:08 +00003469 TypeLoc TL = TSInfo->getTypeLoc();
3470 if (isa<TemplateSpecializationType>(T)) {
3471 TemplateSpecializationTypeLoc SpecTL
3472 = cast<TemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003473
Douglas Gregorb71d8212011-03-02 18:32:08 +00003474 TemplateName Template
3475 = getDerived().TransformTemplateName(SS,
3476 SpecTL.getTypePtr()->getTemplateName(),
3477 SpecTL.getTemplateNameLoc(),
3478 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003479 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003480 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003481
3482 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003483 Template);
3484 } else if (isa<DependentTemplateSpecializationType>(T)) {
3485 DependentTemplateSpecializationTypeLoc SpecTL
3486 = cast<DependentTemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003487
Douglas Gregorb71d8212011-03-02 18:32:08 +00003488 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003489 = getDerived().RebuildTemplateName(SS,
3490 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003491 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003492 ObjectType, UnqualLookup);
3493 if (Template.isNull())
3494 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003495
3496 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003497 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003498 Template,
3499 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003500 } else {
3501 // Nothing special needs to be done for these.
3502 Result = getDerived().TransformType(TLB, TL);
3503 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003504
3505 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003506 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003507
Douglas Gregorb71d8212011-03-02 18:32:08 +00003508 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3509}
3510
John McCalla2becad2009-10-21 00:40:46 +00003511template <class TyLoc> static inline
3512QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3513 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3514 NewT.setNameLoc(T.getNameLoc());
3515 return T.getType();
3516}
3517
John McCalla2becad2009-10-21 00:40:46 +00003518template<typename Derived>
3519QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003520 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003521 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3522 NewT.setBuiltinLoc(T.getBuiltinLoc());
3523 if (T.needsExtraLocalData())
3524 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3525 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003526}
Mike Stump1eb44332009-09-09 15:08:12 +00003527
Douglas Gregor577f75a2009-08-04 16:50:30 +00003528template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003529QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003530 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003531 // FIXME: recurse?
3532 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003533}
Mike Stump1eb44332009-09-09 15:08:12 +00003534
Douglas Gregor577f75a2009-08-04 16:50:30 +00003535template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003536QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003537 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003538 QualType PointeeType
3539 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003540 if (PointeeType.isNull())
3541 return QualType();
3542
3543 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003544 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003545 // A dependent pointer type 'T *' has is being transformed such
3546 // that an Objective-C class type is being replaced for 'T'. The
3547 // resulting pointer type is an ObjCObjectPointerType, not a
3548 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003549 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003550
John McCallc12c5bb2010-05-15 11:32:37 +00003551 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3552 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003553 return Result;
3554 }
John McCall43fed0d2010-11-12 08:19:04 +00003555
Douglas Gregor92e986e2010-04-22 16:44:27 +00003556 if (getDerived().AlwaysRebuild() ||
3557 PointeeType != TL.getPointeeLoc().getType()) {
3558 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3559 if (Result.isNull())
3560 return QualType();
3561 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003562
John McCallf85e1932011-06-15 23:02:42 +00003563 // Objective-C ARC can add lifetime qualifiers to the type that we're
3564 // pointing to.
3565 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003566
Douglas Gregor92e986e2010-04-22 16:44:27 +00003567 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3568 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003569 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003570}
Mike Stump1eb44332009-09-09 15:08:12 +00003571
3572template<typename Derived>
3573QualType
John McCalla2becad2009-10-21 00:40:46 +00003574TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003575 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003576 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003577 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3578 if (PointeeType.isNull())
3579 return QualType();
3580
3581 QualType Result = TL.getType();
3582 if (getDerived().AlwaysRebuild() ||
3583 PointeeType != TL.getPointeeLoc().getType()) {
3584 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003585 TL.getSigilLoc());
3586 if (Result.isNull())
3587 return QualType();
3588 }
3589
Douglas Gregor39968ad2010-04-22 16:50:51 +00003590 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003591 NewT.setSigilLoc(TL.getSigilLoc());
3592 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003593}
3594
John McCall85737a72009-10-30 00:06:24 +00003595/// Transforms a reference type. Note that somewhat paradoxically we
3596/// don't care whether the type itself is an l-value type or an r-value
3597/// type; we only care if the type was *written* as an l-value type
3598/// or an r-value type.
3599template<typename Derived>
3600QualType
3601TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003602 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003603 const ReferenceType *T = TL.getTypePtr();
3604
3605 // Note that this works with the pointee-as-written.
3606 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3607 if (PointeeType.isNull())
3608 return QualType();
3609
3610 QualType Result = TL.getType();
3611 if (getDerived().AlwaysRebuild() ||
3612 PointeeType != T->getPointeeTypeAsWritten()) {
3613 Result = getDerived().RebuildReferenceType(PointeeType,
3614 T->isSpelledAsLValue(),
3615 TL.getSigilLoc());
3616 if (Result.isNull())
3617 return QualType();
3618 }
3619
John McCallf85e1932011-06-15 23:02:42 +00003620 // Objective-C ARC can add lifetime qualifiers to the type that we're
3621 // referring to.
3622 TLB.TypeWasModifiedSafely(
3623 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3624
John McCall85737a72009-10-30 00:06:24 +00003625 // r-value references can be rebuilt as l-value references.
3626 ReferenceTypeLoc NewTL;
3627 if (isa<LValueReferenceType>(Result))
3628 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3629 else
3630 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3631 NewTL.setSigilLoc(TL.getSigilLoc());
3632
3633 return Result;
3634}
3635
Mike Stump1eb44332009-09-09 15:08:12 +00003636template<typename Derived>
3637QualType
John McCalla2becad2009-10-21 00:40:46 +00003638TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003639 LValueReferenceTypeLoc TL) {
3640 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003641}
3642
Mike Stump1eb44332009-09-09 15:08:12 +00003643template<typename Derived>
3644QualType
John McCalla2becad2009-10-21 00:40:46 +00003645TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003646 RValueReferenceTypeLoc TL) {
3647 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003648}
Mike Stump1eb44332009-09-09 15:08:12 +00003649
Douglas Gregor577f75a2009-08-04 16:50:30 +00003650template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003651QualType
John McCalla2becad2009-10-21 00:40:46 +00003652TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003653 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003654 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003655 if (PointeeType.isNull())
3656 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003657
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003658 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3659 TypeSourceInfo* NewClsTInfo = 0;
3660 if (OldClsTInfo) {
3661 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3662 if (!NewClsTInfo)
3663 return QualType();
3664 }
3665
3666 const MemberPointerType *T = TL.getTypePtr();
3667 QualType OldClsType = QualType(T->getClass(), 0);
3668 QualType NewClsType;
3669 if (NewClsTInfo)
3670 NewClsType = NewClsTInfo->getType();
3671 else {
3672 NewClsType = getDerived().TransformType(OldClsType);
3673 if (NewClsType.isNull())
3674 return QualType();
3675 }
Mike Stump1eb44332009-09-09 15:08:12 +00003676
John McCalla2becad2009-10-21 00:40:46 +00003677 QualType Result = TL.getType();
3678 if (getDerived().AlwaysRebuild() ||
3679 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003680 NewClsType != OldClsType) {
3681 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003682 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003683 if (Result.isNull())
3684 return QualType();
3685 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003686
John McCalla2becad2009-10-21 00:40:46 +00003687 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3688 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003689 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003690
3691 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003692}
3693
Mike Stump1eb44332009-09-09 15:08:12 +00003694template<typename Derived>
3695QualType
John McCalla2becad2009-10-21 00:40:46 +00003696TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003697 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003698 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003699 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003700 if (ElementType.isNull())
3701 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003702
John McCalla2becad2009-10-21 00:40:46 +00003703 QualType Result = TL.getType();
3704 if (getDerived().AlwaysRebuild() ||
3705 ElementType != T->getElementType()) {
3706 Result = getDerived().RebuildConstantArrayType(ElementType,
3707 T->getSizeModifier(),
3708 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003709 T->getIndexTypeCVRQualifiers(),
3710 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003711 if (Result.isNull())
3712 return QualType();
3713 }
Eli Friedman457a3772012-01-25 22:19:07 +00003714
3715 // We might have either a ConstantArrayType or a VariableArrayType now:
3716 // a ConstantArrayType is allowed to have an element type which is a
3717 // VariableArrayType if the type is dependent. Fortunately, all array
3718 // types have the same location layout.
3719 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003720 NewTL.setLBracketLoc(TL.getLBracketLoc());
3721 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003722
John McCalla2becad2009-10-21 00:40:46 +00003723 Expr *Size = TL.getSizeExpr();
3724 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003725 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3726 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003727 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003728 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003729 }
3730 NewTL.setSizeExpr(Size);
3731
3732 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003733}
Mike Stump1eb44332009-09-09 15:08:12 +00003734
Douglas Gregor577f75a2009-08-04 16:50:30 +00003735template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003736QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003737 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003738 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003739 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003740 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003741 if (ElementType.isNull())
3742 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003743
John McCalla2becad2009-10-21 00:40:46 +00003744 QualType Result = TL.getType();
3745 if (getDerived().AlwaysRebuild() ||
3746 ElementType != T->getElementType()) {
3747 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003748 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003749 T->getIndexTypeCVRQualifiers(),
3750 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003751 if (Result.isNull())
3752 return QualType();
3753 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003754
John McCalla2becad2009-10-21 00:40:46 +00003755 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3756 NewTL.setLBracketLoc(TL.getLBracketLoc());
3757 NewTL.setRBracketLoc(TL.getRBracketLoc());
3758 NewTL.setSizeExpr(0);
3759
3760 return Result;
3761}
3762
3763template<typename Derived>
3764QualType
3765TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003766 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003767 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003768 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3769 if (ElementType.isNull())
3770 return QualType();
3771
John McCall60d7b3a2010-08-24 06:29:42 +00003772 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003773 = getDerived().TransformExpr(T->getSizeExpr());
3774 if (SizeResult.isInvalid())
3775 return QualType();
3776
John McCall9ae2f072010-08-23 23:25:46 +00003777 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003778
3779 QualType Result = TL.getType();
3780 if (getDerived().AlwaysRebuild() ||
3781 ElementType != T->getElementType() ||
3782 Size != T->getSizeExpr()) {
3783 Result = getDerived().RebuildVariableArrayType(ElementType,
3784 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003785 Size,
John McCalla2becad2009-10-21 00:40:46 +00003786 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003787 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003788 if (Result.isNull())
3789 return QualType();
3790 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003791
John McCalla2becad2009-10-21 00:40:46 +00003792 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3793 NewTL.setLBracketLoc(TL.getLBracketLoc());
3794 NewTL.setRBracketLoc(TL.getRBracketLoc());
3795 NewTL.setSizeExpr(Size);
3796
3797 return Result;
3798}
3799
3800template<typename Derived>
3801QualType
3802TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003803 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003804 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003805 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3806 if (ElementType.isNull())
3807 return QualType();
3808
Richard Smithf6702a32011-12-20 02:08:33 +00003809 // Array bounds are constant expressions.
3810 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3811 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003812
John McCall3b657512011-01-19 10:06:00 +00003813 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3814 Expr *origSize = TL.getSizeExpr();
3815 if (!origSize) origSize = T->getSizeExpr();
3816
3817 ExprResult sizeResult
3818 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003819 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003820 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003821 return QualType();
3822
John McCall3b657512011-01-19 10:06:00 +00003823 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003824
3825 QualType Result = TL.getType();
3826 if (getDerived().AlwaysRebuild() ||
3827 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003828 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003829 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3830 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003831 size,
John McCalla2becad2009-10-21 00:40:46 +00003832 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003833 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003834 if (Result.isNull())
3835 return QualType();
3836 }
John McCalla2becad2009-10-21 00:40:46 +00003837
3838 // We might have any sort of array type now, but fortunately they
3839 // all have the same location layout.
3840 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3841 NewTL.setLBracketLoc(TL.getLBracketLoc());
3842 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003843 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003844
3845 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003846}
Mike Stump1eb44332009-09-09 15:08:12 +00003847
3848template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003849QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003850 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003851 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003852 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003853
3854 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003855 QualType ElementType = getDerived().TransformType(T->getElementType());
3856 if (ElementType.isNull())
3857 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003858
Richard Smithf6702a32011-12-20 02:08:33 +00003859 // Vector sizes are constant expressions.
3860 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3861 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003862
John McCall60d7b3a2010-08-24 06:29:42 +00003863 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003864 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003865 if (Size.isInvalid())
3866 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003867
John McCalla2becad2009-10-21 00:40:46 +00003868 QualType Result = TL.getType();
3869 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003870 ElementType != T->getElementType() ||
3871 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003872 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003873 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003874 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003875 if (Result.isNull())
3876 return QualType();
3877 }
John McCalla2becad2009-10-21 00:40:46 +00003878
3879 // Result might be dependent or not.
3880 if (isa<DependentSizedExtVectorType>(Result)) {
3881 DependentSizedExtVectorTypeLoc NewTL
3882 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3883 NewTL.setNameLoc(TL.getNameLoc());
3884 } else {
3885 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3886 NewTL.setNameLoc(TL.getNameLoc());
3887 }
3888
3889 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003890}
Mike Stump1eb44332009-09-09 15:08:12 +00003891
3892template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003893QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003894 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003895 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003896 QualType ElementType = getDerived().TransformType(T->getElementType());
3897 if (ElementType.isNull())
3898 return QualType();
3899
John McCalla2becad2009-10-21 00:40:46 +00003900 QualType Result = TL.getType();
3901 if (getDerived().AlwaysRebuild() ||
3902 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003903 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003904 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003905 if (Result.isNull())
3906 return QualType();
3907 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003908
John McCalla2becad2009-10-21 00:40:46 +00003909 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3910 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003911
John McCalla2becad2009-10-21 00:40:46 +00003912 return Result;
3913}
3914
3915template<typename Derived>
3916QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003917 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003918 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003919 QualType ElementType = getDerived().TransformType(T->getElementType());
3920 if (ElementType.isNull())
3921 return QualType();
3922
3923 QualType Result = TL.getType();
3924 if (getDerived().AlwaysRebuild() ||
3925 ElementType != T->getElementType()) {
3926 Result = getDerived().RebuildExtVectorType(ElementType,
3927 T->getNumElements(),
3928 /*FIXME*/ SourceLocation());
3929 if (Result.isNull())
3930 return QualType();
3931 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003932
John McCalla2becad2009-10-21 00:40:46 +00003933 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3934 NewTL.setNameLoc(TL.getNameLoc());
3935
3936 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003937}
Mike Stump1eb44332009-09-09 15:08:12 +00003938
3939template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003940ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003941TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003942 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003943 llvm::Optional<unsigned> NumExpansions,
3944 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003945 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003946 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003947
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003948 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003949 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003950 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003951 TypeLoc OldTL = OldDI->getTypeLoc();
3952 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003953
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003954 TypeLocBuilder TLB;
3955 TypeLoc NewTL = OldDI->getTypeLoc();
3956 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003957
3958 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003959 OldExpansionTL.getPatternLoc());
3960 if (Result.isNull())
3961 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003962
3963 Result = RebuildPackExpansionType(Result,
3964 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003965 OldExpansionTL.getEllipsisLoc(),
3966 NumExpansions);
3967 if (Result.isNull())
3968 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003969
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003970 PackExpansionTypeLoc NewExpansionTL
3971 = TLB.push<PackExpansionTypeLoc>(Result);
3972 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3973 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3974 } else
3975 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003976 if (!NewDI)
3977 return 0;
3978
John McCallfb44de92011-05-01 22:35:37 +00003979 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003980 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003981
3982 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3983 OldParm->getDeclContext(),
3984 OldParm->getInnerLocStart(),
3985 OldParm->getLocation(),
3986 OldParm->getIdentifier(),
3987 NewDI->getType(),
3988 NewDI,
3989 OldParm->getStorageClass(),
3990 OldParm->getStorageClassAsWritten(),
3991 /* DefArg */ NULL);
3992 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3993 OldParm->getFunctionScopeIndex() + indexAdjustment);
3994 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003995}
3996
3997template<typename Derived>
3998bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003999 TransformFunctionTypeParams(SourceLocation Loc,
4000 ParmVarDecl **Params, unsigned NumParams,
4001 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004002 SmallVectorImpl<QualType> &OutParamTypes,
4003 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004004 int indexAdjustment = 0;
4005
Douglas Gregora009b592011-01-07 00:20:55 +00004006 for (unsigned i = 0; i != NumParams; ++i) {
4007 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004008 assert(OldParm->getFunctionScopeIndex() == i);
4009
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004010 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004011 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004012 if (OldParm->isParameterPack()) {
4013 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004014 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004015
Douglas Gregor603cfb42011-01-05 23:12:31 +00004016 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004017 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
4018 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
4019 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4020 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004021 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4022
Douglas Gregor603cfb42011-01-05 23:12:31 +00004023 // Determine whether we should expand the parameter packs.
4024 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004025 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004026 llvm::Optional<unsigned> OrigNumExpansions
4027 = ExpansionTL.getTypePtr()->getNumExpansions();
4028 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004029 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4030 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004031 Unexpanded,
4032 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004033 RetainExpansion,
4034 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004035 return true;
4036 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004037
Douglas Gregor603cfb42011-01-05 23:12:31 +00004038 if (ShouldExpand) {
4039 // Expand the function parameter pack into multiple, separate
4040 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004041 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004042 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004043 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004044 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004045 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004046 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004047 OrigNumExpansions,
4048 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004049 if (!NewParm)
4050 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004051
Douglas Gregora009b592011-01-07 00:20:55 +00004052 OutParamTypes.push_back(NewParm->getType());
4053 if (PVars)
4054 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004055 }
Douglas Gregord3731192011-01-10 07:32:04 +00004056
4057 // If we're supposed to retain a pack expansion, do so by temporarily
4058 // forgetting the partially-substituted parameter pack.
4059 if (RetainExpansion) {
4060 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004061 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004062 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004063 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004064 OrigNumExpansions,
4065 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004066 if (!NewParm)
4067 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004068
Douglas Gregord3731192011-01-10 07:32:04 +00004069 OutParamTypes.push_back(NewParm->getType());
4070 if (PVars)
4071 PVars->push_back(NewParm);
4072 }
4073
John McCallfb44de92011-05-01 22:35:37 +00004074 // The next parameter should have the same adjustment as the
4075 // last thing we pushed, but we post-incremented indexAdjustment
4076 // on every push. Also, if we push nothing, the adjustment should
4077 // go down by one.
4078 indexAdjustment--;
4079
Douglas Gregor603cfb42011-01-05 23:12:31 +00004080 // We're done with the pack expansion.
4081 continue;
4082 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004083
4084 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004085 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004086 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4087 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004088 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004089 NumExpansions,
4090 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004091 } else {
4092 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004093 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004094 llvm::Optional<unsigned>(),
4095 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004096 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004097
John McCall21ef0fa2010-03-11 09:03:00 +00004098 if (!NewParm)
4099 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004100
Douglas Gregora009b592011-01-07 00:20:55 +00004101 OutParamTypes.push_back(NewParm->getType());
4102 if (PVars)
4103 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004104 continue;
4105 }
John McCall21ef0fa2010-03-11 09:03:00 +00004106
4107 // Deal with the possibility that we don't have a parameter
4108 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004109 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004110 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004111 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004112 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004113 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004114 = dyn_cast<PackExpansionType>(OldType)) {
4115 // We have a function parameter pack that may need to be expanded.
4116 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004117 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004118 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004119
Douglas Gregor603cfb42011-01-05 23:12:31 +00004120 // Determine whether we should expand the parameter packs.
4121 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004122 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004123 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004124 Unexpanded,
4125 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004126 RetainExpansion,
4127 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004128 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004129 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004130
Douglas Gregor603cfb42011-01-05 23:12:31 +00004131 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004132 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004133 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004134 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004135 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4136 QualType NewType = getDerived().TransformType(Pattern);
4137 if (NewType.isNull())
4138 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004139
Douglas Gregora009b592011-01-07 00:20:55 +00004140 OutParamTypes.push_back(NewType);
4141 if (PVars)
4142 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004143 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004144
Douglas Gregor603cfb42011-01-05 23:12:31 +00004145 // We're done with the pack expansion.
4146 continue;
4147 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004148
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004149 // If we're supposed to retain a pack expansion, do so by temporarily
4150 // forgetting the partially-substituted parameter pack.
4151 if (RetainExpansion) {
4152 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4153 QualType NewType = getDerived().TransformType(Pattern);
4154 if (NewType.isNull())
4155 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004156
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004157 OutParamTypes.push_back(NewType);
4158 if (PVars)
4159 PVars->push_back(0);
4160 }
Douglas Gregord3731192011-01-10 07:32:04 +00004161
Chad Rosier4a9d7952012-08-08 18:46:20 +00004162 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004163 // expansion.
4164 OldType = Expansion->getPattern();
4165 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004166 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4167 NewType = getDerived().TransformType(OldType);
4168 } else {
4169 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004170 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004171
Douglas Gregor603cfb42011-01-05 23:12:31 +00004172 if (NewType.isNull())
4173 return true;
4174
4175 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004176 NewType = getSema().Context.getPackExpansionType(NewType,
4177 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004178
Douglas Gregora009b592011-01-07 00:20:55 +00004179 OutParamTypes.push_back(NewType);
4180 if (PVars)
4181 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004182 }
4183
John McCallfb44de92011-05-01 22:35:37 +00004184#ifndef NDEBUG
4185 if (PVars) {
4186 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4187 if (ParmVarDecl *parm = (*PVars)[i])
4188 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004189 }
John McCallfb44de92011-05-01 22:35:37 +00004190#endif
4191
4192 return false;
4193}
John McCall21ef0fa2010-03-11 09:03:00 +00004194
4195template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004196QualType
John McCalla2becad2009-10-21 00:40:46 +00004197TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004198 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004199 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4200}
4201
4202template<typename Derived>
4203QualType
4204TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4205 FunctionProtoTypeLoc TL,
4206 CXXRecordDecl *ThisContext,
4207 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004208 // Transform the parameters and return type.
4209 //
Richard Smithe6975e92012-04-17 00:58:00 +00004210 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004211 // When the function has a trailing return type, we instantiate the
4212 // parameters before the return type, since the return type can then refer
4213 // to the parameters themselves (via decltype, sizeof, etc.).
4214 //
Chris Lattner686775d2011-07-20 06:58:45 +00004215 SmallVector<QualType, 4> ParamTypes;
4216 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004217 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004218
Douglas Gregordab60ad2010-10-01 18:44:50 +00004219 QualType ResultType;
4220
Richard Smith9fbf3272012-08-14 22:51:13 +00004221 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004222 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004223 TL.getParmArray(),
4224 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004225 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004226 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004227 return QualType();
4228
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004229 {
4230 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004231 // If a declaration declares a member function or member function
4232 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004233 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004234 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004235 // declarator.
4236 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004237
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004238 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4239 if (ResultType.isNull())
4240 return QualType();
4241 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004242 }
4243 else {
4244 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4245 if (ResultType.isNull())
4246 return QualType();
4247
Chad Rosier4a9d7952012-08-08 18:46:20 +00004248 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004249 TL.getParmArray(),
4250 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004251 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004252 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004253 return QualType();
4254 }
4255
Richard Smithe6975e92012-04-17 00:58:00 +00004256 // FIXME: Need to transform the exception-specification too.
4257
John McCalla2becad2009-10-21 00:40:46 +00004258 QualType Result = TL.getType();
4259 if (getDerived().AlwaysRebuild() ||
4260 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004261 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004262 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4263 Result = getDerived().RebuildFunctionProtoType(ResultType,
4264 ParamTypes.data(),
4265 ParamTypes.size(),
4266 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004267 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004268 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004269 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004270 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004271 if (Result.isNull())
4272 return QualType();
4273 }
Mike Stump1eb44332009-09-09 15:08:12 +00004274
John McCalla2becad2009-10-21 00:40:46 +00004275 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004276 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004277 NewTL.setLParenLoc(TL.getLParenLoc());
4278 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004279 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004280 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4281 NewTL.setArg(i, ParamDecls[i]);
4282
4283 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004284}
Mike Stump1eb44332009-09-09 15:08:12 +00004285
Douglas Gregor577f75a2009-08-04 16:50:30 +00004286template<typename Derived>
4287QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004288 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004289 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004290 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004291 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4292 if (ResultType.isNull())
4293 return QualType();
4294
4295 QualType Result = TL.getType();
4296 if (getDerived().AlwaysRebuild() ||
4297 ResultType != T->getResultType())
4298 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4299
4300 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004301 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004302 NewTL.setLParenLoc(TL.getLParenLoc());
4303 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004304 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004305
4306 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004307}
Mike Stump1eb44332009-09-09 15:08:12 +00004308
John McCalled976492009-12-04 22:46:56 +00004309template<typename Derived> QualType
4310TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004311 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004312 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004313 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004314 if (!D)
4315 return QualType();
4316
4317 QualType Result = TL.getType();
4318 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4319 Result = getDerived().RebuildUnresolvedUsingType(D);
4320 if (Result.isNull())
4321 return QualType();
4322 }
4323
4324 // We might get an arbitrary type spec type back. We should at
4325 // least always get a type spec type, though.
4326 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4327 NewTL.setNameLoc(TL.getNameLoc());
4328
4329 return Result;
4330}
4331
Douglas Gregor577f75a2009-08-04 16:50:30 +00004332template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004333QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004334 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004335 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004336 TypedefNameDecl *Typedef
4337 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4338 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004339 if (!Typedef)
4340 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004341
John McCalla2becad2009-10-21 00:40:46 +00004342 QualType Result = TL.getType();
4343 if (getDerived().AlwaysRebuild() ||
4344 Typedef != T->getDecl()) {
4345 Result = getDerived().RebuildTypedefType(Typedef);
4346 if (Result.isNull())
4347 return QualType();
4348 }
Mike Stump1eb44332009-09-09 15:08:12 +00004349
John McCalla2becad2009-10-21 00:40:46 +00004350 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4351 NewTL.setNameLoc(TL.getNameLoc());
4352
4353 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004354}
Mike Stump1eb44332009-09-09 15:08:12 +00004355
Douglas Gregor577f75a2009-08-04 16:50:30 +00004356template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004357QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004358 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004359 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004360 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4361 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004362
John McCall60d7b3a2010-08-24 06:29:42 +00004363 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004364 if (E.isInvalid())
4365 return QualType();
4366
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004367 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4368 if (E.isInvalid())
4369 return QualType();
4370
John McCalla2becad2009-10-21 00:40:46 +00004371 QualType Result = TL.getType();
4372 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004373 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004374 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004375 if (Result.isNull())
4376 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004377 }
John McCalla2becad2009-10-21 00:40:46 +00004378 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004379
John McCalla2becad2009-10-21 00:40:46 +00004380 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004381 NewTL.setTypeofLoc(TL.getTypeofLoc());
4382 NewTL.setLParenLoc(TL.getLParenLoc());
4383 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004384
4385 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004386}
Mike Stump1eb44332009-09-09 15:08:12 +00004387
4388template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004389QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004390 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004391 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4392 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4393 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004394 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004395
John McCalla2becad2009-10-21 00:40:46 +00004396 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004397 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4398 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004399 if (Result.isNull())
4400 return QualType();
4401 }
Mike Stump1eb44332009-09-09 15:08:12 +00004402
John McCalla2becad2009-10-21 00:40:46 +00004403 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004404 NewTL.setTypeofLoc(TL.getTypeofLoc());
4405 NewTL.setLParenLoc(TL.getLParenLoc());
4406 NewTL.setRParenLoc(TL.getRParenLoc());
4407 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004408
4409 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004410}
Mike Stump1eb44332009-09-09 15:08:12 +00004411
4412template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004413QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004414 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004415 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004416
Douglas Gregor670444e2009-08-04 22:27:00 +00004417 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004418 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4419 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004420
John McCall60d7b3a2010-08-24 06:29:42 +00004421 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004422 if (E.isInvalid())
4423 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004424
Richard Smith76f3f692012-02-22 02:04:18 +00004425 E = getSema().ActOnDecltypeExpression(E.take());
4426 if (E.isInvalid())
4427 return QualType();
4428
John McCalla2becad2009-10-21 00:40:46 +00004429 QualType Result = TL.getType();
4430 if (getDerived().AlwaysRebuild() ||
4431 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004432 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004433 if (Result.isNull())
4434 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004435 }
John McCalla2becad2009-10-21 00:40:46 +00004436 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004437
John McCalla2becad2009-10-21 00:40:46 +00004438 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4439 NewTL.setNameLoc(TL.getNameLoc());
4440
4441 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004442}
4443
4444template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004445QualType TreeTransform<Derived>::TransformUnaryTransformType(
4446 TypeLocBuilder &TLB,
4447 UnaryTransformTypeLoc TL) {
4448 QualType Result = TL.getType();
4449 if (Result->isDependentType()) {
4450 const UnaryTransformType *T = TL.getTypePtr();
4451 QualType NewBase =
4452 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4453 Result = getDerived().RebuildUnaryTransformType(NewBase,
4454 T->getUTTKind(),
4455 TL.getKWLoc());
4456 if (Result.isNull())
4457 return QualType();
4458 }
4459
4460 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4461 NewTL.setKWLoc(TL.getKWLoc());
4462 NewTL.setParensRange(TL.getParensRange());
4463 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4464 return Result;
4465}
4466
4467template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004468QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4469 AutoTypeLoc TL) {
4470 const AutoType *T = TL.getTypePtr();
4471 QualType OldDeduced = T->getDeducedType();
4472 QualType NewDeduced;
4473 if (!OldDeduced.isNull()) {
4474 NewDeduced = getDerived().TransformType(OldDeduced);
4475 if (NewDeduced.isNull())
4476 return QualType();
4477 }
4478
4479 QualType Result = TL.getType();
4480 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4481 Result = getDerived().RebuildAutoType(NewDeduced);
4482 if (Result.isNull())
4483 return QualType();
4484 }
4485
4486 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4487 NewTL.setNameLoc(TL.getNameLoc());
4488
4489 return Result;
4490}
4491
4492template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004493QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004494 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004495 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004496 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004497 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4498 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004499 if (!Record)
4500 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004501
John McCalla2becad2009-10-21 00:40:46 +00004502 QualType Result = TL.getType();
4503 if (getDerived().AlwaysRebuild() ||
4504 Record != T->getDecl()) {
4505 Result = getDerived().RebuildRecordType(Record);
4506 if (Result.isNull())
4507 return QualType();
4508 }
Mike Stump1eb44332009-09-09 15:08:12 +00004509
John McCalla2becad2009-10-21 00:40:46 +00004510 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4511 NewTL.setNameLoc(TL.getNameLoc());
4512
4513 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004514}
Mike Stump1eb44332009-09-09 15:08:12 +00004515
4516template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004517QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004518 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004519 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004520 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004521 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4522 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004523 if (!Enum)
4524 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004525
John McCalla2becad2009-10-21 00:40:46 +00004526 QualType Result = TL.getType();
4527 if (getDerived().AlwaysRebuild() ||
4528 Enum != T->getDecl()) {
4529 Result = getDerived().RebuildEnumType(Enum);
4530 if (Result.isNull())
4531 return QualType();
4532 }
Mike Stump1eb44332009-09-09 15:08:12 +00004533
John McCalla2becad2009-10-21 00:40:46 +00004534 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4535 NewTL.setNameLoc(TL.getNameLoc());
4536
4537 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004538}
John McCall7da24312009-09-05 00:15:47 +00004539
John McCall3cb0ebd2010-03-10 03:28:59 +00004540template<typename Derived>
4541QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4542 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004543 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004544 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4545 TL.getTypePtr()->getDecl());
4546 if (!D) return QualType();
4547
4548 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4549 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4550 return T;
4551}
4552
Douglas Gregor577f75a2009-08-04 16:50:30 +00004553template<typename Derived>
4554QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004555 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004556 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004557 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004558}
4559
Mike Stump1eb44332009-09-09 15:08:12 +00004560template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004561QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004562 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004563 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004564 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004565
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004566 // Substitute into the replacement type, which itself might involve something
4567 // that needs to be transformed. This only tends to occur with default
4568 // template arguments of template template parameters.
4569 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4570 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4571 if (Replacement.isNull())
4572 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004573
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004574 // Always canonicalize the replacement type.
4575 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4576 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004577 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004578 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004579
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004580 // Propagate type-source information.
4581 SubstTemplateTypeParmTypeLoc NewTL
4582 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4583 NewTL.setNameLoc(TL.getNameLoc());
4584 return Result;
4585
John McCall49a832b2009-10-18 09:09:24 +00004586}
4587
4588template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004589QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4590 TypeLocBuilder &TLB,
4591 SubstTemplateTypeParmPackTypeLoc TL) {
4592 return TransformTypeSpecType(TLB, TL);
4593}
4594
4595template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004596QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004597 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004598 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004599 const TemplateSpecializationType *T = TL.getTypePtr();
4600
Douglas Gregor1d752d72011-03-02 18:46:51 +00004601 // The nested-name-specifier never matters in a TemplateSpecializationType,
4602 // because we can't have a dependent nested-name-specifier anyway.
4603 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004604 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004605 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4606 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004607 if (Template.isNull())
4608 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004609
John McCall43fed0d2010-11-12 08:19:04 +00004610 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4611}
4612
Eli Friedmanb001de72011-10-06 23:00:33 +00004613template<typename Derived>
4614QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4615 AtomicTypeLoc TL) {
4616 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4617 if (ValueType.isNull())
4618 return QualType();
4619
4620 QualType Result = TL.getType();
4621 if (getDerived().AlwaysRebuild() ||
4622 ValueType != TL.getValueLoc().getType()) {
4623 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4624 if (Result.isNull())
4625 return QualType();
4626 }
4627
4628 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4629 NewTL.setKWLoc(TL.getKWLoc());
4630 NewTL.setLParenLoc(TL.getLParenLoc());
4631 NewTL.setRParenLoc(TL.getRParenLoc());
4632
4633 return Result;
4634}
4635
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004636namespace {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004637 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004638 /// container that provides a \c getArgLoc() member function.
4639 ///
4640 /// This iterator is intended to be used with the iterator form of
4641 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4642 template<typename ArgLocContainer>
4643 class TemplateArgumentLocContainerIterator {
4644 ArgLocContainer *Container;
4645 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004646
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004647 public:
4648 typedef TemplateArgumentLoc value_type;
4649 typedef TemplateArgumentLoc reference;
4650 typedef int difference_type;
4651 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004652
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004653 class pointer {
4654 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004655
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004656 public:
4657 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004658
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004659 const TemplateArgumentLoc *operator->() const {
4660 return &Arg;
4661 }
4662 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004663
4664
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004665 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004666
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004667 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4668 unsigned Index)
4669 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004670
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004671 TemplateArgumentLocContainerIterator &operator++() {
4672 ++Index;
4673 return *this;
4674 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004675
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004676 TemplateArgumentLocContainerIterator operator++(int) {
4677 TemplateArgumentLocContainerIterator Old(*this);
4678 ++(*this);
4679 return Old;
4680 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004681
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004682 TemplateArgumentLoc operator*() const {
4683 return Container->getArgLoc(Index);
4684 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004685
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004686 pointer operator->() const {
4687 return pointer(Container->getArgLoc(Index));
4688 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004689
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004690 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004691 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004692 return X.Container == Y.Container && X.Index == Y.Index;
4693 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004694
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004695 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004696 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004697 return !(X == Y);
4698 }
4699 };
4700}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004701
4702
John McCall43fed0d2010-11-12 08:19:04 +00004703template <typename Derived>
4704QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4705 TypeLocBuilder &TLB,
4706 TemplateSpecializationTypeLoc TL,
4707 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004708 TemplateArgumentListInfo NewTemplateArgs;
4709 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4710 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004711 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4712 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004713 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004714 ArgIterator(TL, TL.getNumArgs()),
4715 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004716 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004717
John McCall833ca992009-10-29 08:12:44 +00004718 // FIXME: maybe don't rebuild if all the template arguments are the same.
4719
4720 QualType Result =
4721 getDerived().RebuildTemplateSpecializationType(Template,
4722 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004723 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004724
4725 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004726 // Specializations of template template parameters are represented as
4727 // TemplateSpecializationTypes, and substitution of type alias templates
4728 // within a dependent context can transform them into
4729 // DependentTemplateSpecializationTypes.
4730 if (isa<DependentTemplateSpecializationType>(Result)) {
4731 DependentTemplateSpecializationTypeLoc NewTL
4732 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004733 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004734 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004735 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004736 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004737 NewTL.setLAngleLoc(TL.getLAngleLoc());
4738 NewTL.setRAngleLoc(TL.getRAngleLoc());
4739 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4740 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4741 return Result;
4742 }
4743
John McCall833ca992009-10-29 08:12:44 +00004744 TemplateSpecializationTypeLoc NewTL
4745 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004746 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004747 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4748 NewTL.setLAngleLoc(TL.getLAngleLoc());
4749 NewTL.setRAngleLoc(TL.getRAngleLoc());
4750 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4751 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004752 }
Mike Stump1eb44332009-09-09 15:08:12 +00004753
John McCall833ca992009-10-29 08:12:44 +00004754 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004755}
Mike Stump1eb44332009-09-09 15:08:12 +00004756
Douglas Gregora88f09f2011-02-28 17:23:35 +00004757template <typename Derived>
4758QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4759 TypeLocBuilder &TLB,
4760 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004761 TemplateName Template,
4762 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004763 TemplateArgumentListInfo NewTemplateArgs;
4764 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4765 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4766 typedef TemplateArgumentLocContainerIterator<
4767 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004768 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004769 ArgIterator(TL, TL.getNumArgs()),
4770 NewTemplateArgs))
4771 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004772
Douglas Gregora88f09f2011-02-28 17:23:35 +00004773 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004774
Douglas Gregora88f09f2011-02-28 17:23:35 +00004775 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4776 QualType Result
4777 = getSema().Context.getDependentTemplateSpecializationType(
4778 TL.getTypePtr()->getKeyword(),
4779 DTN->getQualifier(),
4780 DTN->getIdentifier(),
4781 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004782
Douglas Gregora88f09f2011-02-28 17:23:35 +00004783 DependentTemplateSpecializationTypeLoc NewTL
4784 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004785 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004786 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004787 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004788 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004789 NewTL.setLAngleLoc(TL.getLAngleLoc());
4790 NewTL.setRAngleLoc(TL.getRAngleLoc());
4791 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4792 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4793 return Result;
4794 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004795
4796 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004797 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004798 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004799 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004800
Douglas Gregora88f09f2011-02-28 17:23:35 +00004801 if (!Result.isNull()) {
4802 /// FIXME: Wrap this in an elaborated-type-specifier?
4803 TemplateSpecializationTypeLoc NewTL
4804 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004805 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004806 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004807 NewTL.setLAngleLoc(TL.getLAngleLoc());
4808 NewTL.setRAngleLoc(TL.getRAngleLoc());
4809 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4810 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4811 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004812
Douglas Gregora88f09f2011-02-28 17:23:35 +00004813 return Result;
4814}
4815
Mike Stump1eb44332009-09-09 15:08:12 +00004816template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004817QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004818TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004819 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004820 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004821
Douglas Gregor9e876872011-03-01 18:12:44 +00004822 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004823 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004824 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004825 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004826 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4827 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004828 return QualType();
4829 }
Mike Stump1eb44332009-09-09 15:08:12 +00004830
John McCall43fed0d2010-11-12 08:19:04 +00004831 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4832 if (NamedT.isNull())
4833 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004834
Richard Smith3e4c6c42011-05-05 21:57:07 +00004835 // C++0x [dcl.type.elab]p2:
4836 // If the identifier resolves to a typedef-name or the simple-template-id
4837 // resolves to an alias template specialization, the
4838 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004839 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4840 if (const TemplateSpecializationType *TST =
4841 NamedT->getAs<TemplateSpecializationType>()) {
4842 TemplateName Template = TST->getTemplateName();
4843 if (TypeAliasTemplateDecl *TAT =
4844 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4845 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4846 diag::err_tag_reference_non_tag) << 4;
4847 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4848 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004849 }
4850 }
4851
John McCalla2becad2009-10-21 00:40:46 +00004852 QualType Result = TL.getType();
4853 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004854 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004855 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004856 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004857 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004858 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004859 if (Result.isNull())
4860 return QualType();
4861 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004862
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004863 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004864 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004865 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004866 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004867}
Mike Stump1eb44332009-09-09 15:08:12 +00004868
4869template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004870QualType TreeTransform<Derived>::TransformAttributedType(
4871 TypeLocBuilder &TLB,
4872 AttributedTypeLoc TL) {
4873 const AttributedType *oldType = TL.getTypePtr();
4874 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4875 if (modifiedType.isNull())
4876 return QualType();
4877
4878 QualType result = TL.getType();
4879
4880 // FIXME: dependent operand expressions?
4881 if (getDerived().AlwaysRebuild() ||
4882 modifiedType != oldType->getModifiedType()) {
4883 // TODO: this is really lame; we should really be rebuilding the
4884 // equivalent type from first principles.
4885 QualType equivalentType
4886 = getDerived().TransformType(oldType->getEquivalentType());
4887 if (equivalentType.isNull())
4888 return QualType();
4889 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4890 modifiedType,
4891 equivalentType);
4892 }
4893
4894 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4895 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4896 if (TL.hasAttrOperand())
4897 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4898 if (TL.hasAttrExprOperand())
4899 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4900 else if (TL.hasAttrEnumOperand())
4901 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4902
4903 return result;
4904}
4905
4906template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004907QualType
4908TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4909 ParenTypeLoc TL) {
4910 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4911 if (Inner.isNull())
4912 return QualType();
4913
4914 QualType Result = TL.getType();
4915 if (getDerived().AlwaysRebuild() ||
4916 Inner != TL.getInnerLoc().getType()) {
4917 Result = getDerived().RebuildParenType(Inner);
4918 if (Result.isNull())
4919 return QualType();
4920 }
4921
4922 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4923 NewTL.setLParenLoc(TL.getLParenLoc());
4924 NewTL.setRParenLoc(TL.getRParenLoc());
4925 return Result;
4926}
4927
4928template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004929QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004930 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004931 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004932
Douglas Gregor2494dd02011-03-01 01:34:45 +00004933 NestedNameSpecifierLoc QualifierLoc
4934 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4935 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004936 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004937
John McCall33500952010-06-11 00:33:02 +00004938 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004939 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004940 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004941 QualifierLoc,
4942 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004943 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004944 if (Result.isNull())
4945 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004946
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004947 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4948 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004949 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4950
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004951 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004952 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004953 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004954 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004955 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004956 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004957 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004958 NewTL.setNameLoc(TL.getNameLoc());
4959 }
John McCalla2becad2009-10-21 00:40:46 +00004960 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004961}
Mike Stump1eb44332009-09-09 15:08:12 +00004962
Douglas Gregor577f75a2009-08-04 16:50:30 +00004963template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004964QualType TreeTransform<Derived>::
4965 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004966 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004967 NestedNameSpecifierLoc QualifierLoc;
4968 if (TL.getQualifierLoc()) {
4969 QualifierLoc
4970 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4971 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004972 return QualType();
4973 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004974
John McCall43fed0d2010-11-12 08:19:04 +00004975 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004976 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004977}
4978
4979template<typename Derived>
4980QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004981TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4982 DependentTemplateSpecializationTypeLoc TL,
4983 NestedNameSpecifierLoc QualifierLoc) {
4984 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004985
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004986 TemplateArgumentListInfo NewTemplateArgs;
4987 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4988 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004989
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004990 typedef TemplateArgumentLocContainerIterator<
4991 DependentTemplateSpecializationTypeLoc> ArgIterator;
4992 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4993 ArgIterator(TL, TL.getNumArgs()),
4994 NewTemplateArgs))
4995 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004996
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004997 QualType Result
4998 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4999 QualifierLoc,
5000 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005001 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005002 NewTemplateArgs);
5003 if (Result.isNull())
5004 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005005
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005006 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5007 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005008
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005009 // Copy information relevant to the template specialization.
5010 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005011 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005012 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005013 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005014 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5015 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005016 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005017 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005018
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005019 // Copy information relevant to the elaborated type.
5020 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005021 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005022 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005023 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5024 DependentTemplateSpecializationTypeLoc SpecTL
5025 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005026 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005027 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005028 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005029 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005030 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5031 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005032 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005033 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005034 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005035 TemplateSpecializationTypeLoc SpecTL
5036 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005037 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005038 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005039 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5040 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005041 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005042 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005043 }
5044 return Result;
5045}
5046
5047template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005048QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5049 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005050 QualType Pattern
5051 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005052 if (Pattern.isNull())
5053 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005054
5055 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005056 if (getDerived().AlwaysRebuild() ||
5057 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005058 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005059 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005060 TL.getEllipsisLoc(),
5061 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005062 if (Result.isNull())
5063 return QualType();
5064 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005065
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005066 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5067 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5068 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005069}
5070
5071template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005072QualType
5073TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005074 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005075 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005076 TLB.pushFullCopy(TL);
5077 return TL.getType();
5078}
5079
5080template<typename Derived>
5081QualType
5082TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005083 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005084 // ObjCObjectType is never dependent.
5085 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005086 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005087}
Mike Stump1eb44332009-09-09 15:08:12 +00005088
5089template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005090QualType
5091TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005092 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005093 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005094 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005095 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005096}
5097
Douglas Gregor577f75a2009-08-04 16:50:30 +00005098//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005099// Statement transformation
5100//===----------------------------------------------------------------------===//
5101template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005102StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005103TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005104 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005105}
5106
5107template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005108StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005109TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5110 return getDerived().TransformCompoundStmt(S, false);
5111}
5112
5113template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005114StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005115TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005116 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005117 Sema::CompoundScopeRAII CompoundScope(getSema());
5118
John McCall7114cba2010-08-27 19:56:05 +00005119 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005120 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005121 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005122 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5123 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005124 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005125 if (Result.isInvalid()) {
5126 // Immediately fail if this was a DeclStmt, since it's very
5127 // likely that this will cause problems for future statements.
5128 if (isa<DeclStmt>(*B))
5129 return StmtError();
5130
5131 // Otherwise, just keep processing substatements and fail later.
5132 SubStmtInvalid = true;
5133 continue;
5134 }
Mike Stump1eb44332009-09-09 15:08:12 +00005135
Douglas Gregor43959a92009-08-20 07:17:43 +00005136 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5137 Statements.push_back(Result.takeAs<Stmt>());
5138 }
Mike Stump1eb44332009-09-09 15:08:12 +00005139
John McCall7114cba2010-08-27 19:56:05 +00005140 if (SubStmtInvalid)
5141 return StmtError();
5142
Douglas Gregor43959a92009-08-20 07:17:43 +00005143 if (!getDerived().AlwaysRebuild() &&
5144 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005145 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005146
5147 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005148 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005149 S->getRBracLoc(),
5150 IsStmtExpr);
5151}
Mike Stump1eb44332009-09-09 15:08:12 +00005152
Douglas Gregor43959a92009-08-20 07:17:43 +00005153template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005154StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005155TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005156 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005157 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005158 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5159 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005160
Eli Friedman264c1f82009-11-19 03:14:00 +00005161 // Transform the left-hand case value.
5162 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005163 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005164 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005165 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005166
Eli Friedman264c1f82009-11-19 03:14:00 +00005167 // Transform the right-hand case value (for the GNU case-range extension).
5168 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005169 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005170 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005171 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005172 }
Mike Stump1eb44332009-09-09 15:08:12 +00005173
Douglas Gregor43959a92009-08-20 07:17:43 +00005174 // Build the case statement.
5175 // Case statements are always rebuilt so that they will attached to their
5176 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005177 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005178 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005179 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005180 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005181 S->getColonLoc());
5182 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005183 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005184
Douglas Gregor43959a92009-08-20 07:17:43 +00005185 // Transform the statement following the 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 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005191 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005192}
5193
5194template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005195StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005196TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005197 // Transform the statement following the default case
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
Douglas Gregor43959a92009-08-20 07:17:43 +00005202 // Default statements are always rebuilt
5203 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005204 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005205}
Mike Stump1eb44332009-09-09 15:08:12 +00005206
Douglas Gregor43959a92009-08-20 07:17:43 +00005207template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005208StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005209TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005210 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005211 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005212 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005213
Chris Lattner57ad3782011-02-17 20:34:02 +00005214 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5215 S->getDecl());
5216 if (!LD)
5217 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005218
5219
Douglas Gregor43959a92009-08-20 07:17:43 +00005220 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005221 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005222 cast<LabelDecl>(LD), SourceLocation(),
5223 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005224}
Mike Stump1eb44332009-09-09 15:08:12 +00005225
Douglas Gregor43959a92009-08-20 07:17:43 +00005226template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005227StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005228TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5229 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5230 if (SubStmt.isInvalid())
5231 return StmtError();
5232
5233 // TODO: transform attributes
5234 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5235 return S;
5236
5237 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5238 S->getAttrs(),
5239 SubStmt.get());
5240}
5241
5242template<typename Derived>
5243StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005244TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005245 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005246 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005247 VarDecl *ConditionVar = 0;
5248 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005249 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005250 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005251 getDerived().TransformDefinition(
5252 S->getConditionVariable()->getLocation(),
5253 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005254 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005255 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005256 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005257 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005258
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005259 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005260 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005261
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005262 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005263 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005264 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005265 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005266 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005267 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005268
John McCall9ae2f072010-08-23 23:25:46 +00005269 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005270 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005271 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005272
John McCall9ae2f072010-08-23 23:25:46 +00005273 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5274 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005275 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005276
Douglas Gregor43959a92009-08-20 07:17:43 +00005277 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005278 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005279 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005280 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005281
Douglas Gregor43959a92009-08-20 07:17:43 +00005282 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005283 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005284 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005285 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005286
Douglas Gregor43959a92009-08-20 07:17:43 +00005287 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005288 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005289 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005290 Then.get() == S->getThen() &&
5291 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005292 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005293
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005294 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005295 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005296 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005297}
5298
5299template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005300StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005301TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005302 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005303 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005304 VarDecl *ConditionVar = 0;
5305 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005306 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005307 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005308 getDerived().TransformDefinition(
5309 S->getConditionVariable()->getLocation(),
5310 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005311 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005312 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005313 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005314 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005315
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005316 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005317 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005318 }
Mike Stump1eb44332009-09-09 15:08:12 +00005319
Douglas Gregor43959a92009-08-20 07:17:43 +00005320 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005321 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005322 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005323 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005324 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005325 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005326
Douglas Gregor43959a92009-08-20 07:17:43 +00005327 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005328 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005329 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005330 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005331
Douglas Gregor43959a92009-08-20 07:17:43 +00005332 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005333 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5334 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005335}
Mike Stump1eb44332009-09-09 15:08:12 +00005336
Douglas Gregor43959a92009-08-20 07:17:43 +00005337template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005338StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005339TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005340 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005341 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005342 VarDecl *ConditionVar = 0;
5343 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005344 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005345 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005346 getDerived().TransformDefinition(
5347 S->getConditionVariable()->getLocation(),
5348 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005349 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005350 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005351 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005352 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005353
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005354 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005355 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005356
5357 if (S->getCond()) {
5358 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005359 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005360 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005361 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005362 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005363 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005364 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005365 }
Mike Stump1eb44332009-09-09 15:08:12 +00005366
John McCall9ae2f072010-08-23 23:25:46 +00005367 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5368 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005369 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005370
Douglas Gregor43959a92009-08-20 07:17:43 +00005371 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005372 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005373 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005374 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005375
Douglas Gregor43959a92009-08-20 07:17:43 +00005376 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005377 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005378 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005379 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005380 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005381
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005382 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005383 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005384}
Mike Stump1eb44332009-09-09 15:08:12 +00005385
Douglas Gregor43959a92009-08-20 07:17:43 +00005386template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005387StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005388TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005389 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005390 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005391 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005392 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005393
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005394 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005395 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005396 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005397 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005398
Douglas Gregor43959a92009-08-20 07:17:43 +00005399 if (!getDerived().AlwaysRebuild() &&
5400 Cond.get() == S->getCond() &&
5401 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005402 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005403
John McCall9ae2f072010-08-23 23:25:46 +00005404 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5405 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005406 S->getRParenLoc());
5407}
Mike Stump1eb44332009-09-09 15:08:12 +00005408
Douglas Gregor43959a92009-08-20 07:17:43 +00005409template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005410StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005411TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005412 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005413 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005414 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005415 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005416
Douglas Gregor43959a92009-08-20 07:17:43 +00005417 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005418 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005419 VarDecl *ConditionVar = 0;
5420 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005421 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005422 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005423 getDerived().TransformDefinition(
5424 S->getConditionVariable()->getLocation(),
5425 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005426 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005427 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005428 } else {
5429 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005430
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005431 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005432 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005433
5434 if (S->getCond()) {
5435 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005436 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005437 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005438 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005439 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005440
John McCall9ae2f072010-08-23 23:25:46 +00005441 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005442 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005443 }
Mike Stump1eb44332009-09-09 15:08:12 +00005444
Chad Rosier4a9d7952012-08-08 18:46:20 +00005445 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005446 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005447 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005448
Douglas Gregor43959a92009-08-20 07:17:43 +00005449 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005450 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005451 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005452 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005453
John McCall9ae2f072010-08-23 23:25:46 +00005454 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5455 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005456 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005457
Douglas Gregor43959a92009-08-20 07:17:43 +00005458 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005459 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005460 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005461 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005462
Douglas Gregor43959a92009-08-20 07:17:43 +00005463 if (!getDerived().AlwaysRebuild() &&
5464 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005465 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005466 Inc.get() == S->getInc() &&
5467 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005468 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005469
Douglas Gregor43959a92009-08-20 07:17:43 +00005470 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005471 Init.get(), FullCond, ConditionVar,
5472 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005473}
5474
5475template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005476StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005477TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005478 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5479 S->getLabel());
5480 if (!LD)
5481 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005482
Douglas Gregor43959a92009-08-20 07:17:43 +00005483 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005484 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005485 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005486}
5487
5488template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005489StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005490TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005491 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005492 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005493 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005494 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005495
Douglas Gregor43959a92009-08-20 07:17:43 +00005496 if (!getDerived().AlwaysRebuild() &&
5497 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005498 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005499
5500 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005501 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005502}
5503
5504template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005505StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005506TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005507 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005508}
Mike Stump1eb44332009-09-09 15:08:12 +00005509
Douglas Gregor43959a92009-08-20 07:17:43 +00005510template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005511StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005512TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005513 return SemaRef.Owned(S);
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>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005519 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005520 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005521 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005522
Mike Stump1eb44332009-09-09 15:08:12 +00005523 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005524 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005525 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005526}
Mike Stump1eb44332009-09-09 15:08:12 +00005527
Douglas Gregor43959a92009-08-20 07:17:43 +00005528template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005529StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005530TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005531 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005532 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005533 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5534 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005535 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5536 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005537 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005538 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005539
Douglas Gregor43959a92009-08-20 07:17:43 +00005540 if (Transformed != *D)
5541 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005542
Douglas Gregor43959a92009-08-20 07:17:43 +00005543 Decls.push_back(Transformed);
5544 }
Mike Stump1eb44332009-09-09 15:08:12 +00005545
Douglas Gregor43959a92009-08-20 07:17:43 +00005546 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005547 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005548
5549 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005550 S->getStartLoc(), S->getEndLoc());
5551}
Mike Stump1eb44332009-09-09 15:08:12 +00005552
Douglas Gregor43959a92009-08-20 07:17:43 +00005553template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005554StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005555TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005556
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005557 SmallVector<Expr*, 8> Constraints;
5558 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005559 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005560
John McCall60d7b3a2010-08-24 06:29:42 +00005561 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005562 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005563
5564 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005565
Anders Carlsson703e3942010-01-24 05:50:09 +00005566 // Go through the outputs.
5567 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005568 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005569
Anders Carlsson703e3942010-01-24 05:50:09 +00005570 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005571 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005572
Anders Carlsson703e3942010-01-24 05:50:09 +00005573 // Transform the output expr.
5574 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005575 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005576 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005577 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005578
Anders Carlsson703e3942010-01-24 05:50:09 +00005579 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005580
John McCall9ae2f072010-08-23 23:25:46 +00005581 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005582 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005583
Anders Carlsson703e3942010-01-24 05:50:09 +00005584 // Go through the inputs.
5585 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005586 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005587
Anders Carlsson703e3942010-01-24 05:50:09 +00005588 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005589 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005590
Anders Carlsson703e3942010-01-24 05:50:09 +00005591 // Transform the input expr.
5592 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005593 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005594 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005595 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005596
Anders Carlsson703e3942010-01-24 05:50:09 +00005597 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005598
John McCall9ae2f072010-08-23 23:25:46 +00005599 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005600 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005601
Anders Carlsson703e3942010-01-24 05:50:09 +00005602 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005603 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005604
5605 // Go through the clobbers.
5606 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005607 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005608
5609 // No need to transform the asm string literal.
5610 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005611 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5612 S->isVolatile(), S->getNumOutputs(),
5613 S->getNumInputs(), Names.data(),
5614 Constraints, Exprs, AsmString.get(),
5615 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005616}
5617
Chad Rosier8cd64b42012-06-11 20:47:18 +00005618template<typename Derived>
5619StmtResult
5620TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005621 ArrayRef<Token> AsmToks =
5622 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005623
Chad Rosier7bd092b2012-08-15 16:53:30 +00005624 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
5625 AsmToks, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005626}
Douglas Gregor43959a92009-08-20 07:17:43 +00005627
5628template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005629StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005630TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005631 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005632 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005633 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005634 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005635
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005636 // Transform the @catch statements (if present).
5637 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005638 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005639 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005640 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005641 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005642 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005643 if (Catch.get() != S->getCatchStmt(I))
5644 AnyCatchChanged = true;
5645 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005646 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005647
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005648 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005649 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005650 if (S->getFinallyStmt()) {
5651 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5652 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005653 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005654 }
5655
5656 // If nothing changed, just retain this statement.
5657 if (!getDerived().AlwaysRebuild() &&
5658 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005659 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005660 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005661 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005662
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005663 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005664 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005665 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005666}
Mike Stump1eb44332009-09-09 15:08:12 +00005667
Douglas Gregor43959a92009-08-20 07:17:43 +00005668template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005669StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005670TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005671 // Transform the @catch parameter, if there is one.
5672 VarDecl *Var = 0;
5673 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5674 TypeSourceInfo *TSInfo = 0;
5675 if (FromVar->getTypeSourceInfo()) {
5676 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5677 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005678 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005679 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005680
Douglas Gregorbe270a02010-04-26 17:57:08 +00005681 QualType T;
5682 if (TSInfo)
5683 T = TSInfo->getType();
5684 else {
5685 T = getDerived().TransformType(FromVar->getType());
5686 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005687 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005688 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005689
Douglas Gregorbe270a02010-04-26 17:57:08 +00005690 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5691 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005692 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005693 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005694
John McCall60d7b3a2010-08-24 06:29:42 +00005695 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005696 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005697 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005698
5699 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005700 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005701 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005702}
Mike Stump1eb44332009-09-09 15:08:12 +00005703
Douglas Gregor43959a92009-08-20 07:17:43 +00005704template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005705StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005706TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005707 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005708 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005709 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005710 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005711
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005712 // If nothing changed, just retain this statement.
5713 if (!getDerived().AlwaysRebuild() &&
5714 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005715 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005716
5717 // Build a new statement.
5718 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005719 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005720}
Mike Stump1eb44332009-09-09 15:08:12 +00005721
Douglas Gregor43959a92009-08-20 07:17:43 +00005722template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005723StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005724TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005725 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005726 if (S->getThrowExpr()) {
5727 Operand = getDerived().TransformExpr(S->getThrowExpr());
5728 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005729 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005730 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005731
Douglas Gregord1377b22010-04-22 21:44:01 +00005732 if (!getDerived().AlwaysRebuild() &&
5733 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005734 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005735
John McCall9ae2f072010-08-23 23:25:46 +00005736 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005737}
Mike Stump1eb44332009-09-09 15:08:12 +00005738
Douglas Gregor43959a92009-08-20 07:17:43 +00005739template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005740StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005741TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005742 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005743 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005744 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005745 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005746 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005747 Object =
5748 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5749 Object.get());
5750 if (Object.isInvalid())
5751 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005752
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005753 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005754 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005755 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005756 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005757
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005758 // If nothing change, just retain the current statement.
5759 if (!getDerived().AlwaysRebuild() &&
5760 Object.get() == S->getSynchExpr() &&
5761 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005762 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005763
5764 // Build a new statement.
5765 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005766 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005767}
5768
5769template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005770StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005771TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5772 ObjCAutoreleasePoolStmt *S) {
5773 // Transform the body.
5774 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5775 if (Body.isInvalid())
5776 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005777
John McCallf85e1932011-06-15 23:02:42 +00005778 // If nothing changed, just retain this statement.
5779 if (!getDerived().AlwaysRebuild() &&
5780 Body.get() == S->getSubStmt())
5781 return SemaRef.Owned(S);
5782
5783 // Build a new statement.
5784 return getDerived().RebuildObjCAutoreleasePoolStmt(
5785 S->getAtLoc(), Body.get());
5786}
5787
5788template<typename Derived>
5789StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005790TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005791 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005792 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005793 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005794 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005795 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005796
Douglas Gregorc3203e72010-04-22 23:10:45 +00005797 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005798 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005799 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005800 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005801
Douglas Gregorc3203e72010-04-22 23:10:45 +00005802 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005803 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005804 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005805 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005806
Douglas Gregorc3203e72010-04-22 23:10:45 +00005807 // If nothing changed, just retain this statement.
5808 if (!getDerived().AlwaysRebuild() &&
5809 Element.get() == S->getElement() &&
5810 Collection.get() == S->getCollection() &&
5811 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005812 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005813
Douglas Gregorc3203e72010-04-22 23:10:45 +00005814 // Build a new statement.
5815 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005816 Element.get(),
5817 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005818 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005819 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005820}
5821
5822
5823template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005824StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005825TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5826 // Transform the exception declaration, if any.
5827 VarDecl *Var = 0;
5828 if (S->getExceptionDecl()) {
5829 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005830 TypeSourceInfo *T = getDerived().TransformType(
5831 ExceptionDecl->getTypeSourceInfo());
5832 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005833 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005834
Douglas Gregor83cb9422010-09-09 17:09:21 +00005835 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005836 ExceptionDecl->getInnerLocStart(),
5837 ExceptionDecl->getLocation(),
5838 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005839 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005840 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005841 }
Mike Stump1eb44332009-09-09 15:08:12 +00005842
Douglas Gregor43959a92009-08-20 07:17:43 +00005843 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005844 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005845 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005846 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005847
Douglas Gregor43959a92009-08-20 07:17:43 +00005848 if (!getDerived().AlwaysRebuild() &&
5849 !Var &&
5850 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005851 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005852
5853 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5854 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005855 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005856}
Mike Stump1eb44332009-09-09 15:08:12 +00005857
Douglas Gregor43959a92009-08-20 07:17:43 +00005858template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005859StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005860TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5861 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005862 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005863 = getDerived().TransformCompoundStmt(S->getTryBlock());
5864 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005865 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005866
Douglas Gregor43959a92009-08-20 07:17:43 +00005867 // Transform the handlers.
5868 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005869 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00005870 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005871 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005872 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5873 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005874 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005875
Douglas Gregor43959a92009-08-20 07:17:43 +00005876 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5877 Handlers.push_back(Handler.takeAs<Stmt>());
5878 }
Mike Stump1eb44332009-09-09 15:08:12 +00005879
Douglas Gregor43959a92009-08-20 07:17:43 +00005880 if (!getDerived().AlwaysRebuild() &&
5881 TryBlock.get() == S->getTryBlock() &&
5882 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005883 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005884
John McCall9ae2f072010-08-23 23:25:46 +00005885 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005886 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00005887}
Mike Stump1eb44332009-09-09 15:08:12 +00005888
Richard Smithad762fc2011-04-14 22:09:26 +00005889template<typename Derived>
5890StmtResult
5891TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5892 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5893 if (Range.isInvalid())
5894 return StmtError();
5895
5896 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5897 if (BeginEnd.isInvalid())
5898 return StmtError();
5899
5900 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5901 if (Cond.isInvalid())
5902 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005903 if (Cond.get())
5904 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5905 if (Cond.isInvalid())
5906 return StmtError();
5907 if (Cond.get())
5908 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005909
5910 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5911 if (Inc.isInvalid())
5912 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005913 if (Inc.get())
5914 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005915
5916 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5917 if (LoopVar.isInvalid())
5918 return StmtError();
5919
5920 StmtResult NewStmt = S;
5921 if (getDerived().AlwaysRebuild() ||
5922 Range.get() != S->getRangeStmt() ||
5923 BeginEnd.get() != S->getBeginEndStmt() ||
5924 Cond.get() != S->getCond() ||
5925 Inc.get() != S->getInc() ||
5926 LoopVar.get() != S->getLoopVarStmt())
5927 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5928 S->getColonLoc(), Range.get(),
5929 BeginEnd.get(), Cond.get(),
5930 Inc.get(), LoopVar.get(),
5931 S->getRParenLoc());
5932
5933 StmtResult Body = getDerived().TransformStmt(S->getBody());
5934 if (Body.isInvalid())
5935 return StmtError();
5936
5937 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5938 // it now so we have a new statement to attach the body to.
5939 if (Body.get() != S->getBody() && NewStmt.get() == S)
5940 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5941 S->getColonLoc(), Range.get(),
5942 BeginEnd.get(), Cond.get(),
5943 Inc.get(), LoopVar.get(),
5944 S->getRParenLoc());
5945
5946 if (NewStmt.get() == S)
5947 return SemaRef.Owned(S);
5948
5949 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5950}
5951
John Wiegley28bbe4b2011-04-28 01:08:34 +00005952template<typename Derived>
5953StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005954TreeTransform<Derived>::TransformMSDependentExistsStmt(
5955 MSDependentExistsStmt *S) {
5956 // Transform the nested-name-specifier, if any.
5957 NestedNameSpecifierLoc QualifierLoc;
5958 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005959 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00005960 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5961 if (!QualifierLoc)
5962 return StmtError();
5963 }
5964
5965 // Transform the declaration name.
5966 DeclarationNameInfo NameInfo = S->getNameInfo();
5967 if (NameInfo.getName()) {
5968 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5969 if (!NameInfo.getName())
5970 return StmtError();
5971 }
5972
5973 // Check whether anything changed.
5974 if (!getDerived().AlwaysRebuild() &&
5975 QualifierLoc == S->getQualifierLoc() &&
5976 NameInfo.getName() == S->getNameInfo().getName())
5977 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005978
Douglas Gregorba0513d2011-10-25 01:33:02 +00005979 // Determine whether this name exists, if we can.
5980 CXXScopeSpec SS;
5981 SS.Adopt(QualifierLoc);
5982 bool Dependent = false;
5983 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5984 case Sema::IER_Exists:
5985 if (S->isIfExists())
5986 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005987
Douglas Gregorba0513d2011-10-25 01:33:02 +00005988 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5989
5990 case Sema::IER_DoesNotExist:
5991 if (S->isIfNotExists())
5992 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005993
Douglas Gregorba0513d2011-10-25 01:33:02 +00005994 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005995
Douglas Gregorba0513d2011-10-25 01:33:02 +00005996 case Sema::IER_Dependent:
5997 Dependent = true;
5998 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005999
Douglas Gregor65019ac2011-10-25 03:44:56 +00006000 case Sema::IER_Error:
6001 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006002 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006003
Douglas Gregorba0513d2011-10-25 01:33:02 +00006004 // We need to continue with the instantiation, so do so now.
6005 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6006 if (SubStmt.isInvalid())
6007 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006008
Douglas Gregorba0513d2011-10-25 01:33:02 +00006009 // If we have resolved the name, just transform to the substatement.
6010 if (!Dependent)
6011 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006012
Douglas Gregorba0513d2011-10-25 01:33:02 +00006013 // The name is still dependent, so build a dependent expression again.
6014 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6015 S->isIfExists(),
6016 QualifierLoc,
6017 NameInfo,
6018 SubStmt.get());
6019}
6020
6021template<typename Derived>
6022StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006023TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6024 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6025 if(TryBlock.isInvalid()) return StmtError();
6026
6027 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6028 if(!getDerived().AlwaysRebuild() &&
6029 TryBlock.get() == S->getTryBlock() &&
6030 Handler.get() == S->getHandler())
6031 return SemaRef.Owned(S);
6032
6033 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6034 S->getTryLoc(),
6035 TryBlock.take(),
6036 Handler.take());
6037}
6038
6039template<typename Derived>
6040StmtResult
6041TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6042 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6043 if(Block.isInvalid()) return StmtError();
6044
6045 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6046 Block.take());
6047}
6048
6049template<typename Derived>
6050StmtResult
6051TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6052 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6053 if(FilterExpr.isInvalid()) return StmtError();
6054
6055 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6056 if(Block.isInvalid()) return StmtError();
6057
6058 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6059 FilterExpr.take(),
6060 Block.take());
6061}
6062
6063template<typename Derived>
6064StmtResult
6065TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6066 if(isa<SEHFinallyStmt>(Handler))
6067 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6068 else
6069 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6070}
6071
Douglas Gregor43959a92009-08-20 07:17:43 +00006072//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006073// Expression transformation
6074//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006075template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006076ExprResult
John McCall454feb92009-12-08 09:21:05 +00006077TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006078 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006079}
Mike Stump1eb44332009-09-09 15:08:12 +00006080
6081template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006082ExprResult
John McCall454feb92009-12-08 09:21:05 +00006083TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006084 NestedNameSpecifierLoc QualifierLoc;
6085 if (E->getQualifierLoc()) {
6086 QualifierLoc
6087 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6088 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006089 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006090 }
John McCalldbd872f2009-12-08 09:08:17 +00006091
6092 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006093 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6094 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006095 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006096 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006097
John McCallec8045d2010-08-17 21:27:17 +00006098 DeclarationNameInfo NameInfo = E->getNameInfo();
6099 if (NameInfo.getName()) {
6100 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6101 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006102 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006103 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006104
6105 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006106 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006107 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006108 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006109 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006110
6111 // Mark it referenced in the new context regardless.
6112 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006113 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006114
John McCall3fa5cae2010-10-26 07:05:15 +00006115 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006116 }
John McCalldbd872f2009-12-08 09:08:17 +00006117
6118 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006119 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006120 TemplateArgs = &TransArgs;
6121 TransArgs.setLAngleLoc(E->getLAngleLoc());
6122 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006123 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6124 E->getNumTemplateArgs(),
6125 TransArgs))
6126 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006127 }
6128
Chad Rosier4a9d7952012-08-08 18:46:20 +00006129 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006130 TemplateArgs);
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>::TransformIntegerLiteral(IntegerLiteral *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>::TransformFloatingLiteral(FloatingLiteral *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>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006148 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006149}
Mike Stump1eb44332009-09-09 15:08:12 +00006150
Douglas Gregorb98b1992009-08-11 05:31:07 +00006151template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006152ExprResult
John McCall454feb92009-12-08 09:21:05 +00006153TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006154 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006155}
Mike Stump1eb44332009-09-09 15:08:12 +00006156
Douglas Gregorb98b1992009-08-11 05:31:07 +00006157template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006158ExprResult
John McCall454feb92009-12-08 09:21:05 +00006159TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006160 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006161}
6162
6163template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006164ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006165TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6166 return SemaRef.MaybeBindToTemporary(E);
6167}
6168
6169template<typename Derived>
6170ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006171TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6172 ExprResult ControllingExpr =
6173 getDerived().TransformExpr(E->getControllingExpr());
6174 if (ControllingExpr.isInvalid())
6175 return ExprError();
6176
Chris Lattner686775d2011-07-20 06:58:45 +00006177 SmallVector<Expr *, 4> AssocExprs;
6178 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006179 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6180 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6181 if (TS) {
6182 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6183 if (!AssocType)
6184 return ExprError();
6185 AssocTypes.push_back(AssocType);
6186 } else {
6187 AssocTypes.push_back(0);
6188 }
6189
6190 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6191 if (AssocExpr.isInvalid())
6192 return ExprError();
6193 AssocExprs.push_back(AssocExpr.release());
6194 }
6195
6196 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6197 E->getDefaultLoc(),
6198 E->getRParenLoc(),
6199 ControllingExpr.release(),
6200 AssocTypes.data(),
6201 AssocExprs.data(),
6202 E->getNumAssocs());
6203}
6204
6205template<typename Derived>
6206ExprResult
John McCall454feb92009-12-08 09:21:05 +00006207TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006208 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006209 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006210 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006211
Douglas Gregorb98b1992009-08-11 05:31:07 +00006212 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006213 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006214
John McCall9ae2f072010-08-23 23:25:46 +00006215 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006216 E->getRParen());
6217}
6218
Richard Smithefeeccf2012-10-21 03:28:35 +00006219/// \brief The operand of a unary address-of operator has special rules: it's
6220/// allowed to refer to a non-static member of a class even if there's no 'this'
6221/// object available.
6222template<typename Derived>
6223ExprResult
6224TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6225 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6226 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6227 else
6228 return getDerived().TransformExpr(E);
6229}
6230
Mike Stump1eb44332009-09-09 15:08:12 +00006231template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006232ExprResult
John McCall454feb92009-12-08 09:21:05 +00006233TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00006234 ExprResult SubExpr = TransformAddressOfOperand(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006235 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006236 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006237
Douglas Gregorb98b1992009-08-11 05:31:07 +00006238 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006239 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006240
Douglas Gregorb98b1992009-08-11 05:31:07 +00006241 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6242 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006243 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006244}
Mike Stump1eb44332009-09-09 15:08:12 +00006245
Douglas Gregorb98b1992009-08-11 05:31:07 +00006246template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006247ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006248TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6249 // Transform the type.
6250 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6251 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006252 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006253
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006254 // Transform all of the components into components similar to what the
6255 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006256 // FIXME: It would be slightly more efficient in the non-dependent case to
6257 // just map FieldDecls, rather than requiring the rebuilder to look for
6258 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006259 // template code that we don't care.
6260 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006261 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006262 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006263 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006264 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6265 const Node &ON = E->getComponent(I);
6266 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006267 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006268 Comp.LocStart = ON.getSourceRange().getBegin();
6269 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006270 switch (ON.getKind()) {
6271 case Node::Array: {
6272 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006273 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006274 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006275 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006276
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006277 ExprChanged = ExprChanged || Index.get() != FromIndex;
6278 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006279 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006280 break;
6281 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006282
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006283 case Node::Field:
6284 case Node::Identifier:
6285 Comp.isBrackets = false;
6286 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006287 if (!Comp.U.IdentInfo)
6288 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006289
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006290 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006291
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006292 case Node::Base:
6293 // Will be recomputed during the rebuild.
6294 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006295 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006296
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006297 Components.push_back(Comp);
6298 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006299
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006300 // If nothing changed, retain the existing expression.
6301 if (!getDerived().AlwaysRebuild() &&
6302 Type == E->getTypeSourceInfo() &&
6303 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006304 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006305
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006306 // Build a new offsetof expression.
6307 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6308 Components.data(), Components.size(),
6309 E->getRParenLoc());
6310}
6311
6312template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006313ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006314TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6315 assert(getDerived().AlreadyTransformed(E->getType()) &&
6316 "opaque value expression requires transformation");
6317 return SemaRef.Owned(E);
6318}
6319
6320template<typename Derived>
6321ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006322TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006323 // Rebuild the syntactic form. The original syntactic form has
6324 // opaque-value expressions in it, so strip those away and rebuild
6325 // the result. This is a really awful way of doing this, but the
6326 // better solution (rebuilding the semantic expressions and
6327 // rebinding OVEs as necessary) doesn't work; we'd need
6328 // TreeTransform to not strip away implicit conversions.
6329 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6330 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006331 if (result.isInvalid()) return ExprError();
6332
6333 // If that gives us a pseudo-object result back, the pseudo-object
6334 // expression must have been an lvalue-to-rvalue conversion which we
6335 // should reapply.
6336 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6337 result = SemaRef.checkPseudoObjectRValue(result.take());
6338
6339 return result;
6340}
6341
6342template<typename Derived>
6343ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006344TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6345 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006346 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006347 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006348
John McCalla93c9342009-12-07 02:54:59 +00006349 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006350 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006351 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006352
John McCall5ab75172009-11-04 07:28:41 +00006353 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006354 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006355
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006356 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6357 E->getKind(),
6358 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006359 }
Mike Stump1eb44332009-09-09 15:08:12 +00006360
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006361 // C++0x [expr.sizeof]p1:
6362 // The operand is either an expression, which is an unevaluated operand
6363 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006364 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6365 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006366
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006367 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6368 if (SubExpr.isInvalid())
6369 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006370
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006371 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6372 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006373
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006374 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6375 E->getOperatorLoc(),
6376 E->getKind(),
6377 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006378}
Mike Stump1eb44332009-09-09 15:08:12 +00006379
Douglas Gregorb98b1992009-08-11 05:31:07 +00006380template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006381ExprResult
John McCall454feb92009-12-08 09:21:05 +00006382TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006383 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006384 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006385 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006386
John McCall60d7b3a2010-08-24 06:29:42 +00006387 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006388 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006389 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006390
6391
Douglas Gregorb98b1992009-08-11 05:31:07 +00006392 if (!getDerived().AlwaysRebuild() &&
6393 LHS.get() == E->getLHS() &&
6394 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006395 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006396
John McCall9ae2f072010-08-23 23:25:46 +00006397 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006398 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006399 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006400 E->getRBracketLoc());
6401}
Mike Stump1eb44332009-09-09 15:08:12 +00006402
6403template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006404ExprResult
John McCall454feb92009-12-08 09:21:05 +00006405TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006406 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006407 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006408 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006409 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006410
6411 // Transform arguments.
6412 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006413 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006414 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006415 &ArgChanged))
6416 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006417
Douglas Gregorb98b1992009-08-11 05:31:07 +00006418 if (!getDerived().AlwaysRebuild() &&
6419 Callee.get() == E->getCallee() &&
6420 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006421 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006422
Douglas Gregorb98b1992009-08-11 05:31:07 +00006423 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006424 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006425 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006426 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006427 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006428 E->getRParenLoc());
6429}
Mike Stump1eb44332009-09-09 15:08:12 +00006430
6431template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006432ExprResult
John McCall454feb92009-12-08 09:21:05 +00006433TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006434 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006435 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006436 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006437
Douglas Gregor40d96a62011-02-28 21:54:11 +00006438 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006439 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006440 QualifierLoc
6441 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006442
Douglas Gregor40d96a62011-02-28 21:54:11 +00006443 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006444 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006445 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006446 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006447
Eli Friedmanf595cc42009-12-04 06:40:45 +00006448 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006449 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6450 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006451 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006452 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006453
John McCall6bb80172010-03-30 21:47:33 +00006454 NamedDecl *FoundDecl = E->getFoundDecl();
6455 if (FoundDecl == E->getMemberDecl()) {
6456 FoundDecl = Member;
6457 } else {
6458 FoundDecl = cast_or_null<NamedDecl>(
6459 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6460 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006461 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006462 }
6463
Douglas Gregorb98b1992009-08-11 05:31:07 +00006464 if (!getDerived().AlwaysRebuild() &&
6465 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006466 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006467 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006468 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006469 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006470
Anders Carlsson1f240322009-12-22 05:24:09 +00006471 // Mark it referenced in the new context regardless.
6472 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006473 SemaRef.MarkMemberReferenced(E);
6474
John McCall3fa5cae2010-10-26 07:05:15 +00006475 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006476 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006477
John McCalld5532b62009-11-23 01:53:49 +00006478 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006479 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006480 TransArgs.setLAngleLoc(E->getLAngleLoc());
6481 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006482 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6483 E->getNumTemplateArgs(),
6484 TransArgs))
6485 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006486 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006487
Douglas Gregorb98b1992009-08-11 05:31:07 +00006488 // FIXME: Bogus source location for the operator
6489 SourceLocation FakeOperatorLoc
6490 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6491
John McCallc2233c52010-01-15 08:34:02 +00006492 // FIXME: to do this check properly, we will need to preserve the
6493 // first-qualifier-in-scope here, just in case we had a dependent
6494 // base (and therefore couldn't do the check) and a
6495 // nested-name-qualifier (and therefore could do the lookup).
6496 NamedDecl *FirstQualifierInScope = 0;
6497
John McCall9ae2f072010-08-23 23:25:46 +00006498 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006499 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006500 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006501 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006502 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006503 Member,
John McCall6bb80172010-03-30 21:47:33 +00006504 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006505 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006506 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006507 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006508}
Mike Stump1eb44332009-09-09 15:08:12 +00006509
Douglas Gregorb98b1992009-08-11 05:31:07 +00006510template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006511ExprResult
John McCall454feb92009-12-08 09:21:05 +00006512TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006513 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006514 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006515 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006516
John McCall60d7b3a2010-08-24 06:29:42 +00006517 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006518 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006519 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006520
Douglas Gregorb98b1992009-08-11 05:31:07 +00006521 if (!getDerived().AlwaysRebuild() &&
6522 LHS.get() == E->getLHS() &&
6523 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006524 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006525
Lang Hamesbe9af122012-10-02 04:45:10 +00006526 Sema::FPContractStateRAII FPContractState(getSema());
6527 getSema().FPFeatures.fp_contract = E->isFPContractable();
6528
Douglas Gregorb98b1992009-08-11 05:31:07 +00006529 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006530 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006531}
6532
Mike Stump1eb44332009-09-09 15:08:12 +00006533template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006534ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006535TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006536 CompoundAssignOperator *E) {
6537 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006538}
Mike Stump1eb44332009-09-09 15:08:12 +00006539
Douglas Gregorb98b1992009-08-11 05:31:07 +00006540template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006541ExprResult TreeTransform<Derived>::
6542TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6543 // Just rebuild the common and RHS expressions and see whether we
6544 // get any changes.
6545
6546 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6547 if (commonExpr.isInvalid())
6548 return ExprError();
6549
6550 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6551 if (rhs.isInvalid())
6552 return ExprError();
6553
6554 if (!getDerived().AlwaysRebuild() &&
6555 commonExpr.get() == e->getCommon() &&
6556 rhs.get() == e->getFalseExpr())
6557 return SemaRef.Owned(e);
6558
6559 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6560 e->getQuestionLoc(),
6561 0,
6562 e->getColonLoc(),
6563 rhs.get());
6564}
6565
6566template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006567ExprResult
John McCall454feb92009-12-08 09:21:05 +00006568TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006569 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006570 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006571 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006572
John McCall60d7b3a2010-08-24 06:29:42 +00006573 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006574 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006575 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006576
John McCall60d7b3a2010-08-24 06:29:42 +00006577 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006578 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006579 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006580
Douglas Gregorb98b1992009-08-11 05:31:07 +00006581 if (!getDerived().AlwaysRebuild() &&
6582 Cond.get() == E->getCond() &&
6583 LHS.get() == E->getLHS() &&
6584 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006585 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006586
John McCall9ae2f072010-08-23 23:25:46 +00006587 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006588 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006589 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006590 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006591 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006592}
Mike Stump1eb44332009-09-09 15:08:12 +00006593
6594template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006595ExprResult
John McCall454feb92009-12-08 09:21:05 +00006596TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006597 // Implicit casts are eliminated during transformation, since they
6598 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006599 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006600}
Mike Stump1eb44332009-09-09 15:08:12 +00006601
Douglas Gregorb98b1992009-08-11 05:31:07 +00006602template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006603ExprResult
John McCall454feb92009-12-08 09:21:05 +00006604TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006605 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6606 if (!Type)
6607 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006608
John McCall60d7b3a2010-08-24 06:29:42 +00006609 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006610 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006611 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006612 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006613
Douglas Gregorb98b1992009-08-11 05:31:07 +00006614 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006615 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006616 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006617 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006618
John McCall9d125032010-01-15 18:39:57 +00006619 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006620 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006621 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006622 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006623}
Mike Stump1eb44332009-09-09 15:08:12 +00006624
Douglas Gregorb98b1992009-08-11 05:31:07 +00006625template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006626ExprResult
John McCall454feb92009-12-08 09:21:05 +00006627TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006628 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6629 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6630 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006631 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006632
John McCall60d7b3a2010-08-24 06:29:42 +00006633 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006634 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006635 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006636
Douglas Gregorb98b1992009-08-11 05:31:07 +00006637 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006638 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006639 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006640 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006641
John McCall1d7d8d62010-01-19 22:33:45 +00006642 // Note: the expression type doesn't necessarily match the
6643 // type-as-written, but that's okay, because it should always be
6644 // derivable from the initializer.
6645
John McCall42f56b52010-01-18 19:35:47 +00006646 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006647 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006648 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006649}
Mike Stump1eb44332009-09-09 15:08:12 +00006650
Douglas Gregorb98b1992009-08-11 05:31:07 +00006651template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006652ExprResult
John McCall454feb92009-12-08 09:21:05 +00006653TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006654 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006655 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006656 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006657
Douglas Gregorb98b1992009-08-11 05:31:07 +00006658 if (!getDerived().AlwaysRebuild() &&
6659 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006660 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006661
Douglas Gregorb98b1992009-08-11 05:31:07 +00006662 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006663 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006664 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006665 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006666 E->getAccessorLoc(),
6667 E->getAccessor());
6668}
Mike Stump1eb44332009-09-09 15:08:12 +00006669
Douglas Gregorb98b1992009-08-11 05:31:07 +00006670template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006671ExprResult
John McCall454feb92009-12-08 09:21:05 +00006672TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006673 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006674
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006675 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006676 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006677 Inits, &InitChanged))
6678 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006679
Douglas Gregorb98b1992009-08-11 05:31:07 +00006680 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006681 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006682
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006683 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006684 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006685}
Mike Stump1eb44332009-09-09 15:08:12 +00006686
Douglas Gregorb98b1992009-08-11 05:31:07 +00006687template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006688ExprResult
John McCall454feb92009-12-08 09:21:05 +00006689TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006690 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006691
Douglas Gregor43959a92009-08-20 07:17:43 +00006692 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006693 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006694 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006695 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006696
Douglas Gregor43959a92009-08-20 07:17:43 +00006697 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006698 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006699 bool ExprChanged = false;
6700 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6701 DEnd = E->designators_end();
6702 D != DEnd; ++D) {
6703 if (D->isFieldDesignator()) {
6704 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6705 D->getDotLoc(),
6706 D->getFieldLoc()));
6707 continue;
6708 }
Mike Stump1eb44332009-09-09 15:08:12 +00006709
Douglas Gregorb98b1992009-08-11 05:31:07 +00006710 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006711 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006712 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006713 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006714
6715 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006716 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006717
Douglas Gregorb98b1992009-08-11 05:31:07 +00006718 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6719 ArrayExprs.push_back(Index.release());
6720 continue;
6721 }
Mike Stump1eb44332009-09-09 15:08:12 +00006722
Douglas Gregorb98b1992009-08-11 05:31:07 +00006723 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006724 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006725 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6726 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006727 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006728
John McCall60d7b3a2010-08-24 06:29:42 +00006729 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006730 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006731 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006732
6733 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006734 End.get(),
6735 D->getLBracketLoc(),
6736 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006737
Douglas Gregorb98b1992009-08-11 05:31:07 +00006738 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6739 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006740
Douglas Gregorb98b1992009-08-11 05:31:07 +00006741 ArrayExprs.push_back(Start.release());
6742 ArrayExprs.push_back(End.release());
6743 }
Mike Stump1eb44332009-09-09 15:08:12 +00006744
Douglas Gregorb98b1992009-08-11 05:31:07 +00006745 if (!getDerived().AlwaysRebuild() &&
6746 Init.get() == E->getInit() &&
6747 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006748 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006749
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006750 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006751 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006752 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006753}
Mike Stump1eb44332009-09-09 15:08:12 +00006754
Douglas Gregorb98b1992009-08-11 05:31:07 +00006755template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006756ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006757TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006758 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006759 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006760
Douglas Gregor5557b252009-10-28 00:29:27 +00006761 // FIXME: Will we ever have proper type location here? Will we actually
6762 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006763 QualType T = getDerived().TransformType(E->getType());
6764 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006765 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006766
Douglas Gregorb98b1992009-08-11 05:31:07 +00006767 if (!getDerived().AlwaysRebuild() &&
6768 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006769 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006770
Douglas Gregorb98b1992009-08-11 05:31:07 +00006771 return getDerived().RebuildImplicitValueInitExpr(T);
6772}
Mike Stump1eb44332009-09-09 15:08:12 +00006773
Douglas Gregorb98b1992009-08-11 05:31:07 +00006774template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006775ExprResult
John McCall454feb92009-12-08 09:21:05 +00006776TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006777 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6778 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006779 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006780
John McCall60d7b3a2010-08-24 06:29:42 +00006781 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006782 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006783 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006784
Douglas Gregorb98b1992009-08-11 05:31:07 +00006785 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006786 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006787 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006788 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006789
John McCall9ae2f072010-08-23 23:25:46 +00006790 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006791 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006792}
6793
6794template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006795ExprResult
John McCall454feb92009-12-08 09:21:05 +00006796TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006797 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006798 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00006799 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6800 &ArgumentChanged))
6801 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006802
Douglas Gregorb98b1992009-08-11 05:31:07 +00006803 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006804 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006805 E->getRParenLoc());
6806}
Mike Stump1eb44332009-09-09 15:08:12 +00006807
Douglas Gregorb98b1992009-08-11 05:31:07 +00006808/// \brief Transform an address-of-label expression.
6809///
6810/// By default, the transformation of an address-of-label expression always
6811/// rebuilds the expression, so that the label identifier can be resolved to
6812/// the corresponding label statement by semantic analysis.
6813template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006814ExprResult
John McCall454feb92009-12-08 09:21:05 +00006815TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006816 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6817 E->getLabel());
6818 if (!LD)
6819 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006820
Douglas Gregorb98b1992009-08-11 05:31:07 +00006821 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006822 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006823}
Mike Stump1eb44332009-09-09 15:08:12 +00006824
6825template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006826ExprResult
John McCall454feb92009-12-08 09:21:05 +00006827TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006828 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006829 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006830 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006831 if (SubStmt.isInvalid()) {
6832 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006833 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006834 }
Mike Stump1eb44332009-09-09 15:08:12 +00006835
Douglas Gregorb98b1992009-08-11 05:31:07 +00006836 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006837 SubStmt.get() == E->getSubStmt()) {
6838 // Calling this an 'error' is unintuitive, but it does the right thing.
6839 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006840 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006841 }
Mike Stump1eb44332009-09-09 15:08:12 +00006842
6843 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006844 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006845 E->getRParenLoc());
6846}
Mike Stump1eb44332009-09-09 15:08:12 +00006847
Douglas Gregorb98b1992009-08-11 05:31:07 +00006848template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006849ExprResult
John McCall454feb92009-12-08 09:21:05 +00006850TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006851 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006852 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006853 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006854
John McCall60d7b3a2010-08-24 06:29:42 +00006855 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006856 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006857 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006858
John McCall60d7b3a2010-08-24 06:29:42 +00006859 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006860 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006861 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006862
Douglas Gregorb98b1992009-08-11 05:31:07 +00006863 if (!getDerived().AlwaysRebuild() &&
6864 Cond.get() == E->getCond() &&
6865 LHS.get() == E->getLHS() &&
6866 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006867 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006868
Douglas Gregorb98b1992009-08-11 05:31:07 +00006869 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006870 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006871 E->getRParenLoc());
6872}
Mike Stump1eb44332009-09-09 15:08:12 +00006873
Douglas Gregorb98b1992009-08-11 05:31:07 +00006874template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006875ExprResult
John McCall454feb92009-12-08 09:21:05 +00006876TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006877 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006878}
6879
6880template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006881ExprResult
John McCall454feb92009-12-08 09:21:05 +00006882TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006883 switch (E->getOperator()) {
6884 case OO_New:
6885 case OO_Delete:
6886 case OO_Array_New:
6887 case OO_Array_Delete:
6888 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006889
Douglas Gregor668d6d92009-12-13 20:44:55 +00006890 case OO_Call: {
6891 // This is a call to an object's operator().
6892 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6893
6894 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006895 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006896 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006897 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006898
6899 // FIXME: Poor location information
6900 SourceLocation FakeLParenLoc
6901 = SemaRef.PP.getLocForEndOfToken(
6902 static_cast<Expr *>(Object.get())->getLocEnd());
6903
6904 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006905 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006906 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006907 Args))
6908 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006909
John McCall9ae2f072010-08-23 23:25:46 +00006910 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006911 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006912 E->getLocEnd());
6913 }
6914
6915#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6916 case OO_##Name:
6917#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6918#include "clang/Basic/OperatorKinds.def"
6919 case OO_Subscript:
6920 // Handled below.
6921 break;
6922
6923 case OO_Conditional:
6924 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006925
6926 case OO_None:
6927 case NUM_OVERLOADED_OPERATORS:
6928 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006929 }
6930
John McCall60d7b3a2010-08-24 06:29:42 +00006931 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006932 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006933 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006934
Richard Smithefeeccf2012-10-21 03:28:35 +00006935 ExprResult First;
6936 if (E->getOperator() == OO_Amp)
6937 First = getDerived().TransformAddressOfOperand(E->getArg(0));
6938 else
6939 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006940 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006941 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006942
John McCall60d7b3a2010-08-24 06:29:42 +00006943 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006944 if (E->getNumArgs() == 2) {
6945 Second = getDerived().TransformExpr(E->getArg(1));
6946 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006947 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006948 }
Mike Stump1eb44332009-09-09 15:08:12 +00006949
Douglas Gregorb98b1992009-08-11 05:31:07 +00006950 if (!getDerived().AlwaysRebuild() &&
6951 Callee.get() == E->getCallee() &&
6952 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006953 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006954 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006955
Lang Hamesbe9af122012-10-02 04:45:10 +00006956 Sema::FPContractStateRAII FPContractState(getSema());
6957 getSema().FPFeatures.fp_contract = E->isFPContractable();
6958
Douglas Gregorb98b1992009-08-11 05:31:07 +00006959 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6960 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006961 Callee.get(),
6962 First.get(),
6963 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006964}
Mike Stump1eb44332009-09-09 15:08:12 +00006965
Douglas Gregorb98b1992009-08-11 05:31:07 +00006966template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006967ExprResult
John McCall454feb92009-12-08 09:21:05 +00006968TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6969 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006970}
Mike Stump1eb44332009-09-09 15:08:12 +00006971
Douglas Gregorb98b1992009-08-11 05:31:07 +00006972template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006973ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006974TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6975 // Transform the callee.
6976 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6977 if (Callee.isInvalid())
6978 return ExprError();
6979
6980 // Transform exec config.
6981 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6982 if (EC.isInvalid())
6983 return ExprError();
6984
6985 // Transform arguments.
6986 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006987 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006988 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006989 &ArgChanged))
6990 return ExprError();
6991
6992 if (!getDerived().AlwaysRebuild() &&
6993 Callee.get() == E->getCallee() &&
6994 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006995 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006996
6997 // FIXME: Wrong source location information for the '('.
6998 SourceLocation FakeLParenLoc
6999 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7000 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007001 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007002 E->getRParenLoc(), EC.get());
7003}
7004
7005template<typename Derived>
7006ExprResult
John McCall454feb92009-12-08 09:21:05 +00007007TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007008 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7009 if (!Type)
7010 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007011
John McCall60d7b3a2010-08-24 06:29:42 +00007012 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007013 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007014 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007015 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007016
Douglas Gregorb98b1992009-08-11 05:31:07 +00007017 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007018 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007019 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007020 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007021
Douglas Gregorb98b1992009-08-11 05:31:07 +00007022 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00007023 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007024 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
7025 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007026 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007027 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007028 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007029 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007030 FakeRAngleLoc,
7031 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007032 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007033 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007034}
Mike Stump1eb44332009-09-09 15:08:12 +00007035
Douglas Gregorb98b1992009-08-11 05:31:07 +00007036template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007037ExprResult
John McCall454feb92009-12-08 09:21:05 +00007038TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7039 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007040}
Mike Stump1eb44332009-09-09 15:08:12 +00007041
7042template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007043ExprResult
John McCall454feb92009-12-08 09:21:05 +00007044TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7045 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007046}
7047
Douglas Gregorb98b1992009-08-11 05:31:07 +00007048template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007049ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007050TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007051 CXXReinterpretCastExpr *E) {
7052 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007053}
Mike Stump1eb44332009-09-09 15:08:12 +00007054
Douglas Gregorb98b1992009-08-11 05:31:07 +00007055template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007056ExprResult
John McCall454feb92009-12-08 09:21:05 +00007057TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7058 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007059}
Mike Stump1eb44332009-09-09 15:08:12 +00007060
Douglas Gregorb98b1992009-08-11 05:31:07 +00007061template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007062ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007063TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007064 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007065 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7066 if (!Type)
7067 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007068
John McCall60d7b3a2010-08-24 06:29:42 +00007069 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007070 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007071 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007072 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007073
Douglas Gregorb98b1992009-08-11 05:31:07 +00007074 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007075 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007076 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007077 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007078
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007079 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007080 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007081 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007082 E->getRParenLoc());
7083}
Mike Stump1eb44332009-09-09 15:08:12 +00007084
Douglas Gregorb98b1992009-08-11 05:31:07 +00007085template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007086ExprResult
John McCall454feb92009-12-08 09:21:05 +00007087TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007088 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007089 TypeSourceInfo *TInfo
7090 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7091 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007092 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007093
Douglas Gregorb98b1992009-08-11 05:31:07 +00007094 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007095 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007096 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007097
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007098 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7099 E->getLocStart(),
7100 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007101 E->getLocEnd());
7102 }
Mike Stump1eb44332009-09-09 15:08:12 +00007103
Eli Friedmanef331b72012-01-20 01:26:23 +00007104 // We don't know whether the subexpression is potentially evaluated until
7105 // after we perform semantic analysis. We speculatively assume it is
7106 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007107 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007108 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7109 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007110
John McCall60d7b3a2010-08-24 06:29:42 +00007111 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007112 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007113 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007114
Douglas Gregorb98b1992009-08-11 05:31:07 +00007115 if (!getDerived().AlwaysRebuild() &&
7116 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007117 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007118
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007119 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7120 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007121 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007122 E->getLocEnd());
7123}
7124
7125template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007126ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007127TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7128 if (E->isTypeOperand()) {
7129 TypeSourceInfo *TInfo
7130 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7131 if (!TInfo)
7132 return ExprError();
7133
7134 if (!getDerived().AlwaysRebuild() &&
7135 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007136 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007137
Douglas Gregor3c52a212011-03-06 17:40:41 +00007138 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007139 E->getLocStart(),
7140 TInfo,
7141 E->getLocEnd());
7142 }
7143
Francois Pichet01b7c302010-09-08 12:20:18 +00007144 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7145
7146 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7147 if (SubExpr.isInvalid())
7148 return ExprError();
7149
7150 if (!getDerived().AlwaysRebuild() &&
7151 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007152 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007153
7154 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7155 E->getLocStart(),
7156 SubExpr.get(),
7157 E->getLocEnd());
7158}
7159
7160template<typename Derived>
7161ExprResult
John McCall454feb92009-12-08 09:21:05 +00007162TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007163 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007164}
Mike Stump1eb44332009-09-09 15:08:12 +00007165
Douglas Gregorb98b1992009-08-11 05:31:07 +00007166template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007167ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007168TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007169 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007170 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007171}
Mike Stump1eb44332009-09-09 15:08:12 +00007172
Douglas Gregorb98b1992009-08-11 05:31:07 +00007173template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007174ExprResult
John McCall454feb92009-12-08 09:21:05 +00007175TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007176 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007177 QualType T;
7178 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7179 T = MD->getThisType(getSema().Context);
7180 else
7181 T = getSema().Context.getPointerType(
7182 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007183
Douglas Gregorec79d872012-02-24 17:41:38 +00007184 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7185 // Make sure that we capture 'this'.
7186 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007187 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007188 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007189
Douglas Gregor828a1972010-01-07 23:12:05 +00007190 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007191}
Mike Stump1eb44332009-09-09 15:08:12 +00007192
Douglas Gregorb98b1992009-08-11 05:31:07 +00007193template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007194ExprResult
John McCall454feb92009-12-08 09:21:05 +00007195TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007196 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007197 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007198 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007199
Douglas Gregorb98b1992009-08-11 05:31:07 +00007200 if (!getDerived().AlwaysRebuild() &&
7201 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007202 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007203
Douglas Gregorbca01b42011-07-06 22:04:06 +00007204 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7205 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007206}
Mike Stump1eb44332009-09-09 15:08:12 +00007207
Douglas Gregorb98b1992009-08-11 05:31:07 +00007208template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007209ExprResult
John McCall454feb92009-12-08 09:21:05 +00007210TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007211 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007212 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7213 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007214 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007215 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007216
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007217 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007218 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007219 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007220
Douglas Gregor036aed12009-12-23 23:03:06 +00007221 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007222}
Mike Stump1eb44332009-09-09 15:08:12 +00007223
Douglas Gregorb98b1992009-08-11 05:31:07 +00007224template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007225ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007226TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7227 CXXScalarValueInitExpr *E) {
7228 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7229 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007230 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007231
Douglas Gregorb98b1992009-08-11 05:31:07 +00007232 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007233 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007234 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007235
Chad Rosier4a9d7952012-08-08 18:46:20 +00007236 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007237 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007238 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007239}
Mike Stump1eb44332009-09-09 15:08:12 +00007240
Douglas Gregorb98b1992009-08-11 05:31:07 +00007241template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007242ExprResult
John McCall454feb92009-12-08 09:21:05 +00007243TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007244 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007245 TypeSourceInfo *AllocTypeInfo
7246 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7247 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007248 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007249
Douglas Gregorb98b1992009-08-11 05:31:07 +00007250 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007251 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007252 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007253 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007254
Douglas Gregorb98b1992009-08-11 05:31:07 +00007255 // Transform the placement arguments (if any).
7256 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007257 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007258 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007259 E->getNumPlacementArgs(), true,
7260 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007261 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007262
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007263 // Transform the initializer (if any).
7264 Expr *OldInit = E->getInitializer();
7265 ExprResult NewInit;
7266 if (OldInit)
7267 NewInit = getDerived().TransformExpr(OldInit);
7268 if (NewInit.isInvalid())
7269 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007270
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007271 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007272 FunctionDecl *OperatorNew = 0;
7273 if (E->getOperatorNew()) {
7274 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007275 getDerived().TransformDecl(E->getLocStart(),
7276 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007277 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007278 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007279 }
7280
7281 FunctionDecl *OperatorDelete = 0;
7282 if (E->getOperatorDelete()) {
7283 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007284 getDerived().TransformDecl(E->getLocStart(),
7285 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007286 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007287 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007288 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007289
Douglas Gregorb98b1992009-08-11 05:31:07 +00007290 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007291 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007292 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007293 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007294 OperatorNew == E->getOperatorNew() &&
7295 OperatorDelete == E->getOperatorDelete() &&
7296 !ArgumentChanged) {
7297 // Mark any declarations we need as referenced.
7298 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007299 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007300 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007301 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007302 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007303
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007304 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007305 QualType ElementType
7306 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7307 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7308 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7309 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007310 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007311 }
7312 }
7313 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007314
John McCall3fa5cae2010-10-26 07:05:15 +00007315 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007316 }
Mike Stump1eb44332009-09-09 15:08:12 +00007317
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007318 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007319 if (!ArraySize.get()) {
7320 // If no array size was specified, but the new expression was
7321 // instantiated with an array type (e.g., "new T" where T is
7322 // instantiated with "int[4]"), extract the outer bound from the
7323 // array type as our array size. We do this with constant and
7324 // dependently-sized array types.
7325 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7326 if (!ArrayT) {
7327 // Do nothing
7328 } else if (const ConstantArrayType *ConsArrayT
7329 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007330 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007331 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007332 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007333 SemaRef.Context.getSizeType(),
7334 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007335 AllocType = ConsArrayT->getElementType();
7336 } else if (const DependentSizedArrayType *DepArrayT
7337 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7338 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007339 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007340 AllocType = DepArrayT->getElementType();
7341 }
7342 }
7343 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007344
Douglas Gregorb98b1992009-08-11 05:31:07 +00007345 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7346 E->isGlobalNew(),
7347 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007348 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007349 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007350 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007351 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007352 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007353 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007354 E->getDirectInitRange(),
7355 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007356}
Mike Stump1eb44332009-09-09 15:08:12 +00007357
Douglas Gregorb98b1992009-08-11 05:31:07 +00007358template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007359ExprResult
John McCall454feb92009-12-08 09:21:05 +00007360TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007361 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007362 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007363 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007364
Douglas Gregor1af74512010-02-26 00:38:10 +00007365 // Transform the delete operator, if known.
7366 FunctionDecl *OperatorDelete = 0;
7367 if (E->getOperatorDelete()) {
7368 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007369 getDerived().TransformDecl(E->getLocStart(),
7370 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007371 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007372 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007373 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007374
Douglas Gregorb98b1992009-08-11 05:31:07 +00007375 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007376 Operand.get() == E->getArgument() &&
7377 OperatorDelete == E->getOperatorDelete()) {
7378 // Mark any declarations we need as referenced.
7379 // FIXME: instantiation-specific.
7380 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007381 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007382
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007383 if (!E->getArgument()->isTypeDependent()) {
7384 QualType Destroyed = SemaRef.Context.getBaseElementType(
7385 E->getDestroyedType());
7386 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7387 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007388 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007389 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007390 }
7391 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007392
John McCall3fa5cae2010-10-26 07:05:15 +00007393 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007394 }
Mike Stump1eb44332009-09-09 15:08:12 +00007395
Douglas Gregorb98b1992009-08-11 05:31:07 +00007396 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7397 E->isGlobalDelete(),
7398 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007399 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007400}
Mike Stump1eb44332009-09-09 15:08:12 +00007401
Douglas Gregorb98b1992009-08-11 05:31:07 +00007402template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007403ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007404TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007405 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007406 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007407 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007408 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007409
John McCallb3d87482010-08-24 05:47:05 +00007410 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007411 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007412 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007413 E->getOperatorLoc(),
7414 E->isArrow()? tok::arrow : tok::period,
7415 ObjectTypePtr,
7416 MayBePseudoDestructor);
7417 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007418 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007419
John McCallb3d87482010-08-24 05:47:05 +00007420 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007421 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7422 if (QualifierLoc) {
7423 QualifierLoc
7424 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7425 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007426 return ExprError();
7427 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007428 CXXScopeSpec SS;
7429 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007430
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007431 PseudoDestructorTypeStorage Destroyed;
7432 if (E->getDestroyedTypeInfo()) {
7433 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007434 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007435 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007436 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007437 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007438 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007439 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007440 // We aren't likely to be able to resolve the identifier down to a type
7441 // now anyway, so just retain the identifier.
7442 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7443 E->getDestroyedTypeLoc());
7444 } else {
7445 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007446 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007447 *E->getDestroyedTypeIdentifier(),
7448 E->getDestroyedTypeLoc(),
7449 /*Scope=*/0,
7450 SS, ObjectTypePtr,
7451 false);
7452 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007453 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007454
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007455 Destroyed
7456 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7457 E->getDestroyedTypeLoc());
7458 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007459
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007460 TypeSourceInfo *ScopeTypeInfo = 0;
7461 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007462 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007463 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007464 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007465 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007466
John McCall9ae2f072010-08-23 23:25:46 +00007467 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007468 E->getOperatorLoc(),
7469 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007470 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007471 ScopeTypeInfo,
7472 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007473 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007474 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007475}
Mike Stump1eb44332009-09-09 15:08:12 +00007476
Douglas Gregora71d8192009-09-04 17:36:40 +00007477template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007478ExprResult
John McCallba135432009-11-21 08:51:07 +00007479TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007480 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007481 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7482 Sema::LookupOrdinaryName);
7483
7484 // Transform all the decls.
7485 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7486 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007487 NamedDecl *InstD = static_cast<NamedDecl*>(
7488 getDerived().TransformDecl(Old->getNameLoc(),
7489 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007490 if (!InstD) {
7491 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7492 // This can happen because of dependent hiding.
7493 if (isa<UsingShadowDecl>(*I))
7494 continue;
7495 else
John McCallf312b1e2010-08-26 23:41:50 +00007496 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007497 }
John McCallf7a1a742009-11-24 19:00:30 +00007498
7499 // Expand using declarations.
7500 if (isa<UsingDecl>(InstD)) {
7501 UsingDecl *UD = cast<UsingDecl>(InstD);
7502 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7503 E = UD->shadow_end(); I != E; ++I)
7504 R.addDecl(*I);
7505 continue;
7506 }
7507
7508 R.addDecl(InstD);
7509 }
7510
7511 // Resolve a kind, but don't do any further analysis. If it's
7512 // ambiguous, the callee needs to deal with it.
7513 R.resolveKind();
7514
7515 // Rebuild the nested-name qualifier, if present.
7516 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007517 if (Old->getQualifierLoc()) {
7518 NestedNameSpecifierLoc QualifierLoc
7519 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7520 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007521 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007522
Douglas Gregor4c9be892011-02-28 20:01:57 +00007523 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007524 }
7525
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007526 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007527 CXXRecordDecl *NamingClass
7528 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7529 Old->getNameLoc(),
7530 Old->getNamingClass()));
7531 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007532 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007533
Douglas Gregor66c45152010-04-27 16:10:10 +00007534 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007535 }
7536
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007537 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7538
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007539 // If we have neither explicit template arguments, nor the template keyword,
7540 // it's a normal declaration name.
7541 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007542 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7543
7544 // If we have template arguments, rebuild them, then rebuild the
7545 // templateid expression.
7546 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007547 if (Old->hasExplicitTemplateArgs() &&
7548 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007549 Old->getNumTemplateArgs(),
7550 TransArgs))
7551 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007552
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007553 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007554 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007555}
Mike Stump1eb44332009-09-09 15:08:12 +00007556
Douglas Gregorb98b1992009-08-11 05:31:07 +00007557template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007558ExprResult
John McCall454feb92009-12-08 09:21:05 +00007559TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007560 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7561 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007562 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007563
Douglas Gregorb98b1992009-08-11 05:31:07 +00007564 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007565 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007566 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007567
Mike Stump1eb44332009-09-09 15:08:12 +00007568 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007569 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007570 T,
7571 E->getLocEnd());
7572}
Mike Stump1eb44332009-09-09 15:08:12 +00007573
Douglas Gregorb98b1992009-08-11 05:31:07 +00007574template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007575ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007576TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7577 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7578 if (!LhsT)
7579 return ExprError();
7580
7581 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7582 if (!RhsT)
7583 return ExprError();
7584
7585 if (!getDerived().AlwaysRebuild() &&
7586 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7587 return SemaRef.Owned(E);
7588
7589 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7590 E->getLocStart(),
7591 LhsT, RhsT,
7592 E->getLocEnd());
7593}
7594
7595template<typename Derived>
7596ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007597TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7598 bool ArgChanged = false;
7599 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7600 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7601 TypeSourceInfo *From = E->getArg(I);
7602 TypeLoc FromTL = From->getTypeLoc();
7603 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7604 TypeLocBuilder TLB;
7605 TLB.reserve(FromTL.getFullDataSize());
7606 QualType To = getDerived().TransformType(TLB, FromTL);
7607 if (To.isNull())
7608 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007609
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007610 if (To == From->getType())
7611 Args.push_back(From);
7612 else {
7613 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7614 ArgChanged = true;
7615 }
7616 continue;
7617 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007618
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007619 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007620
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007621 // We have a pack expansion. Instantiate it.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007622 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007623 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7624 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7625 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007626
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007627 // Determine whether the set of unexpanded parameter packs can and should
7628 // be expanded.
7629 bool Expand = true;
7630 bool RetainExpansion = false;
7631 llvm::Optional<unsigned> OrigNumExpansions
7632 = ExpansionTL.getTypePtr()->getNumExpansions();
7633 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7634 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7635 PatternTL.getSourceRange(),
7636 Unexpanded,
7637 Expand, RetainExpansion,
7638 NumExpansions))
7639 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007640
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007641 if (!Expand) {
7642 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007643 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007644 // expansion.
7645 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007646
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007647 TypeLocBuilder TLB;
7648 TLB.reserve(From->getTypeLoc().getFullDataSize());
7649
7650 QualType To = getDerived().TransformType(TLB, PatternTL);
7651 if (To.isNull())
7652 return ExprError();
7653
Chad Rosier4a9d7952012-08-08 18:46:20 +00007654 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007655 PatternTL.getSourceRange(),
7656 ExpansionTL.getEllipsisLoc(),
7657 NumExpansions);
7658 if (To.isNull())
7659 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007660
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007661 PackExpansionTypeLoc ToExpansionTL
7662 = TLB.push<PackExpansionTypeLoc>(To);
7663 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7664 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7665 continue;
7666 }
7667
7668 // Expand the pack expansion by substituting for each argument in the
7669 // pack(s).
7670 for (unsigned I = 0; I != *NumExpansions; ++I) {
7671 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7672 TypeLocBuilder TLB;
7673 TLB.reserve(PatternTL.getFullDataSize());
7674 QualType To = getDerived().TransformType(TLB, PatternTL);
7675 if (To.isNull())
7676 return ExprError();
7677
7678 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7679 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007680
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007681 if (!RetainExpansion)
7682 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007683
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007684 // If we're supposed to retain a pack expansion, do so by temporarily
7685 // forgetting the partially-substituted parameter pack.
7686 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7687
7688 TypeLocBuilder TLB;
7689 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007690
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007691 QualType To = getDerived().TransformType(TLB, PatternTL);
7692 if (To.isNull())
7693 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007694
7695 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007696 PatternTL.getSourceRange(),
7697 ExpansionTL.getEllipsisLoc(),
7698 NumExpansions);
7699 if (To.isNull())
7700 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007701
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007702 PackExpansionTypeLoc ToExpansionTL
7703 = TLB.push<PackExpansionTypeLoc>(To);
7704 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7705 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7706 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007707
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007708 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7709 return SemaRef.Owned(E);
7710
7711 return getDerived().RebuildTypeTrait(E->getTrait(),
7712 E->getLocStart(),
7713 Args,
7714 E->getLocEnd());
7715}
7716
7717template<typename Derived>
7718ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007719TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7720 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7721 if (!T)
7722 return ExprError();
7723
7724 if (!getDerived().AlwaysRebuild() &&
7725 T == E->getQueriedTypeSourceInfo())
7726 return SemaRef.Owned(E);
7727
7728 ExprResult SubExpr;
7729 {
7730 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7731 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7732 if (SubExpr.isInvalid())
7733 return ExprError();
7734
7735 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7736 return SemaRef.Owned(E);
7737 }
7738
7739 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7740 E->getLocStart(),
7741 T,
7742 SubExpr.get(),
7743 E->getLocEnd());
7744}
7745
7746template<typename Derived>
7747ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007748TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7749 ExprResult SubExpr;
7750 {
7751 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7752 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7753 if (SubExpr.isInvalid())
7754 return ExprError();
7755
7756 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7757 return SemaRef.Owned(E);
7758 }
7759
7760 return getDerived().RebuildExpressionTrait(
7761 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7762}
7763
7764template<typename Derived>
7765ExprResult
John McCall865d4472009-11-19 22:55:06 +00007766TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007767 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00007768 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
7769}
7770
7771template<typename Derived>
7772ExprResult
7773TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
7774 DependentScopeDeclRefExpr *E,
7775 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007776 NestedNameSpecifierLoc QualifierLoc
7777 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7778 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007779 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007780 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007781
John McCall43fed0d2010-11-12 08:19:04 +00007782 // TODO: If this is a conversion-function-id, verify that the
7783 // destination type name (if present) resolves the same way after
7784 // instantiation as it did in the local scope.
7785
Abramo Bagnara25777432010-08-11 22:01:17 +00007786 DeclarationNameInfo NameInfo
7787 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7788 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007789 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007790
John McCallf7a1a742009-11-24 19:00:30 +00007791 if (!E->hasExplicitTemplateArgs()) {
7792 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007793 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007794 // Note: it is sufficient to compare the Name component of NameInfo:
7795 // if name has not changed, DNLoc has not changed either.
7796 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007797 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007798
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007799 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007800 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007801 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007802 /*TemplateArgs*/ 0,
7803 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007804 }
John McCalld5532b62009-11-23 01:53:49 +00007805
7806 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007807 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7808 E->getNumTemplateArgs(),
7809 TransArgs))
7810 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007811
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007812 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007813 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007814 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007815 &TransArgs,
7816 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007817}
7818
7819template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007820ExprResult
John McCall454feb92009-12-08 09:21:05 +00007821TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00007822 // CXXConstructExprs other than for list-initialization and
7823 // CXXTemporaryObjectExpr are always implicit, so when we have
7824 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00007825 if ((E->getNumArgs() == 1 ||
7826 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00007827 (!getDerived().DropCallArgument(E->getArg(0))) &&
7828 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00007829 return getDerived().TransformExpr(E->getArg(0));
7830
Douglas Gregorb98b1992009-08-11 05:31:07 +00007831 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7832
7833 QualType T = getDerived().TransformType(E->getType());
7834 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007835 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007836
7837 CXXConstructorDecl *Constructor
7838 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007839 getDerived().TransformDecl(E->getLocStart(),
7840 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007841 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007842 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007843
Douglas Gregorb98b1992009-08-11 05:31:07 +00007844 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007845 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007846 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007847 &ArgumentChanged))
7848 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007849
Douglas Gregorb98b1992009-08-11 05:31:07 +00007850 if (!getDerived().AlwaysRebuild() &&
7851 T == E->getType() &&
7852 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007853 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007854 // Mark the constructor as referenced.
7855 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007856 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007857 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007858 }
Mike Stump1eb44332009-09-09 15:08:12 +00007859
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007860 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7861 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007862 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007863 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00007864 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007865 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007866 E->getConstructionKind(),
7867 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007868}
Mike Stump1eb44332009-09-09 15:08:12 +00007869
Douglas Gregorb98b1992009-08-11 05:31:07 +00007870/// \brief Transform a C++ temporary-binding expression.
7871///
Douglas Gregor51326552009-12-24 18:51:59 +00007872/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7873/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007874template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007875ExprResult
John McCall454feb92009-12-08 09:21:05 +00007876TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007877 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007878}
Mike Stump1eb44332009-09-09 15:08:12 +00007879
John McCall4765fa02010-12-06 08:20:24 +00007880/// \brief Transform a C++ expression that contains cleanups that should
7881/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007882///
John McCall4765fa02010-12-06 08:20:24 +00007883/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007884/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007885template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007886ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007887TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007888 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007889}
Mike Stump1eb44332009-09-09 15:08:12 +00007890
Douglas Gregorb98b1992009-08-11 05:31:07 +00007891template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007892ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007893TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007894 CXXTemporaryObjectExpr *E) {
7895 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7896 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007897 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007898
Douglas Gregorb98b1992009-08-11 05:31:07 +00007899 CXXConstructorDecl *Constructor
7900 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00007901 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007902 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007903 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007904 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007905
Douglas Gregorb98b1992009-08-11 05:31:07 +00007906 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007907 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007908 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007909 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007910 &ArgumentChanged))
7911 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007912
Douglas Gregorb98b1992009-08-11 05:31:07 +00007913 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007914 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007915 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007916 !ArgumentChanged) {
7917 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007918 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007919 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007920 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007921
Richard Smithc83c2302012-12-19 01:39:02 +00007922 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00007923 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7924 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007925 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007926 E->getLocEnd());
7927}
Mike Stump1eb44332009-09-09 15:08:12 +00007928
Douglas Gregorb98b1992009-08-11 05:31:07 +00007929template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007930ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007931TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007932 // Transform the type of the lambda parameters and start the definition of
7933 // the lambda itself.
7934 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00007935 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00007936 if (!MethodTy)
7937 return ExprError();
7938
Eli Friedman8da8a662012-09-19 01:18:11 +00007939 // Create the local class that will describe the lambda.
7940 CXXRecordDecl *Class
7941 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7942 MethodTy,
7943 /*KnownDependent=*/false);
7944 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7945
Douglas Gregorc6889e72012-02-14 22:28:59 +00007946 // Transform lambda parameters.
Douglas Gregorc6889e72012-02-14 22:28:59 +00007947 llvm::SmallVector<QualType, 4> ParamTypes;
7948 llvm::SmallVector<ParmVarDecl *, 4> Params;
7949 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7950 E->getCallOperator()->param_begin(),
7951 E->getCallOperator()->param_size(),
7952 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00007953 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00007954
Douglas Gregordfca6f52012-02-13 22:00:16 +00007955 // Build the call operator.
7956 CXXMethodDecl *CallOperator
7957 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007958 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007959 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007960 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007961 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00007962
Richard Smith612409e2012-07-25 03:56:55 +00007963 return getDerived().TransformLambdaScope(E, CallOperator);
7964}
7965
7966template<typename Derived>
7967ExprResult
7968TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
7969 CXXMethodDecl *CallOperator) {
Douglas Gregord5387e82012-02-14 00:00:48 +00007970 // Introduce the context of the call operator.
7971 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7972
Douglas Gregordfca6f52012-02-13 22:00:16 +00007973 // Enter the scope of the lambda.
7974 sema::LambdaScopeInfo *LSI
7975 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7976 E->getCaptureDefault(),
7977 E->hasExplicitParameters(),
7978 E->hasExplicitResultType(),
7979 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007980
Douglas Gregordfca6f52012-02-13 22:00:16 +00007981 // Transform captures.
Richard Smith612409e2012-07-25 03:56:55 +00007982 bool Invalid = false;
Douglas Gregordfca6f52012-02-13 22:00:16 +00007983 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007984 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007985 CEnd = E->capture_end();
7986 C != CEnd; ++C) {
7987 // When we hit the first implicit capture, tell Sema that we've finished
7988 // the list of explicit captures.
7989 if (!FinishedExplicitCaptures && C->isImplicit()) {
7990 getSema().finishLambdaExplicitCaptures(LSI);
7991 FinishedExplicitCaptures = true;
7992 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007993
Douglas Gregordfca6f52012-02-13 22:00:16 +00007994 // Capturing 'this' is trivial.
7995 if (C->capturesThis()) {
7996 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7997 continue;
7998 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007999
Douglas Gregora7365242012-02-14 19:27:52 +00008000 // Determine the capture kind for Sema.
8001 Sema::TryCaptureKind Kind
8002 = C->isImplicit()? Sema::TryCapture_Implicit
8003 : C->getCaptureKind() == LCK_ByCopy
8004 ? Sema::TryCapture_ExplicitByVal
8005 : Sema::TryCapture_ExplicitByRef;
8006 SourceLocation EllipsisLoc;
8007 if (C->isPackExpansion()) {
8008 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8009 bool ShouldExpand = false;
8010 bool RetainExpansion = false;
8011 llvm::Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008012 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8013 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008014 Unexpanded,
8015 ShouldExpand, RetainExpansion,
8016 NumExpansions))
8017 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008018
Douglas Gregora7365242012-02-14 19:27:52 +00008019 if (ShouldExpand) {
8020 // The transform has determined that we should perform an expansion;
8021 // transform and capture each of the arguments.
8022 // expansion of the pattern. Do so.
8023 VarDecl *Pack = C->getCapturedVar();
8024 for (unsigned I = 0; I != *NumExpansions; ++I) {
8025 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8026 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008027 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008028 Pack));
8029 if (!CapturedVar) {
8030 Invalid = true;
8031 continue;
8032 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008033
Douglas Gregora7365242012-02-14 19:27:52 +00008034 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008035 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8036 }
Douglas Gregora7365242012-02-14 19:27:52 +00008037 continue;
8038 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008039
Douglas Gregora7365242012-02-14 19:27:52 +00008040 EllipsisLoc = C->getEllipsisLoc();
8041 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008042
Douglas Gregordfca6f52012-02-13 22:00:16 +00008043 // Transform the captured variable.
8044 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008045 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008046 C->getCapturedVar()));
8047 if (!CapturedVar) {
8048 Invalid = true;
8049 continue;
8050 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008051
Douglas Gregordfca6f52012-02-13 22:00:16 +00008052 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008053 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008054 }
8055 if (!FinishedExplicitCaptures)
8056 getSema().finishLambdaExplicitCaptures(LSI);
8057
Douglas Gregordfca6f52012-02-13 22:00:16 +00008058
8059 // Enter a new evaluation context to insulate the lambda from any
8060 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008061 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008062
8063 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008064 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008065 /*IsInstantiation=*/true);
8066 return ExprError();
8067 }
8068
8069 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008070 StmtResult Body = getDerived().TransformStmt(E->getBody());
8071 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008072 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008073 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008074 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008075 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008076
Chad Rosier4a9d7952012-08-08 18:46:20 +00008077 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008078 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008079}
8080
8081template<typename Derived>
8082ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008083TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008084 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008085 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8086 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008087 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008088
Douglas Gregorb98b1992009-08-11 05:31:07 +00008089 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008090 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008091 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008092 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008093 &ArgumentChanged))
8094 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008095
Douglas Gregorb98b1992009-08-11 05:31:07 +00008096 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008097 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008098 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008099 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008100
Douglas Gregorb98b1992009-08-11 05:31:07 +00008101 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008102 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008103 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008104 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008105 E->getRParenLoc());
8106}
Mike Stump1eb44332009-09-09 15:08:12 +00008107
Douglas Gregorb98b1992009-08-11 05:31:07 +00008108template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008109ExprResult
John McCall865d4472009-11-19 22:55:06 +00008110TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008111 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008112 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008113 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008114 Expr *OldBase;
8115 QualType BaseType;
8116 QualType ObjectType;
8117 if (!E->isImplicitAccess()) {
8118 OldBase = E->getBase();
8119 Base = getDerived().TransformExpr(OldBase);
8120 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008121 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008122
John McCallaa81e162009-12-01 22:10:20 +00008123 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008124 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008125 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008126 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008127 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008128 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008129 ObjectTy,
8130 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008131 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008132 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008133
John McCallb3d87482010-08-24 05:47:05 +00008134 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008135 BaseType = ((Expr*) Base.get())->getType();
8136 } else {
8137 OldBase = 0;
8138 BaseType = getDerived().TransformType(E->getBaseType());
8139 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8140 }
Mike Stump1eb44332009-09-09 15:08:12 +00008141
Douglas Gregor6cd21982009-10-20 05:58:46 +00008142 // Transform the first part of the nested-name-specifier that qualifies
8143 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008144 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008145 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008146 E->getFirstQualifierFoundInScope(),
8147 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008148
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008149 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008150 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008151 QualifierLoc
8152 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8153 ObjectType,
8154 FirstQualifierInScope);
8155 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008156 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008157 }
Mike Stump1eb44332009-09-09 15:08:12 +00008158
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008159 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8160
John McCall43fed0d2010-11-12 08:19:04 +00008161 // TODO: If this is a conversion-function-id, verify that the
8162 // destination type name (if present) resolves the same way after
8163 // instantiation as it did in the local scope.
8164
Abramo Bagnara25777432010-08-11 22:01:17 +00008165 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008166 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008167 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008168 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008169
John McCallaa81e162009-12-01 22:10:20 +00008170 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008171 // This is a reference to a member without an explicitly-specified
8172 // template argument list. Optimize for this common case.
8173 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008174 Base.get() == OldBase &&
8175 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008176 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008177 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008178 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008179 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008180
John McCall9ae2f072010-08-23 23:25:46 +00008181 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008182 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008183 E->isArrow(),
8184 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008185 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008186 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008187 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008188 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008189 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008190 }
8191
John McCalld5532b62009-11-23 01:53:49 +00008192 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008193 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8194 E->getNumTemplateArgs(),
8195 TransArgs))
8196 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008197
John McCall9ae2f072010-08-23 23:25:46 +00008198 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008199 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008200 E->isArrow(),
8201 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008202 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008203 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008204 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008205 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008206 &TransArgs);
8207}
8208
8209template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008210ExprResult
John McCall454feb92009-12-08 09:21:05 +00008211TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008212 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008213 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008214 QualType BaseType;
8215 if (!Old->isImplicitAccess()) {
8216 Base = getDerived().TransformExpr(Old->getBase());
8217 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008218 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008219 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8220 Old->isArrow());
8221 if (Base.isInvalid())
8222 return ExprError();
8223 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008224 } else {
8225 BaseType = getDerived().TransformType(Old->getBaseType());
8226 }
John McCall129e2df2009-11-30 22:42:35 +00008227
Douglas Gregor4c9be892011-02-28 20:01:57 +00008228 NestedNameSpecifierLoc QualifierLoc;
8229 if (Old->getQualifierLoc()) {
8230 QualifierLoc
8231 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8232 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008233 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008234 }
8235
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008236 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8237
Abramo Bagnara25777432010-08-11 22:01:17 +00008238 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008239 Sema::LookupOrdinaryName);
8240
8241 // Transform all the decls.
8242 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8243 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008244 NamedDecl *InstD = static_cast<NamedDecl*>(
8245 getDerived().TransformDecl(Old->getMemberLoc(),
8246 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008247 if (!InstD) {
8248 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8249 // This can happen because of dependent hiding.
8250 if (isa<UsingShadowDecl>(*I))
8251 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008252 else {
8253 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008254 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008255 }
John McCall9f54ad42009-12-10 09:41:52 +00008256 }
John McCall129e2df2009-11-30 22:42:35 +00008257
8258 // Expand using declarations.
8259 if (isa<UsingDecl>(InstD)) {
8260 UsingDecl *UD = cast<UsingDecl>(InstD);
8261 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8262 E = UD->shadow_end(); I != E; ++I)
8263 R.addDecl(*I);
8264 continue;
8265 }
8266
8267 R.addDecl(InstD);
8268 }
8269
8270 R.resolveKind();
8271
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008272 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008273 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008274 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008275 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008276 Old->getMemberLoc(),
8277 Old->getNamingClass()));
8278 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008279 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008280
Douglas Gregor66c45152010-04-27 16:10:10 +00008281 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008282 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008283
John McCall129e2df2009-11-30 22:42:35 +00008284 TemplateArgumentListInfo TransArgs;
8285 if (Old->hasExplicitTemplateArgs()) {
8286 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8287 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008288 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8289 Old->getNumTemplateArgs(),
8290 TransArgs))
8291 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008292 }
John McCallc2233c52010-01-15 08:34:02 +00008293
8294 // FIXME: to do this check properly, we will need to preserve the
8295 // first-qualifier-in-scope here, just in case we had a dependent
8296 // base (and therefore couldn't do the check) and a
8297 // nested-name-qualifier (and therefore could do the lookup).
8298 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008299
John McCall9ae2f072010-08-23 23:25:46 +00008300 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008301 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008302 Old->getOperatorLoc(),
8303 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008304 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008305 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008306 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008307 R,
8308 (Old->hasExplicitTemplateArgs()
8309 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008310}
8311
8312template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008313ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008314TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008315 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008316 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8317 if (SubExpr.isInvalid())
8318 return ExprError();
8319
8320 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008321 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008322
8323 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8324}
8325
8326template<typename Derived>
8327ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008328TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008329 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8330 if (Pattern.isInvalid())
8331 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008332
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008333 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8334 return SemaRef.Owned(E);
8335
Douglas Gregor67fd1252011-01-14 21:20:45 +00008336 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8337 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008338}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008339
8340template<typename Derived>
8341ExprResult
8342TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8343 // If E is not value-dependent, then nothing will change when we transform it.
8344 // Note: This is an instantiation-centric view.
8345 if (!E->isValueDependent())
8346 return SemaRef.Owned(E);
8347
8348 // Note: None of the implementations of TryExpandParameterPacks can ever
8349 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008350 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008351 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8352 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008353 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008354 llvm::Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008355 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008356 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008357 ShouldExpand, RetainExpansion,
8358 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008359 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008360
Douglas Gregor089e8932011-10-10 18:59:29 +00008361 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008362 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008363
Douglas Gregor089e8932011-10-10 18:59:29 +00008364 NamedDecl *Pack = E->getPack();
8365 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008366 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008367 Pack));
8368 if (!Pack)
8369 return ExprError();
8370 }
8371
Chad Rosier4a9d7952012-08-08 18:46:20 +00008372
Douglas Gregoree8aff02011-01-04 17:33:58 +00008373 // We now know the length of the parameter pack, so build a new expression
8374 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008375 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8376 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008377 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008378}
8379
Douglas Gregorbe230c32011-01-03 17:17:50 +00008380template<typename Derived>
8381ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008382TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8383 SubstNonTypeTemplateParmPackExpr *E) {
8384 // Default behavior is to do nothing with this transformation.
8385 return SemaRef.Owned(E);
8386}
8387
8388template<typename Derived>
8389ExprResult
John McCall91a57552011-07-15 05:09:51 +00008390TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8391 SubstNonTypeTemplateParmExpr *E) {
8392 // Default behavior is to do nothing with this transformation.
8393 return SemaRef.Owned(E);
8394}
8395
8396template<typename Derived>
8397ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008398TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8399 // Default behavior is to do nothing with this transformation.
8400 return SemaRef.Owned(E);
8401}
8402
8403template<typename Derived>
8404ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008405TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8406 MaterializeTemporaryExpr *E) {
8407 return getDerived().TransformExpr(E->GetTemporaryExpr());
8408}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008409
Douglas Gregor03e80032011-06-21 17:03:29 +00008410template<typename Derived>
8411ExprResult
John McCall454feb92009-12-08 09:21:05 +00008412TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008413 return SemaRef.MaybeBindToTemporary(E);
8414}
8415
8416template<typename Derived>
8417ExprResult
8418TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008419 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008420}
8421
8422template<typename Derived>
8423ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008424TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8425 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8426 if (SubExpr.isInvalid())
8427 return ExprError();
8428
8429 if (!getDerived().AlwaysRebuild() &&
8430 SubExpr.get() == E->getSubExpr())
8431 return SemaRef.Owned(E);
8432
8433 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008434}
8435
8436template<typename Derived>
8437ExprResult
8438TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8439 // Transform each of the elements.
8440 llvm::SmallVector<Expr *, 8> Elements;
8441 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008442 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008443 /*IsCall=*/false, Elements, &ArgChanged))
8444 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008445
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008446 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8447 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008448
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008449 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8450 Elements.data(),
8451 Elements.size());
8452}
8453
8454template<typename Derived>
8455ExprResult
8456TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008457 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008458 // Transform each of the elements.
8459 llvm::SmallVector<ObjCDictionaryElement, 8> Elements;
8460 bool ArgChanged = false;
8461 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8462 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008463
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008464 if (OrigElement.isPackExpansion()) {
8465 // This key/value element is a pack expansion.
8466 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8467 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8468 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8469 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8470
8471 // Determine whether the set of unexpanded parameter packs can
8472 // and should be expanded.
8473 bool Expand = true;
8474 bool RetainExpansion = false;
8475 llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8476 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
8477 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8478 OrigElement.Value->getLocEnd());
8479 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8480 PatternRange,
8481 Unexpanded,
8482 Expand, RetainExpansion,
8483 NumExpansions))
8484 return ExprError();
8485
8486 if (!Expand) {
8487 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008488 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008489 // expansion.
8490 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8491 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8492 if (Key.isInvalid())
8493 return ExprError();
8494
8495 if (Key.get() != OrigElement.Key)
8496 ArgChanged = true;
8497
8498 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8499 if (Value.isInvalid())
8500 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008501
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008502 if (Value.get() != OrigElement.Value)
8503 ArgChanged = true;
8504
Chad Rosier4a9d7952012-08-08 18:46:20 +00008505 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008506 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8507 };
8508 Elements.push_back(Expansion);
8509 continue;
8510 }
8511
8512 // Record right away that the argument was changed. This needs
8513 // to happen even if the array expands to nothing.
8514 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008515
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008516 // The transform has determined that we should perform an elementwise
8517 // expansion of the pattern. Do so.
8518 for (unsigned I = 0; I != *NumExpansions; ++I) {
8519 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8520 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8521 if (Key.isInvalid())
8522 return ExprError();
8523
8524 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8525 if (Value.isInvalid())
8526 return ExprError();
8527
Chad Rosier4a9d7952012-08-08 18:46:20 +00008528 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008529 Key.get(), Value.get(), SourceLocation(), NumExpansions
8530 };
8531
8532 // If any unexpanded parameter packs remain, we still have a
8533 // pack expansion.
8534 if (Key.get()->containsUnexpandedParameterPack() ||
8535 Value.get()->containsUnexpandedParameterPack())
8536 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008537
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008538 Elements.push_back(Element);
8539 }
8540
8541 // We've finished with this pack expansion.
8542 continue;
8543 }
8544
8545 // Transform and check key.
8546 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8547 if (Key.isInvalid())
8548 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008549
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008550 if (Key.get() != OrigElement.Key)
8551 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008552
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008553 // Transform and check value.
8554 ExprResult Value
8555 = getDerived().TransformExpr(OrigElement.Value);
8556 if (Value.isInvalid())
8557 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008558
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008559 if (Value.get() != OrigElement.Value)
8560 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008561
8562 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008563 Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8564 };
8565 Elements.push_back(Element);
8566 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008567
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008568 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8569 return SemaRef.MaybeBindToTemporary(E);
8570
8571 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8572 Elements.data(),
8573 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008574}
8575
Mike Stump1eb44332009-09-09 15:08:12 +00008576template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008577ExprResult
John McCall454feb92009-12-08 09:21:05 +00008578TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008579 TypeSourceInfo *EncodedTypeInfo
8580 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8581 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008582 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008583
Douglas Gregorb98b1992009-08-11 05:31:07 +00008584 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008585 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008586 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008587
8588 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008589 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008590 E->getRParenLoc());
8591}
Mike Stump1eb44332009-09-09 15:08:12 +00008592
Douglas Gregorb98b1992009-08-11 05:31:07 +00008593template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008594ExprResult TreeTransform<Derived>::
8595TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8596 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8597 if (result.isInvalid()) return ExprError();
8598 Expr *subExpr = result.take();
8599
8600 if (!getDerived().AlwaysRebuild() &&
8601 subExpr == E->getSubExpr())
8602 return SemaRef.Owned(E);
8603
8604 return SemaRef.Owned(new(SemaRef.Context)
8605 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8606}
8607
8608template<typename Derived>
8609ExprResult TreeTransform<Derived>::
8610TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008611 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008612 = getDerived().TransformType(E->getTypeInfoAsWritten());
8613 if (!TSInfo)
8614 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008615
John McCallf85e1932011-06-15 23:02:42 +00008616 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008617 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008618 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008619
John McCallf85e1932011-06-15 23:02:42 +00008620 if (!getDerived().AlwaysRebuild() &&
8621 TSInfo == E->getTypeInfoAsWritten() &&
8622 Result.get() == E->getSubExpr())
8623 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008624
John McCallf85e1932011-06-15 23:02:42 +00008625 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008626 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008627 Result.get());
8628}
8629
8630template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008631ExprResult
John McCall454feb92009-12-08 09:21:05 +00008632TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008633 // Transform arguments.
8634 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008635 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008636 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008637 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008638 &ArgChanged))
8639 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008640
Douglas Gregor92e986e2010-04-22 16:44:27 +00008641 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8642 // Class message: transform the receiver type.
8643 TypeSourceInfo *ReceiverTypeInfo
8644 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8645 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008646 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008647
Douglas Gregor92e986e2010-04-22 16:44:27 +00008648 // If nothing changed, just retain the existing message send.
8649 if (!getDerived().AlwaysRebuild() &&
8650 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008651 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008652
8653 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008654 SmallVector<SourceLocation, 16> SelLocs;
8655 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008656 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8657 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008658 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008659 E->getMethodDecl(),
8660 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008661 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008662 E->getRightLoc());
8663 }
8664
8665 // Instance message: transform the receiver
8666 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8667 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008668 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008669 = getDerived().TransformExpr(E->getInstanceReceiver());
8670 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008671 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008672
8673 // If nothing changed, just retain the existing message send.
8674 if (!getDerived().AlwaysRebuild() &&
8675 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008676 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008677
Douglas Gregor92e986e2010-04-22 16:44:27 +00008678 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008679 SmallVector<SourceLocation, 16> SelLocs;
8680 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008681 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008682 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008683 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008684 E->getMethodDecl(),
8685 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008686 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008687 E->getRightLoc());
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>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008693 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008694}
8695
Mike Stump1eb44332009-09-09 15:08:12 +00008696template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008697ExprResult
John McCall454feb92009-12-08 09:21:05 +00008698TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008699 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008700}
8701
Mike Stump1eb44332009-09-09 15:08:12 +00008702template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008703ExprResult
John McCall454feb92009-12-08 09:21:05 +00008704TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008705 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008706 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008707 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008708 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008709
8710 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008711
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008712 // If nothing changed, just retain the existing expression.
8713 if (!getDerived().AlwaysRebuild() &&
8714 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008715 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008716
John McCall9ae2f072010-08-23 23:25:46 +00008717 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008718 E->getLocation(),
8719 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008720}
8721
Mike Stump1eb44332009-09-09 15:08:12 +00008722template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008723ExprResult
John McCall454feb92009-12-08 09:21:05 +00008724TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008725 // 'super' and types never change. Property never changes. Just
8726 // retain the existing expression.
8727 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008728 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008729
Douglas Gregore3303542010-04-26 20:47:02 +00008730 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008731 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008732 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008733 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008734
Douglas Gregore3303542010-04-26 20:47:02 +00008735 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008736
Douglas Gregore3303542010-04-26 20:47:02 +00008737 // If nothing changed, just retain the existing expression.
8738 if (!getDerived().AlwaysRebuild() &&
8739 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008740 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008741
John McCall12f78a62010-12-02 01:19:52 +00008742 if (E->isExplicitProperty())
8743 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8744 E->getExplicitProperty(),
8745 E->getLocation());
8746
8747 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008748 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008749 E->getImplicitPropertyGetter(),
8750 E->getImplicitPropertySetter(),
8751 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008752}
8753
Mike Stump1eb44332009-09-09 15:08:12 +00008754template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008755ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008756TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8757 // Transform the base expression.
8758 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8759 if (Base.isInvalid())
8760 return ExprError();
8761
8762 // Transform the key expression.
8763 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8764 if (Key.isInvalid())
8765 return ExprError();
8766
8767 // If nothing changed, just retain the existing expression.
8768 if (!getDerived().AlwaysRebuild() &&
8769 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8770 return SemaRef.Owned(E);
8771
Chad Rosier4a9d7952012-08-08 18:46:20 +00008772 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008773 Base.get(), Key.get(),
8774 E->getAtIndexMethodDecl(),
8775 E->setAtIndexMethodDecl());
8776}
8777
8778template<typename Derived>
8779ExprResult
John McCall454feb92009-12-08 09:21:05 +00008780TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008781 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008782 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008783 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008784 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008785
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008786 // If nothing changed, just retain the existing expression.
8787 if (!getDerived().AlwaysRebuild() &&
8788 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008789 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008790
John McCall9ae2f072010-08-23 23:25:46 +00008791 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008792 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008793}
8794
Mike Stump1eb44332009-09-09 15:08:12 +00008795template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008796ExprResult
John McCall454feb92009-12-08 09:21:05 +00008797TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008798 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008799 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008800 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008801 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008802 SubExprs, &ArgumentChanged))
8803 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008804
Douglas Gregorb98b1992009-08-11 05:31:07 +00008805 if (!getDerived().AlwaysRebuild() &&
8806 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008807 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008808
Douglas Gregorb98b1992009-08-11 05:31:07 +00008809 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008810 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008811 E->getRParenLoc());
8812}
8813
Mike Stump1eb44332009-09-09 15:08:12 +00008814template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008815ExprResult
John McCall454feb92009-12-08 09:21:05 +00008816TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008817 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008818
John McCallc6ac9c32011-02-04 18:33:18 +00008819 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8820 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8821
8822 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008823 blockScope->TheDecl->setBlockMissingReturnType(
8824 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008825
Chris Lattner686775d2011-07-20 06:58:45 +00008826 SmallVector<ParmVarDecl*, 4> params;
8827 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008828
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008829 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008830 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8831 oldBlock->param_begin(),
8832 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008833 0, paramTypes, &params)) {
8834 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008835 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008836 }
John McCallc6ac9c32011-02-04 18:33:18 +00008837
8838 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008839 QualType exprResultType =
8840 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008841
8842 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008843 if (exprResultType->isObjCObjectType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008844 getSema().Diag(E->getCaretLocation(),
8845 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008846 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008847 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008848 return ExprError();
8849 }
John McCall711c52b2011-01-05 12:14:39 +00008850
John McCallc6ac9c32011-02-04 18:33:18 +00008851 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008852 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008853 paramTypes.data(),
8854 paramTypes.size(),
8855 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008856 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008857 exprFunctionType->getExtInfo());
8858 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008859
8860 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008861 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008862 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008863
8864 if (!oldBlock->blockMissingReturnType()) {
8865 blockScope->HasImplicitReturnType = false;
8866 blockScope->ReturnType = exprResultType;
8867 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008868
John McCall711c52b2011-01-05 12:14:39 +00008869 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008870 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008871 if (body.isInvalid()) {
8872 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008873 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008874 }
John McCall711c52b2011-01-05 12:14:39 +00008875
John McCallc6ac9c32011-02-04 18:33:18 +00008876#ifndef NDEBUG
8877 // In builds with assertions, make sure that we captured everything we
8878 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008879 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8880 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8881 e = oldBlock->capture_end(); i != e; ++i) {
8882 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008883
Douglas Gregorfc921372011-05-20 15:32:55 +00008884 // Ignore parameter packs.
8885 if (isa<ParmVarDecl>(oldCapture) &&
8886 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8887 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008888
Douglas Gregorfc921372011-05-20 15:32:55 +00008889 VarDecl *newCapture =
8890 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8891 oldCapture));
8892 assert(blockScope->CaptureMap.count(newCapture));
8893 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008894 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008895 }
8896#endif
8897
8898 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8899 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008900}
8901
Mike Stump1eb44332009-09-09 15:08:12 +00008902template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008903ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008904TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008905 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008906}
Eli Friedman276b0612011-10-11 02:20:01 +00008907
8908template<typename Derived>
8909ExprResult
8910TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008911 QualType RetTy = getDerived().TransformType(E->getType());
8912 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008913 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008914 SubExprs.reserve(E->getNumSubExprs());
8915 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8916 SubExprs, &ArgumentChanged))
8917 return ExprError();
8918
8919 if (!getDerived().AlwaysRebuild() &&
8920 !ArgumentChanged)
8921 return SemaRef.Owned(E);
8922
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008923 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008924 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008925}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008926
Douglas Gregorb98b1992009-08-11 05:31:07 +00008927//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008928// Type reconstruction
8929//===----------------------------------------------------------------------===//
8930
Mike Stump1eb44332009-09-09 15:08:12 +00008931template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008932QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8933 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008934 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008935 getDerived().getBaseEntity());
8936}
8937
Mike Stump1eb44332009-09-09 15:08:12 +00008938template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008939QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8940 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008941 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008942 getDerived().getBaseEntity());
8943}
8944
Mike Stump1eb44332009-09-09 15:08:12 +00008945template<typename Derived>
8946QualType
John McCall85737a72009-10-30 00:06:24 +00008947TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8948 bool WrittenAsLValue,
8949 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008950 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008951 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008952}
8953
8954template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008955QualType
John McCall85737a72009-10-30 00:06:24 +00008956TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8957 QualType ClassType,
8958 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008959 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008960 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008961}
8962
8963template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008964QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008965TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8966 ArrayType::ArraySizeModifier SizeMod,
8967 const llvm::APInt *Size,
8968 Expr *SizeExpr,
8969 unsigned IndexTypeQuals,
8970 SourceRange BracketsRange) {
8971 if (SizeExpr || !Size)
8972 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8973 IndexTypeQuals, BracketsRange,
8974 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008975
8976 QualType Types[] = {
8977 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8978 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8979 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008980 };
8981 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8982 QualType SizeType;
8983 for (unsigned I = 0; I != NumTypes; ++I)
8984 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8985 SizeType = Types[I];
8986 break;
8987 }
Mike Stump1eb44332009-09-09 15:08:12 +00008988
Eli Friedman01f276d2012-01-25 23:20:27 +00008989 // Note that we can return a VariableArrayType here in the case where
8990 // the element type was a dependent VariableArrayType.
8991 IntegerLiteral *ArraySize
8992 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8993 /*FIXME*/BracketsRange.getBegin());
8994 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008995 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008996 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008997}
Mike Stump1eb44332009-09-09 15:08:12 +00008998
Douglas Gregor577f75a2009-08-04 16:50:30 +00008999template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009000QualType
9001TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009002 ArrayType::ArraySizeModifier SizeMod,
9003 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009004 unsigned IndexTypeQuals,
9005 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009006 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009007 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009008}
9009
9010template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009011QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009012TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009013 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009014 unsigned IndexTypeQuals,
9015 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009016 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009017 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009018}
Mike Stump1eb44332009-09-09 15:08:12 +00009019
Douglas Gregor577f75a2009-08-04 16:50:30 +00009020template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009021QualType
9022TreeTransform<Derived>::RebuildVariableArrayType(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>
Mike Stump1eb44332009-09-09 15:08:12 +00009033QualType
9034TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009035 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009036 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009037 unsigned IndexTypeQuals,
9038 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009039 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009040 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009041 IndexTypeQuals, BracketsRange);
9042}
9043
9044template<typename Derived>
9045QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009046 unsigned NumElements,
9047 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009048 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009049 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
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>
9053QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9054 unsigned NumElements,
9055 SourceLocation AttributeLoc) {
9056 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9057 NumElements, true);
9058 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009059 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9060 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009061 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009062}
Mike Stump1eb44332009-09-09 15:08:12 +00009063
Douglas Gregor577f75a2009-08-04 16:50:30 +00009064template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009065QualType
9066TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009067 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009068 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009069 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009070}
Mike Stump1eb44332009-09-09 15:08:12 +00009071
Douglas Gregor577f75a2009-08-04 16:50:30 +00009072template<typename Derived>
9073QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00009074 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009075 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00009076 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009077 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00009078 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00009079 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00009080 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00009081 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009082 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009083 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009084 getDerived().getBaseEntity(),
9085 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009086}
Mike Stump1eb44332009-09-09 15:08:12 +00009087
Douglas Gregor577f75a2009-08-04 16:50:30 +00009088template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009089QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9090 return SemaRef.Context.getFunctionNoProtoType(T);
9091}
9092
9093template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009094QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9095 assert(D && "no decl found");
9096 if (D->isInvalidDecl()) return QualType();
9097
Douglas Gregor92e986e2010-04-22 16:44:27 +00009098 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009099 TypeDecl *Ty;
9100 if (isa<UsingDecl>(D)) {
9101 UsingDecl *Using = cast<UsingDecl>(D);
9102 assert(Using->isTypeName() &&
9103 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9104
9105 // A valid resolved using typename decl points to exactly one type decl.
9106 assert(++Using->shadow_begin() == Using->shadow_end());
9107 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009108
John McCalled976492009-12-04 22:46:56 +00009109 } else {
9110 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9111 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9112 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9113 }
9114
9115 return SemaRef.Context.getTypeDeclType(Ty);
9116}
9117
9118template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009119QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9120 SourceLocation Loc) {
9121 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009122}
9123
9124template<typename Derived>
9125QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9126 return SemaRef.Context.getTypeOfType(Underlying);
9127}
9128
9129template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009130QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9131 SourceLocation Loc) {
9132 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009133}
9134
9135template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009136QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9137 UnaryTransformType::UTTKind UKind,
9138 SourceLocation Loc) {
9139 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9140}
9141
9142template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009143QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009144 TemplateName Template,
9145 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009146 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009147 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009148}
Mike Stump1eb44332009-09-09 15:08:12 +00009149
Douglas Gregordcee1a12009-08-06 05:28:30 +00009150template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009151QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9152 SourceLocation KWLoc) {
9153 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9154}
9155
9156template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009157TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009158TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009159 bool TemplateKW,
9160 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009161 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009162 Template);
9163}
9164
9165template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009166TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009167TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9168 const IdentifierInfo &Name,
9169 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009170 QualType ObjectType,
9171 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009172 UnqualifiedId TemplateName;
9173 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009174 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009175 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009176 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009177 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009178 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009179 /*EnteringContext=*/false,
9180 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009181 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009182}
Mike Stump1eb44332009-09-09 15:08:12 +00009183
Douglas Gregorb98b1992009-08-11 05:31:07 +00009184template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009185TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009186TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009187 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009188 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009189 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009190 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009191 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009192 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009193 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009194 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009195 Sema::TemplateTy Template;
9196 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009197 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009198 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009199 /*EnteringContext=*/false,
9200 Template);
9201 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009202}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009203
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009204template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009205ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009206TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9207 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009208 Expr *OrigCallee,
9209 Expr *First,
9210 Expr *Second) {
9211 Expr *Callee = OrigCallee->IgnoreParenCasts();
9212 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009213
Douglas Gregorb98b1992009-08-11 05:31:07 +00009214 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009215 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009216 if (!First->getType()->isOverloadableType() &&
9217 !Second->getType()->isOverloadableType())
9218 return getSema().CreateBuiltinArraySubscriptExpr(First,
9219 Callee->getLocStart(),
9220 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009221 } else if (Op == OO_Arrow) {
9222 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009223 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9224 } else if (Second == 0 || isPostIncDec) {
9225 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009226 // The argument is not of overloadable type, so try to create a
9227 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009228 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009229 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009230
John McCall9ae2f072010-08-23 23:25:46 +00009231 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009232 }
9233 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009234 if (!First->getType()->isOverloadableType() &&
9235 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009236 // Neither of the arguments is an overloadable type, so try to
9237 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009238 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009239 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009240 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009241 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009242 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009243
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009244 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009245 }
9246 }
Mike Stump1eb44332009-09-09 15:08:12 +00009247
9248 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009249 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009250 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009251
John McCall9ae2f072010-08-23 23:25:46 +00009252 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009253 assert(ULE->requiresADL());
9254
9255 // FIXME: Do we have to check
9256 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009257 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009258 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009259 // If we've resolved this to a particular non-member function, just call
9260 // that function. If we resolved it to a member function,
9261 // CreateOverloaded* will find that function for us.
9262 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9263 if (!isa<CXXMethodDecl>(ND))
9264 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009265 }
Mike Stump1eb44332009-09-09 15:08:12 +00009266
Douglas Gregorb98b1992009-08-11 05:31:07 +00009267 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009268 Expr *Args[2] = { First, Second };
9269 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009270
Douglas Gregorb98b1992009-08-11 05:31:07 +00009271 // Create the overloaded operator invocation for unary operators.
9272 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009273 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009274 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009275 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009276 }
Mike Stump1eb44332009-09-09 15:08:12 +00009277
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009278 if (Op == OO_Subscript) {
9279 SourceLocation LBrace;
9280 SourceLocation RBrace;
9281
9282 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9283 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9284 LBrace = SourceLocation::getFromRawEncoding(
9285 NameLoc.CXXOperatorName.BeginOpNameLoc);
9286 RBrace = SourceLocation::getFromRawEncoding(
9287 NameLoc.CXXOperatorName.EndOpNameLoc);
9288 } else {
9289 LBrace = Callee->getLocStart();
9290 RBrace = OpLoc;
9291 }
9292
9293 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9294 First, Second);
9295 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009296
Douglas Gregorb98b1992009-08-11 05:31:07 +00009297 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009298 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009299 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009300 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9301 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009302 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009303
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009304 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009305}
Mike Stump1eb44332009-09-09 15:08:12 +00009306
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009307template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009308ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009309TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009310 SourceLocation OperatorLoc,
9311 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009312 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009313 TypeSourceInfo *ScopeType,
9314 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009315 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009316 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009317 QualType BaseType = Base->getType();
9318 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009319 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009320 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009321 !BaseType->getAs<PointerType>()->getPointeeType()
9322 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009323 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009324 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009325 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009326 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009327 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009328 /*FIXME?*/true);
9329 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009330
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009331 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009332 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9333 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9334 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9335 NameInfo.setNamedTypeInfo(DestroyedType);
9336
Richard Smith6314db92012-05-15 06:15:11 +00009337 // The scope type is now known to be a valid nested name specifier
9338 // component. Tack it on to the end of the nested name specifier.
9339 if (ScopeType)
9340 SS.Extend(SemaRef.Context, SourceLocation(),
9341 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009342
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009343 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009344 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009345 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009346 SS, TemplateKWLoc,
9347 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009348 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009349 /*TemplateArgs*/ 0);
9350}
9351
Douglas Gregor577f75a2009-08-04 16:50:30 +00009352} // end namespace clang
9353
9354#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H