blob: 0832a24d79135056281dca9455e8ca2fd126afce [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,
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +0000250 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000251 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000252 bool &RetainExpansion,
David Blaikiedc84cd52013-02-20 22:23:23 +0000253 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,
David Blaikiedc84cd52013-02-20 22:23:23 +0000575 Optional<unsigned> NumExpansions,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000576 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,
David Blaikiedc84cd52013-02-20 22:23:23 +0000953 Optional<unsigned> NumExpansions) {
Douglas Gregorcded4f62011-01-14 17:04:44 +0000954 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,
David Blaikiedc84cd52013-02-20 22:23:23 +00002228 Optional<unsigned> Length) {
Douglas Gregor089e8932011-10-10 18:59:29 +00002229 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,
David Blaikiedc84cd52013-02-20 22:23:23 +00002459 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,
David Blaikiedc84cd52013-02-20 22:23:23 +00002506 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002507 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
Richard Smith41956372013-01-14 22:39:08 +00002563 return getSema().ActOnExprStmt(E);
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;
David Blaikiedc84cd52013-02-20 22:23:23 +00002673 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2674 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002675 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2676 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002677 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002678 Expand, RetainExpansion,
2679 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002680 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002681
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002682 if (!Expand) {
2683 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002684 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002685 // expansion.
2686 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2687 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2688 if (OutPattern.isInvalid())
2689 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002690
2691 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002692 Expansion->getEllipsisLoc(),
2693 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002694 if (Out.isInvalid())
2695 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002696
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002697 if (ArgChanged)
2698 *ArgChanged = true;
2699 Outputs.push_back(Out.get());
2700 continue;
2701 }
John McCallc8fc90a2011-07-06 07:30:07 +00002702
2703 // Record right away that the argument was changed. This needs
2704 // to happen even if the array expands to nothing.
2705 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002706
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002707 // The transform has determined that we should perform an elementwise
2708 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002709 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002710 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2711 ExprResult Out = getDerived().TransformExpr(Pattern);
2712 if (Out.isInvalid())
2713 return true;
2714
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002715 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002716 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2717 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002718 if (Out.isInvalid())
2719 return true;
2720 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002721
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002722 Outputs.push_back(Out.get());
2723 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002724
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002725 continue;
2726 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002727
Richard Smithc83c2302012-12-19 01:39:02 +00002728 ExprResult Result =
2729 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2730 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002731 if (Result.isInvalid())
2732 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002733
Douglas Gregoraa165f82011-01-03 19:04:46 +00002734 if (Result.get() != Inputs[I] && ArgChanged)
2735 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002736
2737 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002738 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002739
Douglas Gregoraa165f82011-01-03 19:04:46 +00002740 return false;
2741}
2742
2743template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002744NestedNameSpecifierLoc
2745TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2746 NestedNameSpecifierLoc NNS,
2747 QualType ObjectType,
2748 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002749 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002750 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002751 Qualifier = Qualifier.getPrefix())
2752 Qualifiers.push_back(Qualifier);
2753
2754 CXXScopeSpec SS;
2755 while (!Qualifiers.empty()) {
2756 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2757 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002758
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002759 switch (QNNS->getKind()) {
2760 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002761 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002762 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002763 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002764 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002765 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002766 FirstQualifierInScope, false))
2767 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002768
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002769 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002770
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002771 case NestedNameSpecifier::Namespace: {
2772 NamespaceDecl *NS
2773 = cast_or_null<NamespaceDecl>(
2774 getDerived().TransformDecl(
2775 Q.getLocalBeginLoc(),
2776 QNNS->getAsNamespace()));
2777 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2778 break;
2779 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002780
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002781 case NestedNameSpecifier::NamespaceAlias: {
2782 NamespaceAliasDecl *Alias
2783 = cast_or_null<NamespaceAliasDecl>(
2784 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2785 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002786 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002787 Q.getLocalEndLoc());
2788 break;
2789 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002790
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002791 case NestedNameSpecifier::Global:
2792 // There is no meaningful transformation that one could perform on the
2793 // global scope.
2794 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2795 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002796
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002797 case NestedNameSpecifier::TypeSpecWithTemplate:
2798 case NestedNameSpecifier::TypeSpec: {
2799 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2800 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002801
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002802 if (!TL)
2803 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002804
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002805 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002806 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002807 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002808 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002809 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002810 if (TL.getType()->isEnumeralType())
2811 SemaRef.Diag(TL.getBeginLoc(),
2812 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002813 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2814 Q.getLocalEndLoc());
2815 break;
2816 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002817 // If the nested-name-specifier is an invalid type def, don't emit an
2818 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002819 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2820 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002821 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002822 << TL.getType() << SS.getRange();
2823 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002824 return NestedNameSpecifierLoc();
2825 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002826 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002827
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002828 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002829 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002830 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002831 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002832
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002833 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002834 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002835 !getDerived().AlwaysRebuild())
2836 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002837
2838 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002839 // nested-name-specifier, do so.
2840 if (SS.location_size() == NNS.getDataLength() &&
2841 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2842 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2843
2844 // Allocate new nested-name-specifier location information.
2845 return SS.getWithLocInContext(SemaRef.Context);
2846}
2847
2848template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002849DeclarationNameInfo
2850TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002851::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002852 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002853 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002854 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002855
2856 switch (Name.getNameKind()) {
2857 case DeclarationName::Identifier:
2858 case DeclarationName::ObjCZeroArgSelector:
2859 case DeclarationName::ObjCOneArgSelector:
2860 case DeclarationName::ObjCMultiArgSelector:
2861 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002862 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002863 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002864 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002865
Douglas Gregor81499bb2009-09-03 22:13:48 +00002866 case DeclarationName::CXXConstructorName:
2867 case DeclarationName::CXXDestructorName:
2868 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002869 TypeSourceInfo *NewTInfo;
2870 CanQualType NewCanTy;
2871 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002872 NewTInfo = getDerived().TransformType(OldTInfo);
2873 if (!NewTInfo)
2874 return DeclarationNameInfo();
2875 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002876 }
2877 else {
2878 NewTInfo = 0;
2879 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002880 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002881 if (NewT.isNull())
2882 return DeclarationNameInfo();
2883 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2884 }
Mike Stump1eb44332009-09-09 15:08:12 +00002885
Abramo Bagnara25777432010-08-11 22:01:17 +00002886 DeclarationName NewName
2887 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2888 NewCanTy);
2889 DeclarationNameInfo NewNameInfo(NameInfo);
2890 NewNameInfo.setName(NewName);
2891 NewNameInfo.setNamedTypeInfo(NewTInfo);
2892 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002893 }
Mike Stump1eb44332009-09-09 15:08:12 +00002894 }
2895
David Blaikieb219cfc2011-09-23 05:06:16 +00002896 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002897}
2898
2899template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002900TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002901TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2902 TemplateName Name,
2903 SourceLocation NameLoc,
2904 QualType ObjectType,
2905 NamedDecl *FirstQualifierInScope) {
2906 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2907 TemplateDecl *Template = QTN->getTemplateDecl();
2908 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002909
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002910 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002911 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002912 Template));
2913 if (!TransTemplate)
2914 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002915
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002916 if (!getDerived().AlwaysRebuild() &&
2917 SS.getScopeRep() == QTN->getQualifier() &&
2918 TransTemplate == Template)
2919 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002920
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002921 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2922 TransTemplate);
2923 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002924
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002925 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2926 if (SS.getScopeRep()) {
2927 // These apply to the scope specifier, not the template.
2928 ObjectType = QualType();
2929 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002930 }
2931
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002932 if (!getDerived().AlwaysRebuild() &&
2933 SS.getScopeRep() == DTN->getQualifier() &&
2934 ObjectType.isNull())
2935 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002936
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002937 if (DTN->isIdentifier()) {
2938 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002939 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002940 NameLoc,
2941 ObjectType,
2942 FirstQualifierInScope);
2943 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002944
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002945 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2946 ObjectType);
2947 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002948
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002949 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2950 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002951 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002952 Template));
2953 if (!TransTemplate)
2954 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002955
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002956 if (!getDerived().AlwaysRebuild() &&
2957 TransTemplate == Template)
2958 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002959
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002960 return TemplateName(TransTemplate);
2961 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002962
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002963 if (SubstTemplateTemplateParmPackStorage *SubstPack
2964 = Name.getAsSubstTemplateTemplateParmPack()) {
2965 TemplateTemplateParmDecl *TransParam
2966 = cast_or_null<TemplateTemplateParmDecl>(
2967 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2968 if (!TransParam)
2969 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002970
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002971 if (!getDerived().AlwaysRebuild() &&
2972 TransParam == SubstPack->getParameterPack())
2973 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002974
2975 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002976 SubstPack->getArgumentPack());
2977 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002978
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002979 // These should be getting filtered out before they reach the AST.
2980 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002981}
2982
2983template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002984void TreeTransform<Derived>::InventTemplateArgumentLoc(
2985 const TemplateArgument &Arg,
2986 TemplateArgumentLoc &Output) {
2987 SourceLocation Loc = getDerived().getBaseLocation();
2988 switch (Arg.getKind()) {
2989 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002990 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002991 break;
2992
2993 case TemplateArgument::Type:
2994 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002995 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002996
John McCall833ca992009-10-29 08:12:44 +00002997 break;
2998
Douglas Gregor788cd062009-11-11 01:00:40 +00002999 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003000 case TemplateArgument::TemplateExpansion: {
3001 NestedNameSpecifierLocBuilder Builder;
3002 TemplateName Template = Arg.getAsTemplate();
3003 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3004 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3005 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3006 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003007
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003008 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003009 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003010 Builder.getWithLocInContext(SemaRef.Context),
3011 Loc);
3012 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003013 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003014 Builder.getWithLocInContext(SemaRef.Context),
3015 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003016
Douglas Gregor788cd062009-11-11 01:00:40 +00003017 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003018 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003019
John McCall833ca992009-10-29 08:12:44 +00003020 case TemplateArgument::Expression:
3021 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3022 break;
3023
3024 case TemplateArgument::Declaration:
3025 case TemplateArgument::Integral:
3026 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003027 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003028 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003029 break;
3030 }
3031}
3032
3033template<typename Derived>
3034bool TreeTransform<Derived>::TransformTemplateArgument(
3035 const TemplateArgumentLoc &Input,
3036 TemplateArgumentLoc &Output) {
3037 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003038 switch (Arg.getKind()) {
3039 case TemplateArgument::Null:
3040 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003041 case TemplateArgument::Pack:
3042 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003043 case TemplateArgument::NullPtr:
3044 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003045
Douglas Gregor670444e2009-08-04 22:27:00 +00003046 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003047 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003048 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003049 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003050
3051 DI = getDerived().TransformType(DI);
3052 if (!DI) return true;
3053
3054 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3055 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003056 }
Mike Stump1eb44332009-09-09 15:08:12 +00003057
Douglas Gregor788cd062009-11-11 01:00:40 +00003058 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003059 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3060 if (QualifierLoc) {
3061 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3062 if (!QualifierLoc)
3063 return true;
3064 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003065
Douglas Gregor1d752d72011-03-02 18:46:51 +00003066 CXXScopeSpec SS;
3067 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003068 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003069 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3070 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003071 if (Template.isNull())
3072 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003073
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003074 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003075 Input.getTemplateNameLoc());
3076 return false;
3077 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003078
3079 case TemplateArgument::TemplateExpansion:
3080 llvm_unreachable("Caller should expand pack expansions");
3081
Douglas Gregor670444e2009-08-04 22:27:00 +00003082 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003083 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003084 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003085 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003086
John McCall833ca992009-10-29 08:12:44 +00003087 Expr *InputExpr = Input.getSourceExpression();
3088 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3089
Chris Lattner223de242011-04-25 20:37:58 +00003090 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003091 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003092 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003093 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003094 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003095 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003096 }
Mike Stump1eb44332009-09-09 15:08:12 +00003097
Douglas Gregor670444e2009-08-04 22:27:00 +00003098 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003099 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003100}
3101
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003102/// \brief Iterator adaptor that invents template argument location information
3103/// for each of the template arguments in its underlying iterator.
3104template<typename Derived, typename InputIterator>
3105class TemplateArgumentLocInventIterator {
3106 TreeTransform<Derived> &Self;
3107 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003108
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003109public:
3110 typedef TemplateArgumentLoc value_type;
3111 typedef TemplateArgumentLoc reference;
3112 typedef typename std::iterator_traits<InputIterator>::difference_type
3113 difference_type;
3114 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003115
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003116 class pointer {
3117 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003118
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003119 public:
3120 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003121
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003122 const TemplateArgumentLoc *operator->() const { return &Arg; }
3123 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003124
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003125 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003126
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003127 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3128 InputIterator Iter)
3129 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003130
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003131 TemplateArgumentLocInventIterator &operator++() {
3132 ++Iter;
3133 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003134 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003135
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003136 TemplateArgumentLocInventIterator operator++(int) {
3137 TemplateArgumentLocInventIterator Old(*this);
3138 ++(*this);
3139 return Old;
3140 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003141
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003142 reference operator*() const {
3143 TemplateArgumentLoc Result;
3144 Self.InventTemplateArgumentLoc(*Iter, Result);
3145 return Result;
3146 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003147
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003148 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003149
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003150 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3151 const TemplateArgumentLocInventIterator &Y) {
3152 return X.Iter == Y.Iter;
3153 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003154
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003155 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3156 const TemplateArgumentLocInventIterator &Y) {
3157 return X.Iter != Y.Iter;
3158 }
3159};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003160
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003161template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003162template<typename InputIterator>
3163bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3164 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003165 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003166 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003167 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003168 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003169
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003170 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3171 // Unpack argument packs, which we translate them into separate
3172 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003173 // FIXME: We could do much better if we could guarantee that the
3174 // TemplateArgumentLocInfo for the pack expansion would be usable for
3175 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003176 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003177 TemplateArgument::pack_iterator>
3178 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003179 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003180 In.getArgument().pack_begin()),
3181 PackLocIterator(*this,
3182 In.getArgument().pack_end()),
3183 Outputs))
3184 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003185
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003186 continue;
3187 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003188
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003189 if (In.getArgument().isPackExpansion()) {
3190 // We have a pack expansion, for which we will be substituting into
3191 // the pattern.
3192 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003193 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003194 TemplateArgumentLoc Pattern
Chad Rosier4a9d7952012-08-08 18:46:20 +00003195 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
Douglas Gregorcded4f62011-01-14 17:04:44 +00003196 getSema().Context);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003197
Chris Lattner686775d2011-07-20 06:58:45 +00003198 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003199 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3200 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003201
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003202 // Determine whether the set of unexpanded parameter packs can and should
3203 // be expanded.
3204 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003205 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003206 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003207 if (getDerived().TryExpandParameterPacks(Ellipsis,
3208 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003209 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003210 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003211 RetainExpansion,
3212 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003213 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003214
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003215 if (!Expand) {
3216 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003217 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003218 // expansion.
3219 TemplateArgumentLoc OutPattern;
3220 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3221 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3222 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003223
Douglas Gregorcded4f62011-01-14 17:04:44 +00003224 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3225 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003226 if (Out.getArgument().isNull())
3227 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003228
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003229 Outputs.addArgument(Out);
3230 continue;
3231 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003232
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003233 // The transform has determined that we should perform an elementwise
3234 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003235 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003236 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3237
3238 if (getDerived().TransformTemplateArgument(Pattern, Out))
3239 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003240
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003241 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003242 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3243 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003244 if (Out.getArgument().isNull())
3245 return true;
3246 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003247
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003248 Outputs.addArgument(Out);
3249 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003250
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003251 // If we're supposed to retain a pack expansion, do so by temporarily
3252 // forgetting the partially-substituted parameter pack.
3253 if (RetainExpansion) {
3254 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003255
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003256 if (getDerived().TransformTemplateArgument(Pattern, Out))
3257 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003258
Douglas Gregorcded4f62011-01-14 17:04:44 +00003259 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3260 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003261 if (Out.getArgument().isNull())
3262 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003263
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003264 Outputs.addArgument(Out);
3265 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003266
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003267 continue;
3268 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003269
3270 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003271 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003272 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003273
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003274 Outputs.addArgument(Out);
3275 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003276
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003277 return false;
3278
3279}
3280
Douglas Gregor577f75a2009-08-04 16:50:30 +00003281//===----------------------------------------------------------------------===//
3282// Type transformation
3283//===----------------------------------------------------------------------===//
3284
3285template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003286QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003287 if (getDerived().AlreadyTransformed(T))
3288 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003289
John McCalla2becad2009-10-21 00:40:46 +00003290 // Temporary workaround. All of these transformations should
3291 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003292 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3293 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003294
John McCall43fed0d2010-11-12 08:19:04 +00003295 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003296
John McCalla2becad2009-10-21 00:40:46 +00003297 if (!NewDI)
3298 return QualType();
3299
3300 return NewDI->getType();
3301}
3302
3303template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003304TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003305 // Refine the base location to the type's location.
3306 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3307 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003308 if (getDerived().AlreadyTransformed(DI->getType()))
3309 return DI;
3310
3311 TypeLocBuilder TLB;
3312
3313 TypeLoc TL = DI->getTypeLoc();
3314 TLB.reserve(TL.getFullDataSize());
3315
John McCall43fed0d2010-11-12 08:19:04 +00003316 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003317 if (Result.isNull())
3318 return 0;
3319
John McCalla93c9342009-12-07 02:54:59 +00003320 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003321}
3322
3323template<typename Derived>
3324QualType
John McCall43fed0d2010-11-12 08:19:04 +00003325TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003326 switch (T.getTypeLocClass()) {
3327#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003328#define TYPELOC(CLASS, PARENT) \
3329 case TypeLoc::CLASS: \
3330 return getDerived().Transform##CLASS##Type(TLB, \
3331 T.castAs<CLASS##TypeLoc>());
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.
Douglas Gregor92d13872013-01-17 23:59:28 +00003368 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003369 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003370 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3371 QualType Replacement = SubstTypeParam->getReplacementType();
3372 Qualifiers Qs = Replacement.getQualifiers();
3373 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003374 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003375 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3376 Qs);
3377 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003378 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003379 Replacement);
3380 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003381 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3382 // 'auto' types behave the same way as template parameters.
3383 QualType Deduced = AutoTy->getDeducedType();
3384 Qualifiers Qs = Deduced.getQualifiers();
3385 Qs.removeObjCLifetime();
3386 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3387 Qs);
3388 Result = SemaRef.Context.getAutoType(Deduced);
3389 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003390 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003391 // Otherwise, complain about the addition of a qualifier to an
3392 // already-qualified type.
3393 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003394 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003395 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003396
Douglas Gregore559ca12011-06-17 22:11:49 +00003397 Quals.removeObjCLifetime();
3398 }
3399 }
3400 }
John McCall28654742010-06-05 06:41:15 +00003401 if (!Quals.empty()) {
3402 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3403 TLB.push<QualifiedTypeLoc>(Result);
3404 // No location information to preserve.
3405 }
John McCalla2becad2009-10-21 00:40:46 +00003406
3407 return Result;
3408}
3409
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003410template<typename Derived>
3411TypeLoc
3412TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3413 QualType ObjectType,
3414 NamedDecl *UnqualLookup,
3415 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003416 QualType T = TL.getType();
3417 if (getDerived().AlreadyTransformed(T))
3418 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003419
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003420 TypeLocBuilder TLB;
3421 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003422
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003423 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003424 TemplateSpecializationTypeLoc SpecTL =
3425 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003426
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003427 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003428 getDerived().TransformTemplateName(SS,
3429 SpecTL.getTypePtr()->getTemplateName(),
3430 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003431 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003432 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003433 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003434
3435 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003436 Template);
3437 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003438 DependentTemplateSpecializationTypeLoc SpecTL =
3439 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003440
Douglas Gregora88f09f2011-02-28 17:23:35 +00003441 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003442 = getDerived().RebuildTemplateName(SS,
3443 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003444 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003445 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003446 if (Template.isNull())
3447 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003448
3449 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003450 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003451 Template,
3452 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003453 } else {
3454 // Nothing special needs to be done for these.
3455 Result = getDerived().TransformType(TLB, TL);
3456 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003457
3458 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003459 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003460
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003461 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3462}
3463
Douglas Gregorb71d8212011-03-02 18:32:08 +00003464template<typename Derived>
3465TypeSourceInfo *
3466TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3467 QualType ObjectType,
3468 NamedDecl *UnqualLookup,
3469 CXXScopeSpec &SS) {
3470 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003471
Douglas Gregorb71d8212011-03-02 18:32:08 +00003472 QualType T = TSInfo->getType();
3473 if (getDerived().AlreadyTransformed(T))
3474 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003475
Douglas Gregorb71d8212011-03-02 18:32:08 +00003476 TypeLocBuilder TLB;
3477 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003478
Douglas Gregorb71d8212011-03-02 18:32:08 +00003479 TypeLoc TL = TSInfo->getTypeLoc();
3480 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003481 TemplateSpecializationTypeLoc SpecTL =
3482 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003483
Douglas Gregorb71d8212011-03-02 18:32:08 +00003484 TemplateName Template
3485 = getDerived().TransformTemplateName(SS,
3486 SpecTL.getTypePtr()->getTemplateName(),
3487 SpecTL.getTemplateNameLoc(),
3488 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003489 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003490 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003491
3492 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003493 Template);
3494 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003495 DependentTemplateSpecializationTypeLoc SpecTL =
3496 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003497
Douglas Gregorb71d8212011-03-02 18:32:08 +00003498 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003499 = getDerived().RebuildTemplateName(SS,
3500 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003501 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003502 ObjectType, UnqualLookup);
3503 if (Template.isNull())
3504 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003505
3506 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003507 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003508 Template,
3509 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003510 } else {
3511 // Nothing special needs to be done for these.
3512 Result = getDerived().TransformType(TLB, TL);
3513 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003514
3515 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003516 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003517
Douglas Gregorb71d8212011-03-02 18:32:08 +00003518 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3519}
3520
John McCalla2becad2009-10-21 00:40:46 +00003521template <class TyLoc> static inline
3522QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3523 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3524 NewT.setNameLoc(T.getNameLoc());
3525 return T.getType();
3526}
3527
John McCalla2becad2009-10-21 00:40:46 +00003528template<typename Derived>
3529QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003530 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003531 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3532 NewT.setBuiltinLoc(T.getBuiltinLoc());
3533 if (T.needsExtraLocalData())
3534 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3535 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003536}
Mike Stump1eb44332009-09-09 15:08:12 +00003537
Douglas Gregor577f75a2009-08-04 16:50:30 +00003538template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003539QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003540 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003541 // FIXME: recurse?
3542 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003543}
Mike Stump1eb44332009-09-09 15:08:12 +00003544
Douglas Gregor577f75a2009-08-04 16:50:30 +00003545template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003546QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003547 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003548 QualType PointeeType
3549 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003550 if (PointeeType.isNull())
3551 return QualType();
3552
3553 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003554 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003555 // A dependent pointer type 'T *' has is being transformed such
3556 // that an Objective-C class type is being replaced for 'T'. The
3557 // resulting pointer type is an ObjCObjectPointerType, not a
3558 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003559 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003560
John McCallc12c5bb2010-05-15 11:32:37 +00003561 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3562 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003563 return Result;
3564 }
John McCall43fed0d2010-11-12 08:19:04 +00003565
Douglas Gregor92e986e2010-04-22 16:44:27 +00003566 if (getDerived().AlwaysRebuild() ||
3567 PointeeType != TL.getPointeeLoc().getType()) {
3568 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3569 if (Result.isNull())
3570 return QualType();
3571 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003572
John McCallf85e1932011-06-15 23:02:42 +00003573 // Objective-C ARC can add lifetime qualifiers to the type that we're
3574 // pointing to.
3575 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003576
Douglas Gregor92e986e2010-04-22 16:44:27 +00003577 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3578 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003579 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003580}
Mike Stump1eb44332009-09-09 15:08:12 +00003581
3582template<typename Derived>
3583QualType
John McCalla2becad2009-10-21 00:40:46 +00003584TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003585 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003586 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003587 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3588 if (PointeeType.isNull())
3589 return QualType();
3590
3591 QualType Result = TL.getType();
3592 if (getDerived().AlwaysRebuild() ||
3593 PointeeType != TL.getPointeeLoc().getType()) {
3594 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003595 TL.getSigilLoc());
3596 if (Result.isNull())
3597 return QualType();
3598 }
3599
Douglas Gregor39968ad2010-04-22 16:50:51 +00003600 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003601 NewT.setSigilLoc(TL.getSigilLoc());
3602 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003603}
3604
John McCall85737a72009-10-30 00:06:24 +00003605/// Transforms a reference type. Note that somewhat paradoxically we
3606/// don't care whether the type itself is an l-value type or an r-value
3607/// type; we only care if the type was *written* as an l-value type
3608/// or an r-value type.
3609template<typename Derived>
3610QualType
3611TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003612 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003613 const ReferenceType *T = TL.getTypePtr();
3614
3615 // Note that this works with the pointee-as-written.
3616 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3617 if (PointeeType.isNull())
3618 return QualType();
3619
3620 QualType Result = TL.getType();
3621 if (getDerived().AlwaysRebuild() ||
3622 PointeeType != T->getPointeeTypeAsWritten()) {
3623 Result = getDerived().RebuildReferenceType(PointeeType,
3624 T->isSpelledAsLValue(),
3625 TL.getSigilLoc());
3626 if (Result.isNull())
3627 return QualType();
3628 }
3629
John McCallf85e1932011-06-15 23:02:42 +00003630 // Objective-C ARC can add lifetime qualifiers to the type that we're
3631 // referring to.
3632 TLB.TypeWasModifiedSafely(
3633 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3634
John McCall85737a72009-10-30 00:06:24 +00003635 // r-value references can be rebuilt as l-value references.
3636 ReferenceTypeLoc NewTL;
3637 if (isa<LValueReferenceType>(Result))
3638 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3639 else
3640 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3641 NewTL.setSigilLoc(TL.getSigilLoc());
3642
3643 return Result;
3644}
3645
Mike Stump1eb44332009-09-09 15:08:12 +00003646template<typename Derived>
3647QualType
John McCalla2becad2009-10-21 00:40:46 +00003648TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003649 LValueReferenceTypeLoc TL) {
3650 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003651}
3652
Mike Stump1eb44332009-09-09 15:08:12 +00003653template<typename Derived>
3654QualType
John McCalla2becad2009-10-21 00:40:46 +00003655TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003656 RValueReferenceTypeLoc TL) {
3657 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003658}
Mike Stump1eb44332009-09-09 15:08:12 +00003659
Douglas Gregor577f75a2009-08-04 16:50:30 +00003660template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003661QualType
John McCalla2becad2009-10-21 00:40:46 +00003662TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003663 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003664 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003665 if (PointeeType.isNull())
3666 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003667
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003668 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3669 TypeSourceInfo* NewClsTInfo = 0;
3670 if (OldClsTInfo) {
3671 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3672 if (!NewClsTInfo)
3673 return QualType();
3674 }
3675
3676 const MemberPointerType *T = TL.getTypePtr();
3677 QualType OldClsType = QualType(T->getClass(), 0);
3678 QualType NewClsType;
3679 if (NewClsTInfo)
3680 NewClsType = NewClsTInfo->getType();
3681 else {
3682 NewClsType = getDerived().TransformType(OldClsType);
3683 if (NewClsType.isNull())
3684 return QualType();
3685 }
Mike Stump1eb44332009-09-09 15:08:12 +00003686
John McCalla2becad2009-10-21 00:40:46 +00003687 QualType Result = TL.getType();
3688 if (getDerived().AlwaysRebuild() ||
3689 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003690 NewClsType != OldClsType) {
3691 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003692 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003693 if (Result.isNull())
3694 return QualType();
3695 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003696
John McCalla2becad2009-10-21 00:40:46 +00003697 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3698 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003699 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003700
3701 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003702}
3703
Mike Stump1eb44332009-09-09 15:08:12 +00003704template<typename Derived>
3705QualType
John McCalla2becad2009-10-21 00:40:46 +00003706TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003707 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003708 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003709 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003710 if (ElementType.isNull())
3711 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003712
John McCalla2becad2009-10-21 00:40:46 +00003713 QualType Result = TL.getType();
3714 if (getDerived().AlwaysRebuild() ||
3715 ElementType != T->getElementType()) {
3716 Result = getDerived().RebuildConstantArrayType(ElementType,
3717 T->getSizeModifier(),
3718 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003719 T->getIndexTypeCVRQualifiers(),
3720 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003721 if (Result.isNull())
3722 return QualType();
3723 }
Eli Friedman457a3772012-01-25 22:19:07 +00003724
3725 // We might have either a ConstantArrayType or a VariableArrayType now:
3726 // a ConstantArrayType is allowed to have an element type which is a
3727 // VariableArrayType if the type is dependent. Fortunately, all array
3728 // types have the same location layout.
3729 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003730 NewTL.setLBracketLoc(TL.getLBracketLoc());
3731 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003732
John McCalla2becad2009-10-21 00:40:46 +00003733 Expr *Size = TL.getSizeExpr();
3734 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003735 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3736 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003737 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003738 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003739 }
3740 NewTL.setSizeExpr(Size);
3741
3742 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003743}
Mike Stump1eb44332009-09-09 15:08:12 +00003744
Douglas Gregor577f75a2009-08-04 16:50:30 +00003745template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003746QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003747 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003748 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003749 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003750 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003751 if (ElementType.isNull())
3752 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003753
John McCalla2becad2009-10-21 00:40:46 +00003754 QualType Result = TL.getType();
3755 if (getDerived().AlwaysRebuild() ||
3756 ElementType != T->getElementType()) {
3757 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003758 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003759 T->getIndexTypeCVRQualifiers(),
3760 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003761 if (Result.isNull())
3762 return QualType();
3763 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003764
John McCalla2becad2009-10-21 00:40:46 +00003765 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3766 NewTL.setLBracketLoc(TL.getLBracketLoc());
3767 NewTL.setRBracketLoc(TL.getRBracketLoc());
3768 NewTL.setSizeExpr(0);
3769
3770 return Result;
3771}
3772
3773template<typename Derived>
3774QualType
3775TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003776 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003777 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003778 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3779 if (ElementType.isNull())
3780 return QualType();
3781
John McCall60d7b3a2010-08-24 06:29:42 +00003782 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003783 = getDerived().TransformExpr(T->getSizeExpr());
3784 if (SizeResult.isInvalid())
3785 return QualType();
3786
John McCall9ae2f072010-08-23 23:25:46 +00003787 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003788
3789 QualType Result = TL.getType();
3790 if (getDerived().AlwaysRebuild() ||
3791 ElementType != T->getElementType() ||
3792 Size != T->getSizeExpr()) {
3793 Result = getDerived().RebuildVariableArrayType(ElementType,
3794 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003795 Size,
John McCalla2becad2009-10-21 00:40:46 +00003796 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003797 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003798 if (Result.isNull())
3799 return QualType();
3800 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003801
John McCalla2becad2009-10-21 00:40:46 +00003802 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3803 NewTL.setLBracketLoc(TL.getLBracketLoc());
3804 NewTL.setRBracketLoc(TL.getRBracketLoc());
3805 NewTL.setSizeExpr(Size);
3806
3807 return Result;
3808}
3809
3810template<typename Derived>
3811QualType
3812TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003813 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003814 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003815 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3816 if (ElementType.isNull())
3817 return QualType();
3818
Richard Smithf6702a32011-12-20 02:08:33 +00003819 // Array bounds are constant expressions.
3820 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3821 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003822
John McCall3b657512011-01-19 10:06:00 +00003823 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3824 Expr *origSize = TL.getSizeExpr();
3825 if (!origSize) origSize = T->getSizeExpr();
3826
3827 ExprResult sizeResult
3828 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003829 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003830 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003831 return QualType();
3832
John McCall3b657512011-01-19 10:06:00 +00003833 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003834
3835 QualType Result = TL.getType();
3836 if (getDerived().AlwaysRebuild() ||
3837 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003838 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003839 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3840 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003841 size,
John McCalla2becad2009-10-21 00:40:46 +00003842 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003843 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003844 if (Result.isNull())
3845 return QualType();
3846 }
John McCalla2becad2009-10-21 00:40:46 +00003847
3848 // We might have any sort of array type now, but fortunately they
3849 // all have the same location layout.
3850 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3851 NewTL.setLBracketLoc(TL.getLBracketLoc());
3852 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003853 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003854
3855 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003856}
Mike Stump1eb44332009-09-09 15:08:12 +00003857
3858template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003859QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003860 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003861 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003862 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003863
3864 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003865 QualType ElementType = getDerived().TransformType(T->getElementType());
3866 if (ElementType.isNull())
3867 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003868
Richard Smithf6702a32011-12-20 02:08:33 +00003869 // Vector sizes are constant expressions.
3870 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3871 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003872
John McCall60d7b3a2010-08-24 06:29:42 +00003873 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003874 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003875 if (Size.isInvalid())
3876 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003877
John McCalla2becad2009-10-21 00:40:46 +00003878 QualType Result = TL.getType();
3879 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003880 ElementType != T->getElementType() ||
3881 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003882 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003883 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003884 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003885 if (Result.isNull())
3886 return QualType();
3887 }
John McCalla2becad2009-10-21 00:40:46 +00003888
3889 // Result might be dependent or not.
3890 if (isa<DependentSizedExtVectorType>(Result)) {
3891 DependentSizedExtVectorTypeLoc NewTL
3892 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3893 NewTL.setNameLoc(TL.getNameLoc());
3894 } else {
3895 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3896 NewTL.setNameLoc(TL.getNameLoc());
3897 }
3898
3899 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003900}
Mike Stump1eb44332009-09-09 15:08:12 +00003901
3902template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003903QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003904 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003905 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003906 QualType ElementType = getDerived().TransformType(T->getElementType());
3907 if (ElementType.isNull())
3908 return QualType();
3909
John McCalla2becad2009-10-21 00:40:46 +00003910 QualType Result = TL.getType();
3911 if (getDerived().AlwaysRebuild() ||
3912 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003913 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003914 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003915 if (Result.isNull())
3916 return QualType();
3917 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003918
John McCalla2becad2009-10-21 00:40:46 +00003919 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3920 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003921
John McCalla2becad2009-10-21 00:40:46 +00003922 return Result;
3923}
3924
3925template<typename Derived>
3926QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003927 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003928 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003929 QualType ElementType = getDerived().TransformType(T->getElementType());
3930 if (ElementType.isNull())
3931 return QualType();
3932
3933 QualType Result = TL.getType();
3934 if (getDerived().AlwaysRebuild() ||
3935 ElementType != T->getElementType()) {
3936 Result = getDerived().RebuildExtVectorType(ElementType,
3937 T->getNumElements(),
3938 /*FIXME*/ SourceLocation());
3939 if (Result.isNull())
3940 return QualType();
3941 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003942
John McCalla2becad2009-10-21 00:40:46 +00003943 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3944 NewTL.setNameLoc(TL.getNameLoc());
3945
3946 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003947}
Mike Stump1eb44332009-09-09 15:08:12 +00003948
David Blaikiedc84cd52013-02-20 22:23:23 +00003949template <typename Derived>
3950ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
3951 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
3952 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003953 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003954 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003955
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003956 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003957 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003958 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003959 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00003960 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003961
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003962 TypeLocBuilder TLB;
3963 TypeLoc NewTL = OldDI->getTypeLoc();
3964 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003965
3966 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003967 OldExpansionTL.getPatternLoc());
3968 if (Result.isNull())
3969 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003970
3971 Result = RebuildPackExpansionType(Result,
3972 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003973 OldExpansionTL.getEllipsisLoc(),
3974 NumExpansions);
3975 if (Result.isNull())
3976 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003977
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003978 PackExpansionTypeLoc NewExpansionTL
3979 = TLB.push<PackExpansionTypeLoc>(Result);
3980 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3981 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3982 } else
3983 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003984 if (!NewDI)
3985 return 0;
3986
John McCallfb44de92011-05-01 22:35:37 +00003987 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003988 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003989
3990 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3991 OldParm->getDeclContext(),
3992 OldParm->getInnerLocStart(),
3993 OldParm->getLocation(),
3994 OldParm->getIdentifier(),
3995 NewDI->getType(),
3996 NewDI,
3997 OldParm->getStorageClass(),
3998 OldParm->getStorageClassAsWritten(),
3999 /* DefArg */ NULL);
4000 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4001 OldParm->getFunctionScopeIndex() + indexAdjustment);
4002 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004003}
4004
4005template<typename Derived>
4006bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004007 TransformFunctionTypeParams(SourceLocation Loc,
4008 ParmVarDecl **Params, unsigned NumParams,
4009 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004010 SmallVectorImpl<QualType> &OutParamTypes,
4011 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004012 int indexAdjustment = 0;
4013
Douglas Gregora009b592011-01-07 00:20:55 +00004014 for (unsigned i = 0; i != NumParams; ++i) {
4015 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004016 assert(OldParm->getFunctionScopeIndex() == i);
4017
David Blaikiedc84cd52013-02-20 22:23:23 +00004018 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004019 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004020 if (OldParm->isParameterPack()) {
4021 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004022 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004023
Douglas Gregor603cfb42011-01-05 23:12:31 +00004024 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004025 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004026 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004027 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4028 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004029 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4030
Douglas Gregor603cfb42011-01-05 23:12:31 +00004031 // Determine whether we should expand the parameter packs.
4032 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004033 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004034 Optional<unsigned> OrigNumExpansions =
4035 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004036 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004037 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4038 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004039 Unexpanded,
4040 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004041 RetainExpansion,
4042 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004043 return true;
4044 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004045
Douglas Gregor603cfb42011-01-05 23:12:31 +00004046 if (ShouldExpand) {
4047 // Expand the function parameter pack into multiple, separate
4048 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004049 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004050 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004051 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004052 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004053 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004054 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004055 OrigNumExpansions,
4056 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004057 if (!NewParm)
4058 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004059
Douglas Gregora009b592011-01-07 00:20:55 +00004060 OutParamTypes.push_back(NewParm->getType());
4061 if (PVars)
4062 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004063 }
Douglas Gregord3731192011-01-10 07:32:04 +00004064
4065 // If we're supposed to retain a pack expansion, do so by temporarily
4066 // forgetting the partially-substituted parameter pack.
4067 if (RetainExpansion) {
4068 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004069 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004070 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004071 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004072 OrigNumExpansions,
4073 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004074 if (!NewParm)
4075 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004076
Douglas Gregord3731192011-01-10 07:32:04 +00004077 OutParamTypes.push_back(NewParm->getType());
4078 if (PVars)
4079 PVars->push_back(NewParm);
4080 }
4081
John McCallfb44de92011-05-01 22:35:37 +00004082 // The next parameter should have the same adjustment as the
4083 // last thing we pushed, but we post-incremented indexAdjustment
4084 // on every push. Also, if we push nothing, the adjustment should
4085 // go down by one.
4086 indexAdjustment--;
4087
Douglas Gregor603cfb42011-01-05 23:12:31 +00004088 // We're done with the pack expansion.
4089 continue;
4090 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004091
4092 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004093 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004094 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4095 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004096 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004097 NumExpansions,
4098 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004099 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004100 NewParm = getDerived().TransformFunctionTypeParam(
4101 OldParm, indexAdjustment, Optional<unsigned>(),
4102 /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004103 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004104
John McCall21ef0fa2010-03-11 09:03:00 +00004105 if (!NewParm)
4106 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004107
Douglas Gregora009b592011-01-07 00:20:55 +00004108 OutParamTypes.push_back(NewParm->getType());
4109 if (PVars)
4110 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004111 continue;
4112 }
John McCall21ef0fa2010-03-11 09:03:00 +00004113
4114 // Deal with the possibility that we don't have a parameter
4115 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004116 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004117 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004118 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004119 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004120 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004121 = dyn_cast<PackExpansionType>(OldType)) {
4122 // We have a function parameter pack that may need to be expanded.
4123 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004124 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004125 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004126
Douglas Gregor603cfb42011-01-05 23:12:31 +00004127 // Determine whether we should expand the parameter packs.
4128 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004129 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004130 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004131 Unexpanded,
4132 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004133 RetainExpansion,
4134 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004135 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004136 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004137
Douglas Gregor603cfb42011-01-05 23:12:31 +00004138 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004139 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004140 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004141 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004142 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4143 QualType NewType = getDerived().TransformType(Pattern);
4144 if (NewType.isNull())
4145 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004146
Douglas Gregora009b592011-01-07 00:20:55 +00004147 OutParamTypes.push_back(NewType);
4148 if (PVars)
4149 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004150 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004151
Douglas Gregor603cfb42011-01-05 23:12:31 +00004152 // We're done with the pack expansion.
4153 continue;
4154 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004155
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004156 // If we're supposed to retain a pack expansion, do so by temporarily
4157 // forgetting the partially-substituted parameter pack.
4158 if (RetainExpansion) {
4159 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4160 QualType NewType = getDerived().TransformType(Pattern);
4161 if (NewType.isNull())
4162 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004163
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004164 OutParamTypes.push_back(NewType);
4165 if (PVars)
4166 PVars->push_back(0);
4167 }
Douglas Gregord3731192011-01-10 07:32:04 +00004168
Chad Rosier4a9d7952012-08-08 18:46:20 +00004169 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004170 // expansion.
4171 OldType = Expansion->getPattern();
4172 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004173 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4174 NewType = getDerived().TransformType(OldType);
4175 } else {
4176 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004177 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004178
Douglas Gregor603cfb42011-01-05 23:12:31 +00004179 if (NewType.isNull())
4180 return true;
4181
4182 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004183 NewType = getSema().Context.getPackExpansionType(NewType,
4184 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004185
Douglas Gregora009b592011-01-07 00:20:55 +00004186 OutParamTypes.push_back(NewType);
4187 if (PVars)
4188 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004189 }
4190
John McCallfb44de92011-05-01 22:35:37 +00004191#ifndef NDEBUG
4192 if (PVars) {
4193 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4194 if (ParmVarDecl *parm = (*PVars)[i])
4195 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004196 }
John McCallfb44de92011-05-01 22:35:37 +00004197#endif
4198
4199 return false;
4200}
John McCall21ef0fa2010-03-11 09:03:00 +00004201
4202template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004203QualType
John McCalla2becad2009-10-21 00:40:46 +00004204TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004205 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004206 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4207}
4208
4209template<typename Derived>
4210QualType
4211TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4212 FunctionProtoTypeLoc TL,
4213 CXXRecordDecl *ThisContext,
4214 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004215 // Transform the parameters and return type.
4216 //
Richard Smithe6975e92012-04-17 00:58:00 +00004217 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004218 // When the function has a trailing return type, we instantiate the
4219 // parameters before the return type, since the return type can then refer
4220 // to the parameters themselves (via decltype, sizeof, etc.).
4221 //
Chris Lattner686775d2011-07-20 06:58:45 +00004222 SmallVector<QualType, 4> ParamTypes;
4223 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004224 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004225
Douglas Gregordab60ad2010-10-01 18:44:50 +00004226 QualType ResultType;
4227
Richard Smith9fbf3272012-08-14 22:51:13 +00004228 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004229 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004230 TL.getParmArray(),
4231 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004232 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004233 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004234 return QualType();
4235
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004236 {
4237 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004238 // If a declaration declares a member function or member function
4239 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004240 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004241 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004242 // declarator.
4243 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004244
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004245 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4246 if (ResultType.isNull())
4247 return QualType();
4248 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004249 }
4250 else {
4251 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4252 if (ResultType.isNull())
4253 return QualType();
4254
Chad Rosier4a9d7952012-08-08 18:46:20 +00004255 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004256 TL.getParmArray(),
4257 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004258 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004259 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004260 return QualType();
4261 }
4262
Richard Smithe6975e92012-04-17 00:58:00 +00004263 // FIXME: Need to transform the exception-specification too.
4264
John McCalla2becad2009-10-21 00:40:46 +00004265 QualType Result = TL.getType();
4266 if (getDerived().AlwaysRebuild() ||
4267 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004268 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004269 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4270 Result = getDerived().RebuildFunctionProtoType(ResultType,
4271 ParamTypes.data(),
4272 ParamTypes.size(),
4273 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004274 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004275 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004276 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004277 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004278 if (Result.isNull())
4279 return QualType();
4280 }
Mike Stump1eb44332009-09-09 15:08:12 +00004281
John McCalla2becad2009-10-21 00:40:46 +00004282 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004283 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004284 NewTL.setLParenLoc(TL.getLParenLoc());
4285 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004286 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004287 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4288 NewTL.setArg(i, ParamDecls[i]);
4289
4290 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004291}
Mike Stump1eb44332009-09-09 15:08:12 +00004292
Douglas Gregor577f75a2009-08-04 16:50:30 +00004293template<typename Derived>
4294QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004295 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004296 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004297 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004298 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4299 if (ResultType.isNull())
4300 return QualType();
4301
4302 QualType Result = TL.getType();
4303 if (getDerived().AlwaysRebuild() ||
4304 ResultType != T->getResultType())
4305 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4306
4307 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004308 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004309 NewTL.setLParenLoc(TL.getLParenLoc());
4310 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004311 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004312
4313 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004314}
Mike Stump1eb44332009-09-09 15:08:12 +00004315
John McCalled976492009-12-04 22:46:56 +00004316template<typename Derived> QualType
4317TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004318 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004319 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004320 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004321 if (!D)
4322 return QualType();
4323
4324 QualType Result = TL.getType();
4325 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4326 Result = getDerived().RebuildUnresolvedUsingType(D);
4327 if (Result.isNull())
4328 return QualType();
4329 }
4330
4331 // We might get an arbitrary type spec type back. We should at
4332 // least always get a type spec type, though.
4333 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4334 NewTL.setNameLoc(TL.getNameLoc());
4335
4336 return Result;
4337}
4338
Douglas Gregor577f75a2009-08-04 16:50:30 +00004339template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004340QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004341 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004342 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004343 TypedefNameDecl *Typedef
4344 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4345 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004346 if (!Typedef)
4347 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004348
John McCalla2becad2009-10-21 00:40:46 +00004349 QualType Result = TL.getType();
4350 if (getDerived().AlwaysRebuild() ||
4351 Typedef != T->getDecl()) {
4352 Result = getDerived().RebuildTypedefType(Typedef);
4353 if (Result.isNull())
4354 return QualType();
4355 }
Mike Stump1eb44332009-09-09 15:08:12 +00004356
John McCalla2becad2009-10-21 00:40:46 +00004357 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4358 NewTL.setNameLoc(TL.getNameLoc());
4359
4360 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004361}
Mike Stump1eb44332009-09-09 15:08:12 +00004362
Douglas Gregor577f75a2009-08-04 16:50:30 +00004363template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004364QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004365 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004366 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004367 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4368 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004369
John McCall60d7b3a2010-08-24 06:29:42 +00004370 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004371 if (E.isInvalid())
4372 return QualType();
4373
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004374 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4375 if (E.isInvalid())
4376 return QualType();
4377
John McCalla2becad2009-10-21 00:40:46 +00004378 QualType Result = TL.getType();
4379 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004380 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004381 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004382 if (Result.isNull())
4383 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004384 }
John McCalla2becad2009-10-21 00:40:46 +00004385 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004386
John McCalla2becad2009-10-21 00:40:46 +00004387 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004388 NewTL.setTypeofLoc(TL.getTypeofLoc());
4389 NewTL.setLParenLoc(TL.getLParenLoc());
4390 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004391
4392 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004393}
Mike Stump1eb44332009-09-09 15:08:12 +00004394
4395template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004396QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004397 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004398 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4399 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4400 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004401 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004402
John McCalla2becad2009-10-21 00:40:46 +00004403 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004404 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4405 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004406 if (Result.isNull())
4407 return QualType();
4408 }
Mike Stump1eb44332009-09-09 15:08:12 +00004409
John McCalla2becad2009-10-21 00:40:46 +00004410 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004411 NewTL.setTypeofLoc(TL.getTypeofLoc());
4412 NewTL.setLParenLoc(TL.getLParenLoc());
4413 NewTL.setRParenLoc(TL.getRParenLoc());
4414 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004415
4416 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004417}
Mike Stump1eb44332009-09-09 15:08:12 +00004418
4419template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004420QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004421 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004422 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004423
Douglas Gregor670444e2009-08-04 22:27:00 +00004424 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004425 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4426 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004427
John McCall60d7b3a2010-08-24 06:29:42 +00004428 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004429 if (E.isInvalid())
4430 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004431
Richard Smith76f3f692012-02-22 02:04:18 +00004432 E = getSema().ActOnDecltypeExpression(E.take());
4433 if (E.isInvalid())
4434 return QualType();
4435
John McCalla2becad2009-10-21 00:40:46 +00004436 QualType Result = TL.getType();
4437 if (getDerived().AlwaysRebuild() ||
4438 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004439 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004440 if (Result.isNull())
4441 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004442 }
John McCalla2becad2009-10-21 00:40:46 +00004443 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004444
John McCalla2becad2009-10-21 00:40:46 +00004445 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4446 NewTL.setNameLoc(TL.getNameLoc());
4447
4448 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004449}
4450
4451template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004452QualType TreeTransform<Derived>::TransformUnaryTransformType(
4453 TypeLocBuilder &TLB,
4454 UnaryTransformTypeLoc TL) {
4455 QualType Result = TL.getType();
4456 if (Result->isDependentType()) {
4457 const UnaryTransformType *T = TL.getTypePtr();
4458 QualType NewBase =
4459 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4460 Result = getDerived().RebuildUnaryTransformType(NewBase,
4461 T->getUTTKind(),
4462 TL.getKWLoc());
4463 if (Result.isNull())
4464 return QualType();
4465 }
4466
4467 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4468 NewTL.setKWLoc(TL.getKWLoc());
4469 NewTL.setParensRange(TL.getParensRange());
4470 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4471 return Result;
4472}
4473
4474template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004475QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4476 AutoTypeLoc TL) {
4477 const AutoType *T = TL.getTypePtr();
4478 QualType OldDeduced = T->getDeducedType();
4479 QualType NewDeduced;
4480 if (!OldDeduced.isNull()) {
4481 NewDeduced = getDerived().TransformType(OldDeduced);
4482 if (NewDeduced.isNull())
4483 return QualType();
4484 }
4485
4486 QualType Result = TL.getType();
4487 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4488 Result = getDerived().RebuildAutoType(NewDeduced);
4489 if (Result.isNull())
4490 return QualType();
4491 }
4492
4493 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4494 NewTL.setNameLoc(TL.getNameLoc());
4495
4496 return Result;
4497}
4498
4499template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004500QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004501 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004502 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004503 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004504 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4505 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004506 if (!Record)
4507 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004508
John McCalla2becad2009-10-21 00:40:46 +00004509 QualType Result = TL.getType();
4510 if (getDerived().AlwaysRebuild() ||
4511 Record != T->getDecl()) {
4512 Result = getDerived().RebuildRecordType(Record);
4513 if (Result.isNull())
4514 return QualType();
4515 }
Mike Stump1eb44332009-09-09 15:08:12 +00004516
John McCalla2becad2009-10-21 00:40:46 +00004517 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4518 NewTL.setNameLoc(TL.getNameLoc());
4519
4520 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004521}
Mike Stump1eb44332009-09-09 15:08:12 +00004522
4523template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004524QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004525 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004526 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004527 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004528 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4529 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004530 if (!Enum)
4531 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004532
John McCalla2becad2009-10-21 00:40:46 +00004533 QualType Result = TL.getType();
4534 if (getDerived().AlwaysRebuild() ||
4535 Enum != T->getDecl()) {
4536 Result = getDerived().RebuildEnumType(Enum);
4537 if (Result.isNull())
4538 return QualType();
4539 }
Mike Stump1eb44332009-09-09 15:08:12 +00004540
John McCalla2becad2009-10-21 00:40:46 +00004541 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4542 NewTL.setNameLoc(TL.getNameLoc());
4543
4544 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004545}
John McCall7da24312009-09-05 00:15:47 +00004546
John McCall3cb0ebd2010-03-10 03:28:59 +00004547template<typename Derived>
4548QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4549 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004550 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004551 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4552 TL.getTypePtr()->getDecl());
4553 if (!D) return QualType();
4554
4555 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4556 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4557 return T;
4558}
4559
Douglas Gregor577f75a2009-08-04 16:50:30 +00004560template<typename Derived>
4561QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004562 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004563 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004564 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004565}
4566
Mike Stump1eb44332009-09-09 15:08:12 +00004567template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004568QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004569 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004570 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004571 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004572
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004573 // Substitute into the replacement type, which itself might involve something
4574 // that needs to be transformed. This only tends to occur with default
4575 // template arguments of template template parameters.
4576 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4577 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4578 if (Replacement.isNull())
4579 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004580
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004581 // Always canonicalize the replacement type.
4582 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4583 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004584 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004585 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004586
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004587 // Propagate type-source information.
4588 SubstTemplateTypeParmTypeLoc NewTL
4589 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4590 NewTL.setNameLoc(TL.getNameLoc());
4591 return Result;
4592
John McCall49a832b2009-10-18 09:09:24 +00004593}
4594
4595template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004596QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4597 TypeLocBuilder &TLB,
4598 SubstTemplateTypeParmPackTypeLoc TL) {
4599 return TransformTypeSpecType(TLB, TL);
4600}
4601
4602template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004603QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004604 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004605 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004606 const TemplateSpecializationType *T = TL.getTypePtr();
4607
Douglas Gregor1d752d72011-03-02 18:46:51 +00004608 // The nested-name-specifier never matters in a TemplateSpecializationType,
4609 // because we can't have a dependent nested-name-specifier anyway.
4610 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004611 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004612 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4613 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004614 if (Template.isNull())
4615 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004616
John McCall43fed0d2010-11-12 08:19:04 +00004617 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4618}
4619
Eli Friedmanb001de72011-10-06 23:00:33 +00004620template<typename Derived>
4621QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4622 AtomicTypeLoc TL) {
4623 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4624 if (ValueType.isNull())
4625 return QualType();
4626
4627 QualType Result = TL.getType();
4628 if (getDerived().AlwaysRebuild() ||
4629 ValueType != TL.getValueLoc().getType()) {
4630 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4631 if (Result.isNull())
4632 return QualType();
4633 }
4634
4635 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4636 NewTL.setKWLoc(TL.getKWLoc());
4637 NewTL.setLParenLoc(TL.getLParenLoc());
4638 NewTL.setRParenLoc(TL.getRParenLoc());
4639
4640 return Result;
4641}
4642
Chad Rosier4a9d7952012-08-08 18:46:20 +00004643 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004644 /// container that provides a \c getArgLoc() member function.
4645 ///
4646 /// This iterator is intended to be used with the iterator form of
4647 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4648 template<typename ArgLocContainer>
4649 class TemplateArgumentLocContainerIterator {
4650 ArgLocContainer *Container;
4651 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004652
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004653 public:
4654 typedef TemplateArgumentLoc value_type;
4655 typedef TemplateArgumentLoc reference;
4656 typedef int difference_type;
4657 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004658
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004659 class pointer {
4660 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004661
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004662 public:
4663 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004664
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004665 const TemplateArgumentLoc *operator->() const {
4666 return &Arg;
4667 }
4668 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004669
4670
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004671 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004672
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004673 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4674 unsigned Index)
4675 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004676
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004677 TemplateArgumentLocContainerIterator &operator++() {
4678 ++Index;
4679 return *this;
4680 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004681
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004682 TemplateArgumentLocContainerIterator operator++(int) {
4683 TemplateArgumentLocContainerIterator Old(*this);
4684 ++(*this);
4685 return Old;
4686 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004687
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004688 TemplateArgumentLoc operator*() const {
4689 return Container->getArgLoc(Index);
4690 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004691
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004692 pointer operator->() const {
4693 return pointer(Container->getArgLoc(Index));
4694 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004695
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004696 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004697 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004698 return X.Container == Y.Container && X.Index == Y.Index;
4699 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004700
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004701 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004702 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004703 return !(X == Y);
4704 }
4705 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004706
4707
John McCall43fed0d2010-11-12 08:19:04 +00004708template <typename Derived>
4709QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4710 TypeLocBuilder &TLB,
4711 TemplateSpecializationTypeLoc TL,
4712 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004713 TemplateArgumentListInfo NewTemplateArgs;
4714 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4715 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004716 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4717 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004718 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004719 ArgIterator(TL, TL.getNumArgs()),
4720 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004721 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004722
John McCall833ca992009-10-29 08:12:44 +00004723 // FIXME: maybe don't rebuild if all the template arguments are the same.
4724
4725 QualType Result =
4726 getDerived().RebuildTemplateSpecializationType(Template,
4727 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004728 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004729
4730 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004731 // Specializations of template template parameters are represented as
4732 // TemplateSpecializationTypes, and substitution of type alias templates
4733 // within a dependent context can transform them into
4734 // DependentTemplateSpecializationTypes.
4735 if (isa<DependentTemplateSpecializationType>(Result)) {
4736 DependentTemplateSpecializationTypeLoc NewTL
4737 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004738 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004739 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004740 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004741 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004742 NewTL.setLAngleLoc(TL.getLAngleLoc());
4743 NewTL.setRAngleLoc(TL.getRAngleLoc());
4744 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4745 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4746 return Result;
4747 }
4748
John McCall833ca992009-10-29 08:12:44 +00004749 TemplateSpecializationTypeLoc NewTL
4750 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004751 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004752 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4753 NewTL.setLAngleLoc(TL.getLAngleLoc());
4754 NewTL.setRAngleLoc(TL.getRAngleLoc());
4755 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4756 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004757 }
Mike Stump1eb44332009-09-09 15:08:12 +00004758
John McCall833ca992009-10-29 08:12:44 +00004759 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004760}
Mike Stump1eb44332009-09-09 15:08:12 +00004761
Douglas Gregora88f09f2011-02-28 17:23:35 +00004762template <typename Derived>
4763QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4764 TypeLocBuilder &TLB,
4765 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004766 TemplateName Template,
4767 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004768 TemplateArgumentListInfo NewTemplateArgs;
4769 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4770 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4771 typedef TemplateArgumentLocContainerIterator<
4772 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004773 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004774 ArgIterator(TL, TL.getNumArgs()),
4775 NewTemplateArgs))
4776 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004777
Douglas Gregora88f09f2011-02-28 17:23:35 +00004778 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004779
Douglas Gregora88f09f2011-02-28 17:23:35 +00004780 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4781 QualType Result
4782 = getSema().Context.getDependentTemplateSpecializationType(
4783 TL.getTypePtr()->getKeyword(),
4784 DTN->getQualifier(),
4785 DTN->getIdentifier(),
4786 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004787
Douglas Gregora88f09f2011-02-28 17:23:35 +00004788 DependentTemplateSpecializationTypeLoc NewTL
4789 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004790 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004791 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004792 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004793 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004794 NewTL.setLAngleLoc(TL.getLAngleLoc());
4795 NewTL.setRAngleLoc(TL.getRAngleLoc());
4796 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4797 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4798 return Result;
4799 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004800
4801 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004802 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004803 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004804 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004805
Douglas Gregora88f09f2011-02-28 17:23:35 +00004806 if (!Result.isNull()) {
4807 /// FIXME: Wrap this in an elaborated-type-specifier?
4808 TemplateSpecializationTypeLoc NewTL
4809 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004810 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004811 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004812 NewTL.setLAngleLoc(TL.getLAngleLoc());
4813 NewTL.setRAngleLoc(TL.getRAngleLoc());
4814 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4815 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4816 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004817
Douglas Gregora88f09f2011-02-28 17:23:35 +00004818 return Result;
4819}
4820
Mike Stump1eb44332009-09-09 15:08:12 +00004821template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004822QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004823TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004824 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004825 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004826
Douglas Gregor9e876872011-03-01 18:12:44 +00004827 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004828 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004829 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004830 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004831 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4832 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004833 return QualType();
4834 }
Mike Stump1eb44332009-09-09 15:08:12 +00004835
John McCall43fed0d2010-11-12 08:19:04 +00004836 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4837 if (NamedT.isNull())
4838 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004839
Richard Smith3e4c6c42011-05-05 21:57:07 +00004840 // C++0x [dcl.type.elab]p2:
4841 // If the identifier resolves to a typedef-name or the simple-template-id
4842 // resolves to an alias template specialization, the
4843 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004844 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4845 if (const TemplateSpecializationType *TST =
4846 NamedT->getAs<TemplateSpecializationType>()) {
4847 TemplateName Template = TST->getTemplateName();
4848 if (TypeAliasTemplateDecl *TAT =
4849 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4850 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4851 diag::err_tag_reference_non_tag) << 4;
4852 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4853 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004854 }
4855 }
4856
John McCalla2becad2009-10-21 00:40:46 +00004857 QualType Result = TL.getType();
4858 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004859 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004860 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004861 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004862 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004863 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004864 if (Result.isNull())
4865 return QualType();
4866 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004867
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004868 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004869 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004870 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004871 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004872}
Mike Stump1eb44332009-09-09 15:08:12 +00004873
4874template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004875QualType TreeTransform<Derived>::TransformAttributedType(
4876 TypeLocBuilder &TLB,
4877 AttributedTypeLoc TL) {
4878 const AttributedType *oldType = TL.getTypePtr();
4879 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4880 if (modifiedType.isNull())
4881 return QualType();
4882
4883 QualType result = TL.getType();
4884
4885 // FIXME: dependent operand expressions?
4886 if (getDerived().AlwaysRebuild() ||
4887 modifiedType != oldType->getModifiedType()) {
4888 // TODO: this is really lame; we should really be rebuilding the
4889 // equivalent type from first principles.
4890 QualType equivalentType
4891 = getDerived().TransformType(oldType->getEquivalentType());
4892 if (equivalentType.isNull())
4893 return QualType();
4894 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4895 modifiedType,
4896 equivalentType);
4897 }
4898
4899 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4900 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4901 if (TL.hasAttrOperand())
4902 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4903 if (TL.hasAttrExprOperand())
4904 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4905 else if (TL.hasAttrEnumOperand())
4906 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4907
4908 return result;
4909}
4910
4911template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004912QualType
4913TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4914 ParenTypeLoc TL) {
4915 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4916 if (Inner.isNull())
4917 return QualType();
4918
4919 QualType Result = TL.getType();
4920 if (getDerived().AlwaysRebuild() ||
4921 Inner != TL.getInnerLoc().getType()) {
4922 Result = getDerived().RebuildParenType(Inner);
4923 if (Result.isNull())
4924 return QualType();
4925 }
4926
4927 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4928 NewTL.setLParenLoc(TL.getLParenLoc());
4929 NewTL.setRParenLoc(TL.getRParenLoc());
4930 return Result;
4931}
4932
4933template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004934QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004935 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004936 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004937
Douglas Gregor2494dd02011-03-01 01:34:45 +00004938 NestedNameSpecifierLoc QualifierLoc
4939 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4940 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004941 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004942
John McCall33500952010-06-11 00:33:02 +00004943 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004944 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004945 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004946 QualifierLoc,
4947 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004948 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004949 if (Result.isNull())
4950 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004951
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004952 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4953 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004954 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4955
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004956 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004957 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004958 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004959 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004960 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004961 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004962 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004963 NewTL.setNameLoc(TL.getNameLoc());
4964 }
John McCalla2becad2009-10-21 00:40:46 +00004965 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004966}
Mike Stump1eb44332009-09-09 15:08:12 +00004967
Douglas Gregor577f75a2009-08-04 16:50:30 +00004968template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004969QualType TreeTransform<Derived>::
4970 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004971 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004972 NestedNameSpecifierLoc QualifierLoc;
4973 if (TL.getQualifierLoc()) {
4974 QualifierLoc
4975 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4976 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004977 return QualType();
4978 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004979
John McCall43fed0d2010-11-12 08:19:04 +00004980 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004981 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004982}
4983
4984template<typename Derived>
4985QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004986TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4987 DependentTemplateSpecializationTypeLoc TL,
4988 NestedNameSpecifierLoc QualifierLoc) {
4989 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004990
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004991 TemplateArgumentListInfo NewTemplateArgs;
4992 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4993 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004994
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004995 typedef TemplateArgumentLocContainerIterator<
4996 DependentTemplateSpecializationTypeLoc> ArgIterator;
4997 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4998 ArgIterator(TL, TL.getNumArgs()),
4999 NewTemplateArgs))
5000 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005001
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005002 QualType Result
5003 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5004 QualifierLoc,
5005 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005006 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005007 NewTemplateArgs);
5008 if (Result.isNull())
5009 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005010
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005011 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5012 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005013
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005014 // Copy information relevant to the template specialization.
5015 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005016 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005017 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005018 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005019 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5020 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005021 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005022 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005023
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005024 // Copy information relevant to the elaborated type.
5025 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005026 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005027 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005028 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5029 DependentTemplateSpecializationTypeLoc SpecTL
5030 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005031 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005032 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005033 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005034 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005035 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5036 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005037 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005038 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005039 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005040 TemplateSpecializationTypeLoc SpecTL
5041 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005042 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005043 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005044 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5045 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005046 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005047 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005048 }
5049 return Result;
5050}
5051
5052template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005053QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5054 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005055 QualType Pattern
5056 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005057 if (Pattern.isNull())
5058 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005059
5060 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005061 if (getDerived().AlwaysRebuild() ||
5062 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005063 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005064 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005065 TL.getEllipsisLoc(),
5066 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005067 if (Result.isNull())
5068 return QualType();
5069 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005070
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005071 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5072 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5073 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005074}
5075
5076template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005077QualType
5078TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005079 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005080 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005081 TLB.pushFullCopy(TL);
5082 return TL.getType();
5083}
5084
5085template<typename Derived>
5086QualType
5087TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005088 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005089 // ObjCObjectType is never dependent.
5090 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005091 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005092}
Mike Stump1eb44332009-09-09 15:08:12 +00005093
5094template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005095QualType
5096TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005097 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005098 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005099 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005100 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005101}
5102
Douglas Gregor577f75a2009-08-04 16:50:30 +00005103//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005104// Statement transformation
5105//===----------------------------------------------------------------------===//
5106template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005107StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005108TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005109 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005110}
5111
5112template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005113StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005114TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5115 return getDerived().TransformCompoundStmt(S, false);
5116}
5117
5118template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005119StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005120TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005121 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005122 Sema::CompoundScopeRAII CompoundScope(getSema());
5123
John McCall7114cba2010-08-27 19:56:05 +00005124 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005125 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005126 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005127 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5128 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005129 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005130 if (Result.isInvalid()) {
5131 // Immediately fail if this was a DeclStmt, since it's very
5132 // likely that this will cause problems for future statements.
5133 if (isa<DeclStmt>(*B))
5134 return StmtError();
5135
5136 // Otherwise, just keep processing substatements and fail later.
5137 SubStmtInvalid = true;
5138 continue;
5139 }
Mike Stump1eb44332009-09-09 15:08:12 +00005140
Douglas Gregor43959a92009-08-20 07:17:43 +00005141 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5142 Statements.push_back(Result.takeAs<Stmt>());
5143 }
Mike Stump1eb44332009-09-09 15:08:12 +00005144
John McCall7114cba2010-08-27 19:56:05 +00005145 if (SubStmtInvalid)
5146 return StmtError();
5147
Douglas Gregor43959a92009-08-20 07:17:43 +00005148 if (!getDerived().AlwaysRebuild() &&
5149 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005150 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005151
5152 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005153 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005154 S->getRBracLoc(),
5155 IsStmtExpr);
5156}
Mike Stump1eb44332009-09-09 15:08:12 +00005157
Douglas Gregor43959a92009-08-20 07:17:43 +00005158template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005159StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005160TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005161 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005162 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005163 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5164 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005165
Eli Friedman264c1f82009-11-19 03:14:00 +00005166 // Transform the left-hand case value.
5167 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005168 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005169 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005170 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005171
Eli Friedman264c1f82009-11-19 03:14:00 +00005172 // Transform the right-hand case value (for the GNU case-range extension).
5173 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005174 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005175 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005176 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005177 }
Mike Stump1eb44332009-09-09 15:08:12 +00005178
Douglas Gregor43959a92009-08-20 07:17:43 +00005179 // Build the case statement.
5180 // Case statements are always rebuilt so that they will attached to their
5181 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005182 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005183 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005184 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005185 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005186 S->getColonLoc());
5187 if (Case.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 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005191 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005192 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005193 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005194
Douglas Gregor43959a92009-08-20 07:17:43 +00005195 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005196 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005197}
5198
5199template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005200StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005201TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005202 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005203 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005204 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005205 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005206
Douglas Gregor43959a92009-08-20 07:17:43 +00005207 // Default statements are always rebuilt
5208 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005209 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005210}
Mike Stump1eb44332009-09-09 15:08:12 +00005211
Douglas Gregor43959a92009-08-20 07:17:43 +00005212template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005213StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005214TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005215 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005216 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005217 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005218
Chris Lattner57ad3782011-02-17 20:34:02 +00005219 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5220 S->getDecl());
5221 if (!LD)
5222 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005223
5224
Douglas Gregor43959a92009-08-20 07:17:43 +00005225 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005226 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005227 cast<LabelDecl>(LD), SourceLocation(),
5228 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005229}
Mike Stump1eb44332009-09-09 15:08:12 +00005230
Douglas Gregor43959a92009-08-20 07:17:43 +00005231template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005232StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005233TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5234 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5235 if (SubStmt.isInvalid())
5236 return StmtError();
5237
5238 // TODO: transform attributes
5239 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5240 return S;
5241
5242 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5243 S->getAttrs(),
5244 SubStmt.get());
5245}
5246
5247template<typename Derived>
5248StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005249TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005250 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005251 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005252 VarDecl *ConditionVar = 0;
5253 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005254 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005255 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005256 getDerived().TransformDefinition(
5257 S->getConditionVariable()->getLocation(),
5258 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005259 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005260 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005261 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005262 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005263
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005264 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005265 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005266
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005267 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005268 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005269 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005270 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005271 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005272 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005273
John McCall9ae2f072010-08-23 23:25:46 +00005274 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005275 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005276 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005277
John McCall9ae2f072010-08-23 23:25:46 +00005278 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5279 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005280 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005281
Douglas Gregor43959a92009-08-20 07:17:43 +00005282 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005283 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005284 if (Then.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 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005288 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005289 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005290 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005291
Douglas Gregor43959a92009-08-20 07:17:43 +00005292 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005293 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005294 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005295 Then.get() == S->getThen() &&
5296 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005297 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005298
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005299 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005300 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005301 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005302}
5303
5304template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005305StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005306TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005307 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005308 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005309 VarDecl *ConditionVar = 0;
5310 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005311 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005312 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005313 getDerived().TransformDefinition(
5314 S->getConditionVariable()->getLocation(),
5315 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005316 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005317 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005318 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005319 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005320
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005321 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005322 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005323 }
Mike Stump1eb44332009-09-09 15:08:12 +00005324
Douglas Gregor43959a92009-08-20 07:17:43 +00005325 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005326 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005327 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005328 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005329 if (Switch.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 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005333 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005334 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005335 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005336
Douglas Gregor43959a92009-08-20 07:17:43 +00005337 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005338 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5339 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005340}
Mike Stump1eb44332009-09-09 15:08:12 +00005341
Douglas Gregor43959a92009-08-20 07:17:43 +00005342template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005343StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005344TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005345 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005346 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005347 VarDecl *ConditionVar = 0;
5348 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005349 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005350 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005351 getDerived().TransformDefinition(
5352 S->getConditionVariable()->getLocation(),
5353 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005354 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005355 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005356 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005357 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005358
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005359 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005360 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005361
5362 if (S->getCond()) {
5363 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005364 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005365 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005366 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005367 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005368 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005369 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005370 }
Mike Stump1eb44332009-09-09 15:08:12 +00005371
John McCall9ae2f072010-08-23 23:25:46 +00005372 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5373 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005374 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005375
Douglas Gregor43959a92009-08-20 07:17:43 +00005376 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005377 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005378 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005379 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005380
Douglas Gregor43959a92009-08-20 07:17:43 +00005381 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005382 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005383 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005384 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005385 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005386
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005387 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005388 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005389}
Mike Stump1eb44332009-09-09 15:08:12 +00005390
Douglas Gregor43959a92009-08-20 07:17:43 +00005391template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005392StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005393TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005394 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005395 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005396 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005397 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005398
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005399 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005400 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005401 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005402 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005403
Douglas Gregor43959a92009-08-20 07:17:43 +00005404 if (!getDerived().AlwaysRebuild() &&
5405 Cond.get() == S->getCond() &&
5406 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005407 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005408
John McCall9ae2f072010-08-23 23:25:46 +00005409 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5410 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005411 S->getRParenLoc());
5412}
Mike Stump1eb44332009-09-09 15:08:12 +00005413
Douglas Gregor43959a92009-08-20 07:17:43 +00005414template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005415StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005416TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005417 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005418 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005419 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005420 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005421
Douglas Gregor43959a92009-08-20 07:17:43 +00005422 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005423 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005424 VarDecl *ConditionVar = 0;
5425 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005426 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005427 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005428 getDerived().TransformDefinition(
5429 S->getConditionVariable()->getLocation(),
5430 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005431 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005432 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005433 } else {
5434 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005435
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005436 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005437 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005438
5439 if (S->getCond()) {
5440 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005441 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005442 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005443 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005444 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005445
John McCall9ae2f072010-08-23 23:25:46 +00005446 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005447 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005448 }
Mike Stump1eb44332009-09-09 15:08:12 +00005449
Chad Rosier4a9d7952012-08-08 18:46:20 +00005450 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005451 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005452 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005453
Douglas Gregor43959a92009-08-20 07:17:43 +00005454 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005455 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005456 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005457 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005458
Richard Smith41956372013-01-14 22:39:08 +00005459 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005460 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005461 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005462
Douglas Gregor43959a92009-08-20 07:17:43 +00005463 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005464 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005465 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005466 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005467
Douglas Gregor43959a92009-08-20 07:17:43 +00005468 if (!getDerived().AlwaysRebuild() &&
5469 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005470 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005471 Inc.get() == S->getInc() &&
5472 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005473 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005474
Douglas Gregor43959a92009-08-20 07:17:43 +00005475 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005476 Init.get(), FullCond, ConditionVar,
5477 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005478}
5479
5480template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005481StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005482TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005483 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5484 S->getLabel());
5485 if (!LD)
5486 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005487
Douglas Gregor43959a92009-08-20 07:17:43 +00005488 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005489 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005490 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005491}
5492
5493template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005494StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005495TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005496 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005497 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005498 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005499 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005500
Douglas Gregor43959a92009-08-20 07:17:43 +00005501 if (!getDerived().AlwaysRebuild() &&
5502 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005503 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005504
5505 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005506 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005507}
5508
5509template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005510StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005511TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005512 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005513}
Mike Stump1eb44332009-09-09 15:08:12 +00005514
Douglas Gregor43959a92009-08-20 07:17:43 +00005515template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005516StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005517TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005518 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005519}
Mike Stump1eb44332009-09-09 15:08:12 +00005520
Douglas Gregor43959a92009-08-20 07:17:43 +00005521template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005522StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005523TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005524 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005525 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005526 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005527
Mike Stump1eb44332009-09-09 15:08:12 +00005528 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005529 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005530 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005531}
Mike Stump1eb44332009-09-09 15:08:12 +00005532
Douglas Gregor43959a92009-08-20 07:17:43 +00005533template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005534StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005535TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005536 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005537 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005538 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5539 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005540 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5541 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005542 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005543 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005544
Douglas Gregor43959a92009-08-20 07:17:43 +00005545 if (Transformed != *D)
5546 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005547
Douglas Gregor43959a92009-08-20 07:17:43 +00005548 Decls.push_back(Transformed);
5549 }
Mike Stump1eb44332009-09-09 15:08:12 +00005550
Douglas Gregor43959a92009-08-20 07:17:43 +00005551 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005552 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005553
5554 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005555 S->getStartLoc(), S->getEndLoc());
5556}
Mike Stump1eb44332009-09-09 15:08:12 +00005557
Douglas Gregor43959a92009-08-20 07:17:43 +00005558template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005559StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005560TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005561
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005562 SmallVector<Expr*, 8> Constraints;
5563 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005564 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005565
John McCall60d7b3a2010-08-24 06:29:42 +00005566 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005567 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005568
5569 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005570
Anders Carlsson703e3942010-01-24 05:50:09 +00005571 // Go through the outputs.
5572 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005573 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005574
Anders Carlsson703e3942010-01-24 05:50:09 +00005575 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005576 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005577
Anders Carlsson703e3942010-01-24 05:50:09 +00005578 // Transform the output expr.
5579 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005580 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005581 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005582 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005583
Anders Carlsson703e3942010-01-24 05:50:09 +00005584 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005585
John McCall9ae2f072010-08-23 23:25:46 +00005586 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005587 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005588
Anders Carlsson703e3942010-01-24 05:50:09 +00005589 // Go through the inputs.
5590 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005591 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005592
Anders Carlsson703e3942010-01-24 05:50:09 +00005593 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005594 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005595
Anders Carlsson703e3942010-01-24 05:50:09 +00005596 // Transform the input expr.
5597 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005598 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005599 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005600 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005601
Anders Carlsson703e3942010-01-24 05:50:09 +00005602 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005603
John McCall9ae2f072010-08-23 23:25:46 +00005604 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005605 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005606
Anders Carlsson703e3942010-01-24 05:50:09 +00005607 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005608 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005609
5610 // Go through the clobbers.
5611 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005612 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005613
5614 // No need to transform the asm string literal.
5615 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005616 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5617 S->isVolatile(), S->getNumOutputs(),
5618 S->getNumInputs(), Names.data(),
5619 Constraints, Exprs, AsmString.get(),
5620 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005621}
5622
Chad Rosier8cd64b42012-06-11 20:47:18 +00005623template<typename Derived>
5624StmtResult
5625TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005626 ArrayRef<Token> AsmToks =
5627 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005628
Chad Rosier7bd092b2012-08-15 16:53:30 +00005629 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
5630 AsmToks, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005631}
Douglas Gregor43959a92009-08-20 07:17:43 +00005632
5633template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005634StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005635TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005636 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005637 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005638 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005639 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005640
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005641 // Transform the @catch statements (if present).
5642 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005643 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005644 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005645 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005646 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005647 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005648 if (Catch.get() != S->getCatchStmt(I))
5649 AnyCatchChanged = true;
5650 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005651 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005652
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005653 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005654 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005655 if (S->getFinallyStmt()) {
5656 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5657 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005658 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005659 }
5660
5661 // If nothing changed, just retain this statement.
5662 if (!getDerived().AlwaysRebuild() &&
5663 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005664 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005665 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005666 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005667
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005668 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005669 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005670 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005671}
Mike Stump1eb44332009-09-09 15:08:12 +00005672
Douglas Gregor43959a92009-08-20 07:17:43 +00005673template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005674StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005675TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005676 // Transform the @catch parameter, if there is one.
5677 VarDecl *Var = 0;
5678 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5679 TypeSourceInfo *TSInfo = 0;
5680 if (FromVar->getTypeSourceInfo()) {
5681 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5682 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005683 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005684 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005685
Douglas Gregorbe270a02010-04-26 17:57:08 +00005686 QualType T;
5687 if (TSInfo)
5688 T = TSInfo->getType();
5689 else {
5690 T = getDerived().TransformType(FromVar->getType());
5691 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005692 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005693 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005694
Douglas Gregorbe270a02010-04-26 17:57:08 +00005695 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5696 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005697 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005698 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005699
John McCall60d7b3a2010-08-24 06:29:42 +00005700 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005701 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005702 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005703
5704 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005705 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005706 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005707}
Mike Stump1eb44332009-09-09 15:08:12 +00005708
Douglas Gregor43959a92009-08-20 07:17:43 +00005709template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005710StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005711TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005712 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005713 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005714 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005715 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005716
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005717 // If nothing changed, just retain this statement.
5718 if (!getDerived().AlwaysRebuild() &&
5719 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005720 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005721
5722 // Build a new statement.
5723 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005724 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005725}
Mike Stump1eb44332009-09-09 15:08:12 +00005726
Douglas Gregor43959a92009-08-20 07:17:43 +00005727template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005728StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005729TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005730 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005731 if (S->getThrowExpr()) {
5732 Operand = getDerived().TransformExpr(S->getThrowExpr());
5733 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005734 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005735 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005736
Douglas Gregord1377b22010-04-22 21:44:01 +00005737 if (!getDerived().AlwaysRebuild() &&
5738 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005739 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005740
John McCall9ae2f072010-08-23 23:25:46 +00005741 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005742}
Mike Stump1eb44332009-09-09 15:08:12 +00005743
Douglas Gregor43959a92009-08-20 07:17:43 +00005744template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005745StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005746TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005747 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005748 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005749 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005750 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005751 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005752 Object =
5753 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5754 Object.get());
5755 if (Object.isInvalid())
5756 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005757
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005758 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005759 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005760 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005761 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005762
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005763 // If nothing change, just retain the current statement.
5764 if (!getDerived().AlwaysRebuild() &&
5765 Object.get() == S->getSynchExpr() &&
5766 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005767 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005768
5769 // Build a new statement.
5770 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005771 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005772}
5773
5774template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005775StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005776TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5777 ObjCAutoreleasePoolStmt *S) {
5778 // Transform the body.
5779 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5780 if (Body.isInvalid())
5781 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005782
John McCallf85e1932011-06-15 23:02:42 +00005783 // If nothing changed, just retain this statement.
5784 if (!getDerived().AlwaysRebuild() &&
5785 Body.get() == S->getSubStmt())
5786 return SemaRef.Owned(S);
5787
5788 // Build a new statement.
5789 return getDerived().RebuildObjCAutoreleasePoolStmt(
5790 S->getAtLoc(), Body.get());
5791}
5792
5793template<typename Derived>
5794StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005795TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005796 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005797 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005798 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005799 if (Element.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 collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005803 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005804 if (Collection.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 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005808 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005809 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005810 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005811
Douglas Gregorc3203e72010-04-22 23:10:45 +00005812 // If nothing changed, just retain this statement.
5813 if (!getDerived().AlwaysRebuild() &&
5814 Element.get() == S->getElement() &&
5815 Collection.get() == S->getCollection() &&
5816 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005817 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005818
Douglas Gregorc3203e72010-04-22 23:10:45 +00005819 // Build a new statement.
5820 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005821 Element.get(),
5822 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005823 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005824 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005825}
5826
5827
5828template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005829StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005830TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5831 // Transform the exception declaration, if any.
5832 VarDecl *Var = 0;
5833 if (S->getExceptionDecl()) {
5834 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005835 TypeSourceInfo *T = getDerived().TransformType(
5836 ExceptionDecl->getTypeSourceInfo());
5837 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005838 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005839
Douglas Gregor83cb9422010-09-09 17:09:21 +00005840 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005841 ExceptionDecl->getInnerLocStart(),
5842 ExceptionDecl->getLocation(),
5843 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005844 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005845 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005846 }
Mike Stump1eb44332009-09-09 15:08:12 +00005847
Douglas Gregor43959a92009-08-20 07:17:43 +00005848 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005849 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005850 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005851 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005852
Douglas Gregor43959a92009-08-20 07:17:43 +00005853 if (!getDerived().AlwaysRebuild() &&
5854 !Var &&
5855 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005856 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005857
5858 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5859 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005860 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005861}
Mike Stump1eb44332009-09-09 15:08:12 +00005862
Douglas Gregor43959a92009-08-20 07:17:43 +00005863template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005864StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005865TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5866 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005867 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005868 = getDerived().TransformCompoundStmt(S->getTryBlock());
5869 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005870 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005871
Douglas Gregor43959a92009-08-20 07:17:43 +00005872 // Transform the handlers.
5873 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005874 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00005875 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005876 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005877 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5878 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005879 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005880
Douglas Gregor43959a92009-08-20 07:17:43 +00005881 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5882 Handlers.push_back(Handler.takeAs<Stmt>());
5883 }
Mike Stump1eb44332009-09-09 15:08:12 +00005884
Douglas Gregor43959a92009-08-20 07:17:43 +00005885 if (!getDerived().AlwaysRebuild() &&
5886 TryBlock.get() == S->getTryBlock() &&
5887 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005888 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005889
John McCall9ae2f072010-08-23 23:25:46 +00005890 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005891 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00005892}
Mike Stump1eb44332009-09-09 15:08:12 +00005893
Richard Smithad762fc2011-04-14 22:09:26 +00005894template<typename Derived>
5895StmtResult
5896TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5897 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5898 if (Range.isInvalid())
5899 return StmtError();
5900
5901 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5902 if (BeginEnd.isInvalid())
5903 return StmtError();
5904
5905 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5906 if (Cond.isInvalid())
5907 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005908 if (Cond.get())
5909 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5910 if (Cond.isInvalid())
5911 return StmtError();
5912 if (Cond.get())
5913 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005914
5915 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5916 if (Inc.isInvalid())
5917 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005918 if (Inc.get())
5919 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005920
5921 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5922 if (LoopVar.isInvalid())
5923 return StmtError();
5924
5925 StmtResult NewStmt = S;
5926 if (getDerived().AlwaysRebuild() ||
5927 Range.get() != S->getRangeStmt() ||
5928 BeginEnd.get() != S->getBeginEndStmt() ||
5929 Cond.get() != S->getCond() ||
5930 Inc.get() != S->getInc() ||
5931 LoopVar.get() != S->getLoopVarStmt())
5932 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5933 S->getColonLoc(), Range.get(),
5934 BeginEnd.get(), Cond.get(),
5935 Inc.get(), LoopVar.get(),
5936 S->getRParenLoc());
5937
5938 StmtResult Body = getDerived().TransformStmt(S->getBody());
5939 if (Body.isInvalid())
5940 return StmtError();
5941
5942 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5943 // it now so we have a new statement to attach the body to.
5944 if (Body.get() != S->getBody() && NewStmt.get() == S)
5945 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5946 S->getColonLoc(), Range.get(),
5947 BeginEnd.get(), Cond.get(),
5948 Inc.get(), LoopVar.get(),
5949 S->getRParenLoc());
5950
5951 if (NewStmt.get() == S)
5952 return SemaRef.Owned(S);
5953
5954 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5955}
5956
John Wiegley28bbe4b2011-04-28 01:08:34 +00005957template<typename Derived>
5958StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005959TreeTransform<Derived>::TransformMSDependentExistsStmt(
5960 MSDependentExistsStmt *S) {
5961 // Transform the nested-name-specifier, if any.
5962 NestedNameSpecifierLoc QualifierLoc;
5963 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005964 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00005965 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5966 if (!QualifierLoc)
5967 return StmtError();
5968 }
5969
5970 // Transform the declaration name.
5971 DeclarationNameInfo NameInfo = S->getNameInfo();
5972 if (NameInfo.getName()) {
5973 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5974 if (!NameInfo.getName())
5975 return StmtError();
5976 }
5977
5978 // Check whether anything changed.
5979 if (!getDerived().AlwaysRebuild() &&
5980 QualifierLoc == S->getQualifierLoc() &&
5981 NameInfo.getName() == S->getNameInfo().getName())
5982 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005983
Douglas Gregorba0513d2011-10-25 01:33:02 +00005984 // Determine whether this name exists, if we can.
5985 CXXScopeSpec SS;
5986 SS.Adopt(QualifierLoc);
5987 bool Dependent = false;
5988 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5989 case Sema::IER_Exists:
5990 if (S->isIfExists())
5991 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005992
Douglas Gregorba0513d2011-10-25 01:33:02 +00005993 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5994
5995 case Sema::IER_DoesNotExist:
5996 if (S->isIfNotExists())
5997 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005998
Douglas Gregorba0513d2011-10-25 01:33:02 +00005999 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006000
Douglas Gregorba0513d2011-10-25 01:33:02 +00006001 case Sema::IER_Dependent:
6002 Dependent = true;
6003 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006004
Douglas Gregor65019ac2011-10-25 03:44:56 +00006005 case Sema::IER_Error:
6006 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006007 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006008
Douglas Gregorba0513d2011-10-25 01:33:02 +00006009 // We need to continue with the instantiation, so do so now.
6010 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6011 if (SubStmt.isInvalid())
6012 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006013
Douglas Gregorba0513d2011-10-25 01:33:02 +00006014 // If we have resolved the name, just transform to the substatement.
6015 if (!Dependent)
6016 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006017
Douglas Gregorba0513d2011-10-25 01:33:02 +00006018 // The name is still dependent, so build a dependent expression again.
6019 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6020 S->isIfExists(),
6021 QualifierLoc,
6022 NameInfo,
6023 SubStmt.get());
6024}
6025
6026template<typename Derived>
6027StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006028TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6029 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6030 if(TryBlock.isInvalid()) return StmtError();
6031
6032 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6033 if(!getDerived().AlwaysRebuild() &&
6034 TryBlock.get() == S->getTryBlock() &&
6035 Handler.get() == S->getHandler())
6036 return SemaRef.Owned(S);
6037
6038 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6039 S->getTryLoc(),
6040 TryBlock.take(),
6041 Handler.take());
6042}
6043
6044template<typename Derived>
6045StmtResult
6046TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6047 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6048 if(Block.isInvalid()) return StmtError();
6049
6050 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6051 Block.take());
6052}
6053
6054template<typename Derived>
6055StmtResult
6056TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6057 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6058 if(FilterExpr.isInvalid()) return StmtError();
6059
6060 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6061 if(Block.isInvalid()) return StmtError();
6062
6063 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6064 FilterExpr.take(),
6065 Block.take());
6066}
6067
6068template<typename Derived>
6069StmtResult
6070TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6071 if(isa<SEHFinallyStmt>(Handler))
6072 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6073 else
6074 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6075}
6076
Douglas Gregor43959a92009-08-20 07:17:43 +00006077//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006078// Expression transformation
6079//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006080template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006081ExprResult
John McCall454feb92009-12-08 09:21:05 +00006082TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006083 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006084}
Mike Stump1eb44332009-09-09 15:08:12 +00006085
6086template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006087ExprResult
John McCall454feb92009-12-08 09:21:05 +00006088TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006089 NestedNameSpecifierLoc QualifierLoc;
6090 if (E->getQualifierLoc()) {
6091 QualifierLoc
6092 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6093 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006094 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006095 }
John McCalldbd872f2009-12-08 09:08:17 +00006096
6097 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006098 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6099 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006100 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006101 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006102
John McCallec8045d2010-08-17 21:27:17 +00006103 DeclarationNameInfo NameInfo = E->getNameInfo();
6104 if (NameInfo.getName()) {
6105 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6106 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006107 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006108 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006109
6110 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006111 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006112 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006113 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006114 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006115
6116 // Mark it referenced in the new context regardless.
6117 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006118 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006119
John McCall3fa5cae2010-10-26 07:05:15 +00006120 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006121 }
John McCalldbd872f2009-12-08 09:08:17 +00006122
6123 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006124 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006125 TemplateArgs = &TransArgs;
6126 TransArgs.setLAngleLoc(E->getLAngleLoc());
6127 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006128 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6129 E->getNumTemplateArgs(),
6130 TransArgs))
6131 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006132 }
6133
Chad Rosier4a9d7952012-08-08 18:46:20 +00006134 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006135 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006136}
Mike Stump1eb44332009-09-09 15:08:12 +00006137
Douglas Gregorb98b1992009-08-11 05:31:07 +00006138template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006139ExprResult
John McCall454feb92009-12-08 09:21:05 +00006140TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006141 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006142}
Mike Stump1eb44332009-09-09 15:08:12 +00006143
Douglas Gregorb98b1992009-08-11 05:31:07 +00006144template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006145ExprResult
John McCall454feb92009-12-08 09:21:05 +00006146TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006147 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006148}
Mike Stump1eb44332009-09-09 15:08:12 +00006149
Douglas Gregorb98b1992009-08-11 05:31:07 +00006150template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006151ExprResult
John McCall454feb92009-12-08 09:21:05 +00006152TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006153 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006154}
Mike Stump1eb44332009-09-09 15:08:12 +00006155
Douglas Gregorb98b1992009-08-11 05:31:07 +00006156template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006157ExprResult
John McCall454feb92009-12-08 09:21:05 +00006158TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006159 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006160}
Mike Stump1eb44332009-09-09 15:08:12 +00006161
Douglas Gregorb98b1992009-08-11 05:31:07 +00006162template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006163ExprResult
John McCall454feb92009-12-08 09:21:05 +00006164TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006165 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006166}
6167
6168template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006169ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006170TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6171 return SemaRef.MaybeBindToTemporary(E);
6172}
6173
6174template<typename Derived>
6175ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006176TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6177 ExprResult ControllingExpr =
6178 getDerived().TransformExpr(E->getControllingExpr());
6179 if (ControllingExpr.isInvalid())
6180 return ExprError();
6181
Chris Lattner686775d2011-07-20 06:58:45 +00006182 SmallVector<Expr *, 4> AssocExprs;
6183 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006184 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6185 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6186 if (TS) {
6187 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6188 if (!AssocType)
6189 return ExprError();
6190 AssocTypes.push_back(AssocType);
6191 } else {
6192 AssocTypes.push_back(0);
6193 }
6194
6195 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6196 if (AssocExpr.isInvalid())
6197 return ExprError();
6198 AssocExprs.push_back(AssocExpr.release());
6199 }
6200
6201 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6202 E->getDefaultLoc(),
6203 E->getRParenLoc(),
6204 ControllingExpr.release(),
6205 AssocTypes.data(),
6206 AssocExprs.data(),
6207 E->getNumAssocs());
6208}
6209
6210template<typename Derived>
6211ExprResult
John McCall454feb92009-12-08 09:21:05 +00006212TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006213 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006214 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006215 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006216
Douglas Gregorb98b1992009-08-11 05:31:07 +00006217 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006218 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006219
John McCall9ae2f072010-08-23 23:25:46 +00006220 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006221 E->getRParen());
6222}
6223
Richard Smithefeeccf2012-10-21 03:28:35 +00006224/// \brief The operand of a unary address-of operator has special rules: it's
6225/// allowed to refer to a non-static member of a class even if there's no 'this'
6226/// object available.
6227template<typename Derived>
6228ExprResult
6229TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6230 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6231 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6232 else
6233 return getDerived().TransformExpr(E);
6234}
6235
Mike Stump1eb44332009-09-09 15:08:12 +00006236template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006237ExprResult
John McCall454feb92009-12-08 09:21:05 +00006238TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00006239 ExprResult SubExpr = TransformAddressOfOperand(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006240 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006241 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006242
Douglas Gregorb98b1992009-08-11 05:31:07 +00006243 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006244 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006245
Douglas Gregorb98b1992009-08-11 05:31:07 +00006246 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6247 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006248 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006249}
Mike Stump1eb44332009-09-09 15:08:12 +00006250
Douglas Gregorb98b1992009-08-11 05:31:07 +00006251template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006252ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006253TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6254 // Transform the type.
6255 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6256 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006257 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006258
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006259 // Transform all of the components into components similar to what the
6260 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006261 // FIXME: It would be slightly more efficient in the non-dependent case to
6262 // just map FieldDecls, rather than requiring the rebuilder to look for
6263 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006264 // template code that we don't care.
6265 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006266 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006267 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006268 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006269 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6270 const Node &ON = E->getComponent(I);
6271 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006272 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006273 Comp.LocStart = ON.getSourceRange().getBegin();
6274 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006275 switch (ON.getKind()) {
6276 case Node::Array: {
6277 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006278 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006279 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006280 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006281
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006282 ExprChanged = ExprChanged || Index.get() != FromIndex;
6283 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006284 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006285 break;
6286 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006287
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006288 case Node::Field:
6289 case Node::Identifier:
6290 Comp.isBrackets = false;
6291 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006292 if (!Comp.U.IdentInfo)
6293 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006294
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006295 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006296
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006297 case Node::Base:
6298 // Will be recomputed during the rebuild.
6299 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006300 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006301
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006302 Components.push_back(Comp);
6303 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006304
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006305 // If nothing changed, retain the existing expression.
6306 if (!getDerived().AlwaysRebuild() &&
6307 Type == E->getTypeSourceInfo() &&
6308 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006309 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006310
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006311 // Build a new offsetof expression.
6312 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6313 Components.data(), Components.size(),
6314 E->getRParenLoc());
6315}
6316
6317template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006318ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006319TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6320 assert(getDerived().AlreadyTransformed(E->getType()) &&
6321 "opaque value expression requires transformation");
6322 return SemaRef.Owned(E);
6323}
6324
6325template<typename Derived>
6326ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006327TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006328 // Rebuild the syntactic form. The original syntactic form has
6329 // opaque-value expressions in it, so strip those away and rebuild
6330 // the result. This is a really awful way of doing this, but the
6331 // better solution (rebuilding the semantic expressions and
6332 // rebinding OVEs as necessary) doesn't work; we'd need
6333 // TreeTransform to not strip away implicit conversions.
6334 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6335 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006336 if (result.isInvalid()) return ExprError();
6337
6338 // If that gives us a pseudo-object result back, the pseudo-object
6339 // expression must have been an lvalue-to-rvalue conversion which we
6340 // should reapply.
6341 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6342 result = SemaRef.checkPseudoObjectRValue(result.take());
6343
6344 return result;
6345}
6346
6347template<typename Derived>
6348ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006349TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6350 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006351 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006352 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006353
John McCalla93c9342009-12-07 02:54:59 +00006354 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006355 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006356 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006357
John McCall5ab75172009-11-04 07:28:41 +00006358 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006359 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006360
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006361 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6362 E->getKind(),
6363 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006364 }
Mike Stump1eb44332009-09-09 15:08:12 +00006365
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006366 // C++0x [expr.sizeof]p1:
6367 // The operand is either an expression, which is an unevaluated operand
6368 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006369 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6370 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006371
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006372 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6373 if (SubExpr.isInvalid())
6374 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006375
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006376 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6377 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006378
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006379 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6380 E->getOperatorLoc(),
6381 E->getKind(),
6382 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006383}
Mike Stump1eb44332009-09-09 15:08:12 +00006384
Douglas Gregorb98b1992009-08-11 05:31:07 +00006385template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006386ExprResult
John McCall454feb92009-12-08 09:21:05 +00006387TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006388 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006389 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006390 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006391
John McCall60d7b3a2010-08-24 06:29:42 +00006392 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006393 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006394 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006395
6396
Douglas Gregorb98b1992009-08-11 05:31:07 +00006397 if (!getDerived().AlwaysRebuild() &&
6398 LHS.get() == E->getLHS() &&
6399 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006400 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006401
John McCall9ae2f072010-08-23 23:25:46 +00006402 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006403 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006404 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006405 E->getRBracketLoc());
6406}
Mike Stump1eb44332009-09-09 15:08:12 +00006407
6408template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006409ExprResult
John McCall454feb92009-12-08 09:21:05 +00006410TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006411 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006412 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006413 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006414 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006415
6416 // Transform arguments.
6417 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006418 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006419 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006420 &ArgChanged))
6421 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006422
Douglas Gregorb98b1992009-08-11 05:31:07 +00006423 if (!getDerived().AlwaysRebuild() &&
6424 Callee.get() == E->getCallee() &&
6425 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006426 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006427
Douglas Gregorb98b1992009-08-11 05:31:07 +00006428 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006429 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006430 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006431 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006432 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006433 E->getRParenLoc());
6434}
Mike Stump1eb44332009-09-09 15:08:12 +00006435
6436template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006437ExprResult
John McCall454feb92009-12-08 09:21:05 +00006438TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006439 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006440 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006441 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006442
Douglas Gregor40d96a62011-02-28 21:54:11 +00006443 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006444 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006445 QualifierLoc
6446 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006447
Douglas Gregor40d96a62011-02-28 21:54:11 +00006448 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006449 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006450 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006451 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006452
Eli Friedmanf595cc42009-12-04 06:40:45 +00006453 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006454 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6455 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006456 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006457 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006458
John McCall6bb80172010-03-30 21:47:33 +00006459 NamedDecl *FoundDecl = E->getFoundDecl();
6460 if (FoundDecl == E->getMemberDecl()) {
6461 FoundDecl = Member;
6462 } else {
6463 FoundDecl = cast_or_null<NamedDecl>(
6464 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6465 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006466 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006467 }
6468
Douglas Gregorb98b1992009-08-11 05:31:07 +00006469 if (!getDerived().AlwaysRebuild() &&
6470 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006471 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006472 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006473 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006474 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006475
Anders Carlsson1f240322009-12-22 05:24:09 +00006476 // Mark it referenced in the new context regardless.
6477 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006478 SemaRef.MarkMemberReferenced(E);
6479
John McCall3fa5cae2010-10-26 07:05:15 +00006480 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006481 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006482
John McCalld5532b62009-11-23 01:53:49 +00006483 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006484 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006485 TransArgs.setLAngleLoc(E->getLAngleLoc());
6486 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006487 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6488 E->getNumTemplateArgs(),
6489 TransArgs))
6490 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006491 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006492
Douglas Gregorb98b1992009-08-11 05:31:07 +00006493 // FIXME: Bogus source location for the operator
6494 SourceLocation FakeOperatorLoc
6495 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6496
John McCallc2233c52010-01-15 08:34:02 +00006497 // FIXME: to do this check properly, we will need to preserve the
6498 // first-qualifier-in-scope here, just in case we had a dependent
6499 // base (and therefore couldn't do the check) and a
6500 // nested-name-qualifier (and therefore could do the lookup).
6501 NamedDecl *FirstQualifierInScope = 0;
6502
John McCall9ae2f072010-08-23 23:25:46 +00006503 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006504 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006505 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006506 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006507 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006508 Member,
John McCall6bb80172010-03-30 21:47:33 +00006509 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006510 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006511 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006512 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006513}
Mike Stump1eb44332009-09-09 15:08:12 +00006514
Douglas Gregorb98b1992009-08-11 05:31:07 +00006515template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006516ExprResult
John McCall454feb92009-12-08 09:21:05 +00006517TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006518 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006519 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006520 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006521
John McCall60d7b3a2010-08-24 06:29:42 +00006522 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006523 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006524 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006525
Douglas Gregorb98b1992009-08-11 05:31:07 +00006526 if (!getDerived().AlwaysRebuild() &&
6527 LHS.get() == E->getLHS() &&
6528 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006529 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006530
Lang Hamesbe9af122012-10-02 04:45:10 +00006531 Sema::FPContractStateRAII FPContractState(getSema());
6532 getSema().FPFeatures.fp_contract = E->isFPContractable();
6533
Douglas Gregorb98b1992009-08-11 05:31:07 +00006534 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006535 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006536}
6537
Mike Stump1eb44332009-09-09 15:08:12 +00006538template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006539ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006540TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006541 CompoundAssignOperator *E) {
6542 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006543}
Mike Stump1eb44332009-09-09 15:08:12 +00006544
Douglas Gregorb98b1992009-08-11 05:31:07 +00006545template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006546ExprResult TreeTransform<Derived>::
6547TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6548 // Just rebuild the common and RHS expressions and see whether we
6549 // get any changes.
6550
6551 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6552 if (commonExpr.isInvalid())
6553 return ExprError();
6554
6555 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6556 if (rhs.isInvalid())
6557 return ExprError();
6558
6559 if (!getDerived().AlwaysRebuild() &&
6560 commonExpr.get() == e->getCommon() &&
6561 rhs.get() == e->getFalseExpr())
6562 return SemaRef.Owned(e);
6563
6564 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6565 e->getQuestionLoc(),
6566 0,
6567 e->getColonLoc(),
6568 rhs.get());
6569}
6570
6571template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006572ExprResult
John McCall454feb92009-12-08 09:21:05 +00006573TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006574 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006575 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006576 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006577
John McCall60d7b3a2010-08-24 06:29:42 +00006578 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006579 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006580 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006581
John McCall60d7b3a2010-08-24 06:29:42 +00006582 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006583 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006584 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006585
Douglas Gregorb98b1992009-08-11 05:31:07 +00006586 if (!getDerived().AlwaysRebuild() &&
6587 Cond.get() == E->getCond() &&
6588 LHS.get() == E->getLHS() &&
6589 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006590 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006591
John McCall9ae2f072010-08-23 23:25:46 +00006592 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006593 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006594 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006595 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006596 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006597}
Mike Stump1eb44332009-09-09 15:08:12 +00006598
6599template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006600ExprResult
John McCall454feb92009-12-08 09:21:05 +00006601TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006602 // Implicit casts are eliminated during transformation, since they
6603 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006604 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006605}
Mike Stump1eb44332009-09-09 15:08:12 +00006606
Douglas Gregorb98b1992009-08-11 05:31:07 +00006607template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006608ExprResult
John McCall454feb92009-12-08 09:21:05 +00006609TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006610 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6611 if (!Type)
6612 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006613
John McCall60d7b3a2010-08-24 06:29:42 +00006614 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006615 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006616 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006617 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006618
Douglas Gregorb98b1992009-08-11 05:31:07 +00006619 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006620 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006621 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006622 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006623
John McCall9d125032010-01-15 18:39:57 +00006624 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006625 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006626 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006627 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006628}
Mike Stump1eb44332009-09-09 15:08:12 +00006629
Douglas Gregorb98b1992009-08-11 05:31:07 +00006630template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006631ExprResult
John McCall454feb92009-12-08 09:21:05 +00006632TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006633 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6634 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6635 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006636 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006637
John McCall60d7b3a2010-08-24 06:29:42 +00006638 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006639 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006640 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006641
Douglas Gregorb98b1992009-08-11 05:31:07 +00006642 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006643 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006644 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006645 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006646
John McCall1d7d8d62010-01-19 22:33:45 +00006647 // Note: the expression type doesn't necessarily match the
6648 // type-as-written, but that's okay, because it should always be
6649 // derivable from the initializer.
6650
John McCall42f56b52010-01-18 19:35:47 +00006651 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006652 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006653 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006654}
Mike Stump1eb44332009-09-09 15:08:12 +00006655
Douglas Gregorb98b1992009-08-11 05:31:07 +00006656template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006657ExprResult
John McCall454feb92009-12-08 09:21:05 +00006658TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006659 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006660 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006661 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006662
Douglas Gregorb98b1992009-08-11 05:31:07 +00006663 if (!getDerived().AlwaysRebuild() &&
6664 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006665 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006666
Douglas Gregorb98b1992009-08-11 05:31:07 +00006667 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006668 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006669 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006670 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006671 E->getAccessorLoc(),
6672 E->getAccessor());
6673}
Mike Stump1eb44332009-09-09 15:08:12 +00006674
Douglas Gregorb98b1992009-08-11 05:31:07 +00006675template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006676ExprResult
John McCall454feb92009-12-08 09:21:05 +00006677TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006678 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006679
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006680 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006681 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006682 Inits, &InitChanged))
6683 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006684
Douglas Gregorb98b1992009-08-11 05:31:07 +00006685 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006686 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006687
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006688 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006689 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006690}
Mike Stump1eb44332009-09-09 15:08:12 +00006691
Douglas Gregorb98b1992009-08-11 05:31:07 +00006692template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006693ExprResult
John McCall454feb92009-12-08 09:21:05 +00006694TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006695 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006696
Douglas Gregor43959a92009-08-20 07:17:43 +00006697 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006698 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006699 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006700 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006701
Douglas Gregor43959a92009-08-20 07:17:43 +00006702 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006703 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006704 bool ExprChanged = false;
6705 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6706 DEnd = E->designators_end();
6707 D != DEnd; ++D) {
6708 if (D->isFieldDesignator()) {
6709 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6710 D->getDotLoc(),
6711 D->getFieldLoc()));
6712 continue;
6713 }
Mike Stump1eb44332009-09-09 15:08:12 +00006714
Douglas Gregorb98b1992009-08-11 05:31:07 +00006715 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006716 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006717 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006718 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006719
6720 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006721 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006722
Douglas Gregorb98b1992009-08-11 05:31:07 +00006723 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6724 ArrayExprs.push_back(Index.release());
6725 continue;
6726 }
Mike Stump1eb44332009-09-09 15:08:12 +00006727
Douglas Gregorb98b1992009-08-11 05:31:07 +00006728 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006729 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006730 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6731 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006732 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006733
John McCall60d7b3a2010-08-24 06:29:42 +00006734 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006735 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006736 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006737
6738 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006739 End.get(),
6740 D->getLBracketLoc(),
6741 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006742
Douglas Gregorb98b1992009-08-11 05:31:07 +00006743 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6744 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006745
Douglas Gregorb98b1992009-08-11 05:31:07 +00006746 ArrayExprs.push_back(Start.release());
6747 ArrayExprs.push_back(End.release());
6748 }
Mike Stump1eb44332009-09-09 15:08:12 +00006749
Douglas Gregorb98b1992009-08-11 05:31:07 +00006750 if (!getDerived().AlwaysRebuild() &&
6751 Init.get() == E->getInit() &&
6752 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006753 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006754
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006755 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006756 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006757 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006758}
Mike Stump1eb44332009-09-09 15:08:12 +00006759
Douglas Gregorb98b1992009-08-11 05:31:07 +00006760template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006761ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006762TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006763 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006764 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006765
Douglas Gregor5557b252009-10-28 00:29:27 +00006766 // FIXME: Will we ever have proper type location here? Will we actually
6767 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006768 QualType T = getDerived().TransformType(E->getType());
6769 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006770 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006771
Douglas Gregorb98b1992009-08-11 05:31:07 +00006772 if (!getDerived().AlwaysRebuild() &&
6773 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006774 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006775
Douglas Gregorb98b1992009-08-11 05:31:07 +00006776 return getDerived().RebuildImplicitValueInitExpr(T);
6777}
Mike Stump1eb44332009-09-09 15:08:12 +00006778
Douglas Gregorb98b1992009-08-11 05:31:07 +00006779template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006780ExprResult
John McCall454feb92009-12-08 09:21:05 +00006781TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006782 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6783 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006784 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006785
John McCall60d7b3a2010-08-24 06:29:42 +00006786 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006787 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006788 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006789
Douglas Gregorb98b1992009-08-11 05:31:07 +00006790 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006791 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006792 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006793 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006794
John McCall9ae2f072010-08-23 23:25:46 +00006795 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006796 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006797}
6798
6799template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006800ExprResult
John McCall454feb92009-12-08 09:21:05 +00006801TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006802 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006803 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00006804 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6805 &ArgumentChanged))
6806 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006807
Douglas Gregorb98b1992009-08-11 05:31:07 +00006808 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006809 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006810 E->getRParenLoc());
6811}
Mike Stump1eb44332009-09-09 15:08:12 +00006812
Douglas Gregorb98b1992009-08-11 05:31:07 +00006813/// \brief Transform an address-of-label expression.
6814///
6815/// By default, the transformation of an address-of-label expression always
6816/// rebuilds the expression, so that the label identifier can be resolved to
6817/// the corresponding label statement by semantic analysis.
6818template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006819ExprResult
John McCall454feb92009-12-08 09:21:05 +00006820TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006821 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6822 E->getLabel());
6823 if (!LD)
6824 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006825
Douglas Gregorb98b1992009-08-11 05:31:07 +00006826 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006827 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006828}
Mike Stump1eb44332009-09-09 15:08:12 +00006829
6830template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006831ExprResult
John McCall454feb92009-12-08 09:21:05 +00006832TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006833 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006834 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006835 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006836 if (SubStmt.isInvalid()) {
6837 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006838 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006839 }
Mike Stump1eb44332009-09-09 15:08:12 +00006840
Douglas Gregorb98b1992009-08-11 05:31:07 +00006841 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006842 SubStmt.get() == E->getSubStmt()) {
6843 // Calling this an 'error' is unintuitive, but it does the right thing.
6844 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006845 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006846 }
Mike Stump1eb44332009-09-09 15:08:12 +00006847
6848 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006849 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006850 E->getRParenLoc());
6851}
Mike Stump1eb44332009-09-09 15:08:12 +00006852
Douglas Gregorb98b1992009-08-11 05:31:07 +00006853template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006854ExprResult
John McCall454feb92009-12-08 09:21:05 +00006855TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006856 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006857 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006858 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006859
John McCall60d7b3a2010-08-24 06:29:42 +00006860 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006861 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006862 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006863
John McCall60d7b3a2010-08-24 06:29:42 +00006864 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006865 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006866 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006867
Douglas Gregorb98b1992009-08-11 05:31:07 +00006868 if (!getDerived().AlwaysRebuild() &&
6869 Cond.get() == E->getCond() &&
6870 LHS.get() == E->getLHS() &&
6871 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006872 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006873
Douglas Gregorb98b1992009-08-11 05:31:07 +00006874 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006875 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006876 E->getRParenLoc());
6877}
Mike Stump1eb44332009-09-09 15:08:12 +00006878
Douglas Gregorb98b1992009-08-11 05:31:07 +00006879template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006880ExprResult
John McCall454feb92009-12-08 09:21:05 +00006881TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006882 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006883}
6884
6885template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006886ExprResult
John McCall454feb92009-12-08 09:21:05 +00006887TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006888 switch (E->getOperator()) {
6889 case OO_New:
6890 case OO_Delete:
6891 case OO_Array_New:
6892 case OO_Array_Delete:
6893 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006894
Douglas Gregor668d6d92009-12-13 20:44:55 +00006895 case OO_Call: {
6896 // This is a call to an object's operator().
6897 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6898
6899 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006900 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006901 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006902 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006903
6904 // FIXME: Poor location information
6905 SourceLocation FakeLParenLoc
6906 = SemaRef.PP.getLocForEndOfToken(
6907 static_cast<Expr *>(Object.get())->getLocEnd());
6908
6909 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006910 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006911 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006912 Args))
6913 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006914
John McCall9ae2f072010-08-23 23:25:46 +00006915 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006916 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006917 E->getLocEnd());
6918 }
6919
6920#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6921 case OO_##Name:
6922#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6923#include "clang/Basic/OperatorKinds.def"
6924 case OO_Subscript:
6925 // Handled below.
6926 break;
6927
6928 case OO_Conditional:
6929 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006930
6931 case OO_None:
6932 case NUM_OVERLOADED_OPERATORS:
6933 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006934 }
6935
John McCall60d7b3a2010-08-24 06:29:42 +00006936 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006937 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006938 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006939
Richard Smithefeeccf2012-10-21 03:28:35 +00006940 ExprResult First;
6941 if (E->getOperator() == OO_Amp)
6942 First = getDerived().TransformAddressOfOperand(E->getArg(0));
6943 else
6944 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006945 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006946 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006947
John McCall60d7b3a2010-08-24 06:29:42 +00006948 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006949 if (E->getNumArgs() == 2) {
6950 Second = getDerived().TransformExpr(E->getArg(1));
6951 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006952 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006953 }
Mike Stump1eb44332009-09-09 15:08:12 +00006954
Douglas Gregorb98b1992009-08-11 05:31:07 +00006955 if (!getDerived().AlwaysRebuild() &&
6956 Callee.get() == E->getCallee() &&
6957 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006958 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006959 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006960
Lang Hamesbe9af122012-10-02 04:45:10 +00006961 Sema::FPContractStateRAII FPContractState(getSema());
6962 getSema().FPFeatures.fp_contract = E->isFPContractable();
6963
Douglas Gregorb98b1992009-08-11 05:31:07 +00006964 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6965 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006966 Callee.get(),
6967 First.get(),
6968 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006969}
Mike Stump1eb44332009-09-09 15:08:12 +00006970
Douglas Gregorb98b1992009-08-11 05:31:07 +00006971template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006972ExprResult
John McCall454feb92009-12-08 09:21:05 +00006973TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6974 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006975}
Mike Stump1eb44332009-09-09 15:08:12 +00006976
Douglas Gregorb98b1992009-08-11 05:31:07 +00006977template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006978ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006979TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6980 // Transform the callee.
6981 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6982 if (Callee.isInvalid())
6983 return ExprError();
6984
6985 // Transform exec config.
6986 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6987 if (EC.isInvalid())
6988 return ExprError();
6989
6990 // Transform arguments.
6991 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006992 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006993 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006994 &ArgChanged))
6995 return ExprError();
6996
6997 if (!getDerived().AlwaysRebuild() &&
6998 Callee.get() == E->getCallee() &&
6999 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007000 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00007001
7002 // FIXME: Wrong source location information for the '('.
7003 SourceLocation FakeLParenLoc
7004 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7005 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007006 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007007 E->getRParenLoc(), EC.get());
7008}
7009
7010template<typename Derived>
7011ExprResult
John McCall454feb92009-12-08 09:21:05 +00007012TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007013 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7014 if (!Type)
7015 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007016
John McCall60d7b3a2010-08-24 06:29:42 +00007017 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007018 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007019 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007020 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007021
Douglas Gregorb98b1992009-08-11 05:31:07 +00007022 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007023 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007024 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007025 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007026
Douglas Gregorb98b1992009-08-11 05:31:07 +00007027 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00007028 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007029 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
7030 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007031 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007032 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007033 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007034 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007035 FakeRAngleLoc,
7036 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007037 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007038 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007039}
Mike Stump1eb44332009-09-09 15:08:12 +00007040
Douglas Gregorb98b1992009-08-11 05:31:07 +00007041template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007042ExprResult
John McCall454feb92009-12-08 09:21:05 +00007043TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7044 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007045}
Mike Stump1eb44332009-09-09 15:08:12 +00007046
7047template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007048ExprResult
John McCall454feb92009-12-08 09:21:05 +00007049TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7050 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007051}
7052
Douglas Gregorb98b1992009-08-11 05:31:07 +00007053template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007054ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007055TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007056 CXXReinterpretCastExpr *E) {
7057 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007058}
Mike Stump1eb44332009-09-09 15:08:12 +00007059
Douglas Gregorb98b1992009-08-11 05:31:07 +00007060template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007061ExprResult
John McCall454feb92009-12-08 09:21:05 +00007062TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7063 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007064}
Mike Stump1eb44332009-09-09 15:08:12 +00007065
Douglas Gregorb98b1992009-08-11 05:31:07 +00007066template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007067ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007068TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007069 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007070 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7071 if (!Type)
7072 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007073
John McCall60d7b3a2010-08-24 06:29:42 +00007074 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007075 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007076 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007077 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007078
Douglas Gregorb98b1992009-08-11 05:31:07 +00007079 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007080 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007081 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007082 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007083
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007084 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007085 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007086 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007087 E->getRParenLoc());
7088}
Mike Stump1eb44332009-09-09 15:08:12 +00007089
Douglas Gregorb98b1992009-08-11 05:31:07 +00007090template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007091ExprResult
John McCall454feb92009-12-08 09:21:05 +00007092TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007093 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007094 TypeSourceInfo *TInfo
7095 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7096 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007097 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007098
Douglas Gregorb98b1992009-08-11 05:31:07 +00007099 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007100 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007101 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007102
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007103 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7104 E->getLocStart(),
7105 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007106 E->getLocEnd());
7107 }
Mike Stump1eb44332009-09-09 15:08:12 +00007108
Eli Friedmanef331b72012-01-20 01:26:23 +00007109 // We don't know whether the subexpression is potentially evaluated until
7110 // after we perform semantic analysis. We speculatively assume it is
7111 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007112 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007113 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7114 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007115
John McCall60d7b3a2010-08-24 06:29:42 +00007116 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007117 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007118 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007119
Douglas Gregorb98b1992009-08-11 05:31:07 +00007120 if (!getDerived().AlwaysRebuild() &&
7121 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007122 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007123
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007124 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7125 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007126 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007127 E->getLocEnd());
7128}
7129
7130template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007131ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007132TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7133 if (E->isTypeOperand()) {
7134 TypeSourceInfo *TInfo
7135 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7136 if (!TInfo)
7137 return ExprError();
7138
7139 if (!getDerived().AlwaysRebuild() &&
7140 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007141 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007142
Douglas Gregor3c52a212011-03-06 17:40:41 +00007143 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007144 E->getLocStart(),
7145 TInfo,
7146 E->getLocEnd());
7147 }
7148
Francois Pichet01b7c302010-09-08 12:20:18 +00007149 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7150
7151 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7152 if (SubExpr.isInvalid())
7153 return ExprError();
7154
7155 if (!getDerived().AlwaysRebuild() &&
7156 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007157 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007158
7159 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7160 E->getLocStart(),
7161 SubExpr.get(),
7162 E->getLocEnd());
7163}
7164
7165template<typename Derived>
7166ExprResult
John McCall454feb92009-12-08 09:21:05 +00007167TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007168 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007169}
Mike Stump1eb44332009-09-09 15:08:12 +00007170
Douglas Gregorb98b1992009-08-11 05:31:07 +00007171template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007172ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007173TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007174 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007175 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007176}
Mike Stump1eb44332009-09-09 15:08:12 +00007177
Douglas Gregorb98b1992009-08-11 05:31:07 +00007178template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007179ExprResult
John McCall454feb92009-12-08 09:21:05 +00007180TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007181 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007182 QualType T;
7183 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7184 T = MD->getThisType(getSema().Context);
7185 else
7186 T = getSema().Context.getPointerType(
7187 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007188
Douglas Gregorec79d872012-02-24 17:41:38 +00007189 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7190 // Make sure that we capture 'this'.
7191 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007192 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007193 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007194
Douglas Gregor828a1972010-01-07 23:12:05 +00007195 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007196}
Mike Stump1eb44332009-09-09 15:08:12 +00007197
Douglas Gregorb98b1992009-08-11 05:31:07 +00007198template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007199ExprResult
John McCall454feb92009-12-08 09:21:05 +00007200TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007201 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007202 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007203 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007204
Douglas Gregorb98b1992009-08-11 05:31:07 +00007205 if (!getDerived().AlwaysRebuild() &&
7206 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007207 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007208
Douglas Gregorbca01b42011-07-06 22:04:06 +00007209 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7210 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007211}
Mike Stump1eb44332009-09-09 15:08:12 +00007212
Douglas Gregorb98b1992009-08-11 05:31:07 +00007213template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007214ExprResult
John McCall454feb92009-12-08 09:21:05 +00007215TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007216 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007217 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7218 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007219 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007220 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007221
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007222 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007223 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007224 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007225
Douglas Gregor036aed12009-12-23 23:03:06 +00007226 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007227}
Mike Stump1eb44332009-09-09 15:08:12 +00007228
Douglas Gregorb98b1992009-08-11 05:31:07 +00007229template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007230ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007231TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7232 CXXScalarValueInitExpr *E) {
7233 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7234 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007235 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007236
Douglas Gregorb98b1992009-08-11 05:31:07 +00007237 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007238 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007239 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007240
Chad Rosier4a9d7952012-08-08 18:46:20 +00007241 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007242 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007243 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007244}
Mike Stump1eb44332009-09-09 15:08:12 +00007245
Douglas Gregorb98b1992009-08-11 05:31:07 +00007246template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007247ExprResult
John McCall454feb92009-12-08 09:21:05 +00007248TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007249 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007250 TypeSourceInfo *AllocTypeInfo
7251 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7252 if (!AllocTypeInfo)
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 size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007256 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007257 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007258 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007259
Douglas Gregorb98b1992009-08-11 05:31:07 +00007260 // Transform the placement arguments (if any).
7261 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007262 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007263 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007264 E->getNumPlacementArgs(), true,
7265 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007266 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007267
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007268 // Transform the initializer (if any).
7269 Expr *OldInit = E->getInitializer();
7270 ExprResult NewInit;
7271 if (OldInit)
7272 NewInit = getDerived().TransformExpr(OldInit);
7273 if (NewInit.isInvalid())
7274 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007275
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007276 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007277 FunctionDecl *OperatorNew = 0;
7278 if (E->getOperatorNew()) {
7279 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007280 getDerived().TransformDecl(E->getLocStart(),
7281 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007282 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007283 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007284 }
7285
7286 FunctionDecl *OperatorDelete = 0;
7287 if (E->getOperatorDelete()) {
7288 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007289 getDerived().TransformDecl(E->getLocStart(),
7290 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007291 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007292 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007293 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007294
Douglas Gregorb98b1992009-08-11 05:31:07 +00007295 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007296 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007297 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007298 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007299 OperatorNew == E->getOperatorNew() &&
7300 OperatorDelete == E->getOperatorDelete() &&
7301 !ArgumentChanged) {
7302 // Mark any declarations we need as referenced.
7303 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007304 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007305 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007306 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007307 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007308
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007309 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007310 QualType ElementType
7311 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7312 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7313 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7314 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007315 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007316 }
7317 }
7318 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007319
John McCall3fa5cae2010-10-26 07:05:15 +00007320 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007321 }
Mike Stump1eb44332009-09-09 15:08:12 +00007322
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007323 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007324 if (!ArraySize.get()) {
7325 // If no array size was specified, but the new expression was
7326 // instantiated with an array type (e.g., "new T" where T is
7327 // instantiated with "int[4]"), extract the outer bound from the
7328 // array type as our array size. We do this with constant and
7329 // dependently-sized array types.
7330 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7331 if (!ArrayT) {
7332 // Do nothing
7333 } else if (const ConstantArrayType *ConsArrayT
7334 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007335 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007336 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007337 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007338 SemaRef.Context.getSizeType(),
7339 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007340 AllocType = ConsArrayT->getElementType();
7341 } else if (const DependentSizedArrayType *DepArrayT
7342 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7343 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007344 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007345 AllocType = DepArrayT->getElementType();
7346 }
7347 }
7348 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007349
Douglas Gregorb98b1992009-08-11 05:31:07 +00007350 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7351 E->isGlobalNew(),
7352 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007353 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007354 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007355 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007356 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007357 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007358 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007359 E->getDirectInitRange(),
7360 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007361}
Mike Stump1eb44332009-09-09 15:08:12 +00007362
Douglas Gregorb98b1992009-08-11 05:31:07 +00007363template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007364ExprResult
John McCall454feb92009-12-08 09:21:05 +00007365TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007366 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007367 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007368 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007369
Douglas Gregor1af74512010-02-26 00:38:10 +00007370 // Transform the delete operator, if known.
7371 FunctionDecl *OperatorDelete = 0;
7372 if (E->getOperatorDelete()) {
7373 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007374 getDerived().TransformDecl(E->getLocStart(),
7375 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007376 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007377 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007378 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007379
Douglas Gregorb98b1992009-08-11 05:31:07 +00007380 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007381 Operand.get() == E->getArgument() &&
7382 OperatorDelete == E->getOperatorDelete()) {
7383 // Mark any declarations we need as referenced.
7384 // FIXME: instantiation-specific.
7385 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007386 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007387
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007388 if (!E->getArgument()->isTypeDependent()) {
7389 QualType Destroyed = SemaRef.Context.getBaseElementType(
7390 E->getDestroyedType());
7391 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7392 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007393 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007394 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007395 }
7396 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007397
John McCall3fa5cae2010-10-26 07:05:15 +00007398 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007399 }
Mike Stump1eb44332009-09-09 15:08:12 +00007400
Douglas Gregorb98b1992009-08-11 05:31:07 +00007401 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7402 E->isGlobalDelete(),
7403 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007404 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007405}
Mike Stump1eb44332009-09-09 15:08:12 +00007406
Douglas Gregorb98b1992009-08-11 05:31:07 +00007407template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007408ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007409TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007410 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007411 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007412 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007413 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007414
John McCallb3d87482010-08-24 05:47:05 +00007415 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007416 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007417 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007418 E->getOperatorLoc(),
7419 E->isArrow()? tok::arrow : tok::period,
7420 ObjectTypePtr,
7421 MayBePseudoDestructor);
7422 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007423 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007424
John McCallb3d87482010-08-24 05:47:05 +00007425 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007426 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7427 if (QualifierLoc) {
7428 QualifierLoc
7429 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7430 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007431 return ExprError();
7432 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007433 CXXScopeSpec SS;
7434 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007435
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007436 PseudoDestructorTypeStorage Destroyed;
7437 if (E->getDestroyedTypeInfo()) {
7438 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007439 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007440 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007441 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007442 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007443 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007444 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007445 // We aren't likely to be able to resolve the identifier down to a type
7446 // now anyway, so just retain the identifier.
7447 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7448 E->getDestroyedTypeLoc());
7449 } else {
7450 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007451 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007452 *E->getDestroyedTypeIdentifier(),
7453 E->getDestroyedTypeLoc(),
7454 /*Scope=*/0,
7455 SS, ObjectTypePtr,
7456 false);
7457 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007458 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007459
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007460 Destroyed
7461 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7462 E->getDestroyedTypeLoc());
7463 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007464
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007465 TypeSourceInfo *ScopeTypeInfo = 0;
7466 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007467 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007468 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007469 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007470 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007471
John McCall9ae2f072010-08-23 23:25:46 +00007472 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007473 E->getOperatorLoc(),
7474 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007475 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007476 ScopeTypeInfo,
7477 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007478 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007479 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007480}
Mike Stump1eb44332009-09-09 15:08:12 +00007481
Douglas Gregora71d8192009-09-04 17:36:40 +00007482template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007483ExprResult
John McCallba135432009-11-21 08:51:07 +00007484TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007485 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007486 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7487 Sema::LookupOrdinaryName);
7488
7489 // Transform all the decls.
7490 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7491 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007492 NamedDecl *InstD = static_cast<NamedDecl*>(
7493 getDerived().TransformDecl(Old->getNameLoc(),
7494 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007495 if (!InstD) {
7496 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7497 // This can happen because of dependent hiding.
7498 if (isa<UsingShadowDecl>(*I))
7499 continue;
7500 else
John McCallf312b1e2010-08-26 23:41:50 +00007501 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007502 }
John McCallf7a1a742009-11-24 19:00:30 +00007503
7504 // Expand using declarations.
7505 if (isa<UsingDecl>(InstD)) {
7506 UsingDecl *UD = cast<UsingDecl>(InstD);
7507 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7508 E = UD->shadow_end(); I != E; ++I)
7509 R.addDecl(*I);
7510 continue;
7511 }
7512
7513 R.addDecl(InstD);
7514 }
7515
7516 // Resolve a kind, but don't do any further analysis. If it's
7517 // ambiguous, the callee needs to deal with it.
7518 R.resolveKind();
7519
7520 // Rebuild the nested-name qualifier, if present.
7521 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007522 if (Old->getQualifierLoc()) {
7523 NestedNameSpecifierLoc QualifierLoc
7524 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7525 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007526 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007527
Douglas Gregor4c9be892011-02-28 20:01:57 +00007528 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007529 }
7530
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007531 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007532 CXXRecordDecl *NamingClass
7533 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7534 Old->getNameLoc(),
7535 Old->getNamingClass()));
7536 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007537 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007538
Douglas Gregor66c45152010-04-27 16:10:10 +00007539 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007540 }
7541
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007542 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7543
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007544 // If we have neither explicit template arguments, nor the template keyword,
7545 // it's a normal declaration name.
7546 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007547 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7548
7549 // If we have template arguments, rebuild them, then rebuild the
7550 // templateid expression.
7551 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007552 if (Old->hasExplicitTemplateArgs() &&
7553 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007554 Old->getNumTemplateArgs(),
7555 TransArgs))
7556 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007557
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007558 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007559 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007560}
Mike Stump1eb44332009-09-09 15:08:12 +00007561
Douglas Gregorb98b1992009-08-11 05:31:07 +00007562template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007563ExprResult
John McCall454feb92009-12-08 09:21:05 +00007564TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007565 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7566 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007567 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007568
Douglas Gregorb98b1992009-08-11 05:31:07 +00007569 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007570 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007571 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007572
Mike Stump1eb44332009-09-09 15:08:12 +00007573 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007574 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007575 T,
7576 E->getLocEnd());
7577}
Mike Stump1eb44332009-09-09 15:08:12 +00007578
Douglas Gregorb98b1992009-08-11 05:31:07 +00007579template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007580ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007581TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7582 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7583 if (!LhsT)
7584 return ExprError();
7585
7586 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7587 if (!RhsT)
7588 return ExprError();
7589
7590 if (!getDerived().AlwaysRebuild() &&
7591 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7592 return SemaRef.Owned(E);
7593
7594 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7595 E->getLocStart(),
7596 LhsT, RhsT,
7597 E->getLocEnd());
7598}
7599
7600template<typename Derived>
7601ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007602TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7603 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007604 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007605 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7606 TypeSourceInfo *From = E->getArg(I);
7607 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007608 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007609 TypeLocBuilder TLB;
7610 TLB.reserve(FromTL.getFullDataSize());
7611 QualType To = getDerived().TransformType(TLB, FromTL);
7612 if (To.isNull())
7613 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007614
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007615 if (To == From->getType())
7616 Args.push_back(From);
7617 else {
7618 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7619 ArgChanged = true;
7620 }
7621 continue;
7622 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007623
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007624 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007625
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007626 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007627 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007628 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7629 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7630 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007631
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007632 // Determine whether the set of unexpanded parameter packs can and should
7633 // be expanded.
7634 bool Expand = true;
7635 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007636 Optional<unsigned> OrigNumExpansions =
7637 ExpansionTL.getTypePtr()->getNumExpansions();
7638 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007639 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7640 PatternTL.getSourceRange(),
7641 Unexpanded,
7642 Expand, RetainExpansion,
7643 NumExpansions))
7644 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007645
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007646 if (!Expand) {
7647 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007648 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007649 // expansion.
7650 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007651
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007652 TypeLocBuilder TLB;
7653 TLB.reserve(From->getTypeLoc().getFullDataSize());
7654
7655 QualType To = getDerived().TransformType(TLB, PatternTL);
7656 if (To.isNull())
7657 return ExprError();
7658
Chad Rosier4a9d7952012-08-08 18:46:20 +00007659 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007660 PatternTL.getSourceRange(),
7661 ExpansionTL.getEllipsisLoc(),
7662 NumExpansions);
7663 if (To.isNull())
7664 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007665
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007666 PackExpansionTypeLoc ToExpansionTL
7667 = TLB.push<PackExpansionTypeLoc>(To);
7668 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7669 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7670 continue;
7671 }
7672
7673 // Expand the pack expansion by substituting for each argument in the
7674 // pack(s).
7675 for (unsigned I = 0; I != *NumExpansions; ++I) {
7676 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7677 TypeLocBuilder TLB;
7678 TLB.reserve(PatternTL.getFullDataSize());
7679 QualType To = getDerived().TransformType(TLB, PatternTL);
7680 if (To.isNull())
7681 return ExprError();
7682
7683 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7684 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007685
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007686 if (!RetainExpansion)
7687 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007688
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007689 // If we're supposed to retain a pack expansion, do so by temporarily
7690 // forgetting the partially-substituted parameter pack.
7691 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7692
7693 TypeLocBuilder TLB;
7694 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007695
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007696 QualType To = getDerived().TransformType(TLB, PatternTL);
7697 if (To.isNull())
7698 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007699
7700 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007701 PatternTL.getSourceRange(),
7702 ExpansionTL.getEllipsisLoc(),
7703 NumExpansions);
7704 if (To.isNull())
7705 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007706
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007707 PackExpansionTypeLoc ToExpansionTL
7708 = TLB.push<PackExpansionTypeLoc>(To);
7709 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7710 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7711 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007712
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007713 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7714 return SemaRef.Owned(E);
7715
7716 return getDerived().RebuildTypeTrait(E->getTrait(),
7717 E->getLocStart(),
7718 Args,
7719 E->getLocEnd());
7720}
7721
7722template<typename Derived>
7723ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007724TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7725 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7726 if (!T)
7727 return ExprError();
7728
7729 if (!getDerived().AlwaysRebuild() &&
7730 T == E->getQueriedTypeSourceInfo())
7731 return SemaRef.Owned(E);
7732
7733 ExprResult SubExpr;
7734 {
7735 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7736 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7737 if (SubExpr.isInvalid())
7738 return ExprError();
7739
7740 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7741 return SemaRef.Owned(E);
7742 }
7743
7744 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7745 E->getLocStart(),
7746 T,
7747 SubExpr.get(),
7748 E->getLocEnd());
7749}
7750
7751template<typename Derived>
7752ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007753TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7754 ExprResult SubExpr;
7755 {
7756 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7757 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7758 if (SubExpr.isInvalid())
7759 return ExprError();
7760
7761 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7762 return SemaRef.Owned(E);
7763 }
7764
7765 return getDerived().RebuildExpressionTrait(
7766 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7767}
7768
7769template<typename Derived>
7770ExprResult
John McCall865d4472009-11-19 22:55:06 +00007771TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007772 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00007773 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
7774}
7775
7776template<typename Derived>
7777ExprResult
7778TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
7779 DependentScopeDeclRefExpr *E,
7780 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007781 NestedNameSpecifierLoc QualifierLoc
7782 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7783 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007784 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007785 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007786
John McCall43fed0d2010-11-12 08:19:04 +00007787 // TODO: If this is a conversion-function-id, verify that the
7788 // destination type name (if present) resolves the same way after
7789 // instantiation as it did in the local scope.
7790
Abramo Bagnara25777432010-08-11 22:01:17 +00007791 DeclarationNameInfo NameInfo
7792 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7793 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007794 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007795
John McCallf7a1a742009-11-24 19:00:30 +00007796 if (!E->hasExplicitTemplateArgs()) {
7797 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007798 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007799 // Note: it is sufficient to compare the Name component of NameInfo:
7800 // if name has not changed, DNLoc has not changed either.
7801 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007802 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007803
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007804 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007805 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007806 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007807 /*TemplateArgs*/ 0,
7808 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007809 }
John McCalld5532b62009-11-23 01:53:49 +00007810
7811 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007812 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7813 E->getNumTemplateArgs(),
7814 TransArgs))
7815 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007816
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007817 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007818 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007819 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007820 &TransArgs,
7821 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007822}
7823
7824template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007825ExprResult
John McCall454feb92009-12-08 09:21:05 +00007826TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00007827 // CXXConstructExprs other than for list-initialization and
7828 // CXXTemporaryObjectExpr are always implicit, so when we have
7829 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00007830 if ((E->getNumArgs() == 1 ||
7831 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00007832 (!getDerived().DropCallArgument(E->getArg(0))) &&
7833 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00007834 return getDerived().TransformExpr(E->getArg(0));
7835
Douglas Gregorb98b1992009-08-11 05:31:07 +00007836 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7837
7838 QualType T = getDerived().TransformType(E->getType());
7839 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007840 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007841
7842 CXXConstructorDecl *Constructor
7843 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007844 getDerived().TransformDecl(E->getLocStart(),
7845 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007846 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007847 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007848
Douglas Gregorb98b1992009-08-11 05:31:07 +00007849 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007850 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007851 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007852 &ArgumentChanged))
7853 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007854
Douglas Gregorb98b1992009-08-11 05:31:07 +00007855 if (!getDerived().AlwaysRebuild() &&
7856 T == E->getType() &&
7857 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007858 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007859 // Mark the constructor as referenced.
7860 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007861 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007862 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007863 }
Mike Stump1eb44332009-09-09 15:08:12 +00007864
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007865 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7866 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007867 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007868 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00007869 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007870 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007871 E->getConstructionKind(),
7872 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007873}
Mike Stump1eb44332009-09-09 15:08:12 +00007874
Douglas Gregorb98b1992009-08-11 05:31:07 +00007875/// \brief Transform a C++ temporary-binding expression.
7876///
Douglas Gregor51326552009-12-24 18:51:59 +00007877/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7878/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007879template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007880ExprResult
John McCall454feb92009-12-08 09:21:05 +00007881TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007882 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007883}
Mike Stump1eb44332009-09-09 15:08:12 +00007884
John McCall4765fa02010-12-06 08:20:24 +00007885/// \brief Transform a C++ expression that contains cleanups that should
7886/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007887///
John McCall4765fa02010-12-06 08:20:24 +00007888/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007889/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007890template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007891ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007892TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007893 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007894}
Mike Stump1eb44332009-09-09 15:08:12 +00007895
Douglas Gregorb98b1992009-08-11 05:31:07 +00007896template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007897ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007898TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007899 CXXTemporaryObjectExpr *E) {
7900 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7901 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007902 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007903
Douglas Gregorb98b1992009-08-11 05:31:07 +00007904 CXXConstructorDecl *Constructor
7905 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00007906 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007907 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007908 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007909 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007910
Douglas Gregorb98b1992009-08-11 05:31:07 +00007911 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007912 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007913 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007914 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007915 &ArgumentChanged))
7916 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007917
Douglas Gregorb98b1992009-08-11 05:31:07 +00007918 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007919 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007920 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007921 !ArgumentChanged) {
7922 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007923 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007924 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007925 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007926
Richard Smithc83c2302012-12-19 01:39:02 +00007927 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00007928 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7929 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007930 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007931 E->getLocEnd());
7932}
Mike Stump1eb44332009-09-09 15:08:12 +00007933
Douglas Gregorb98b1992009-08-11 05:31:07 +00007934template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007935ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007936TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007937 // Transform the type of the lambda parameters and start the definition of
7938 // the lambda itself.
7939 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00007940 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00007941 if (!MethodTy)
7942 return ExprError();
7943
Eli Friedman8da8a662012-09-19 01:18:11 +00007944 // Create the local class that will describe the lambda.
7945 CXXRecordDecl *Class
7946 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7947 MethodTy,
7948 /*KnownDependent=*/false);
7949 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7950
Douglas Gregorc6889e72012-02-14 22:28:59 +00007951 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007952 SmallVector<QualType, 4> ParamTypes;
7953 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00007954 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7955 E->getCallOperator()->param_begin(),
7956 E->getCallOperator()->param_size(),
7957 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00007958 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00007959
Douglas Gregordfca6f52012-02-13 22:00:16 +00007960 // Build the call operator.
7961 CXXMethodDecl *CallOperator
7962 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007963 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007964 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007965 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007966 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00007967
Richard Smith612409e2012-07-25 03:56:55 +00007968 return getDerived().TransformLambdaScope(E, CallOperator);
7969}
7970
7971template<typename Derived>
7972ExprResult
7973TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
7974 CXXMethodDecl *CallOperator) {
Douglas Gregord5387e82012-02-14 00:00:48 +00007975 // Introduce the context of the call operator.
7976 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7977
Douglas Gregordfca6f52012-02-13 22:00:16 +00007978 // Enter the scope of the lambda.
7979 sema::LambdaScopeInfo *LSI
7980 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7981 E->getCaptureDefault(),
7982 E->hasExplicitParameters(),
7983 E->hasExplicitResultType(),
7984 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007985
Douglas Gregordfca6f52012-02-13 22:00:16 +00007986 // Transform captures.
Richard Smith612409e2012-07-25 03:56:55 +00007987 bool Invalid = false;
Douglas Gregordfca6f52012-02-13 22:00:16 +00007988 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007989 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007990 CEnd = E->capture_end();
7991 C != CEnd; ++C) {
7992 // When we hit the first implicit capture, tell Sema that we've finished
7993 // the list of explicit captures.
7994 if (!FinishedExplicitCaptures && C->isImplicit()) {
7995 getSema().finishLambdaExplicitCaptures(LSI);
7996 FinishedExplicitCaptures = true;
7997 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007998
Douglas Gregordfca6f52012-02-13 22:00:16 +00007999 // Capturing 'this' is trivial.
8000 if (C->capturesThis()) {
8001 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8002 continue;
8003 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008004
Douglas Gregora7365242012-02-14 19:27:52 +00008005 // Determine the capture kind for Sema.
8006 Sema::TryCaptureKind Kind
8007 = C->isImplicit()? Sema::TryCapture_Implicit
8008 : C->getCaptureKind() == LCK_ByCopy
8009 ? Sema::TryCapture_ExplicitByVal
8010 : Sema::TryCapture_ExplicitByRef;
8011 SourceLocation EllipsisLoc;
8012 if (C->isPackExpansion()) {
8013 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8014 bool ShouldExpand = false;
8015 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008016 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008017 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8018 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008019 Unexpanded,
8020 ShouldExpand, RetainExpansion,
8021 NumExpansions))
8022 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008023
Douglas Gregora7365242012-02-14 19:27:52 +00008024 if (ShouldExpand) {
8025 // The transform has determined that we should perform an expansion;
8026 // transform and capture each of the arguments.
8027 // expansion of the pattern. Do so.
8028 VarDecl *Pack = C->getCapturedVar();
8029 for (unsigned I = 0; I != *NumExpansions; ++I) {
8030 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8031 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008032 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008033 Pack));
8034 if (!CapturedVar) {
8035 Invalid = true;
8036 continue;
8037 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008038
Douglas Gregora7365242012-02-14 19:27:52 +00008039 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008040 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8041 }
Douglas Gregora7365242012-02-14 19:27:52 +00008042 continue;
8043 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008044
Douglas Gregora7365242012-02-14 19:27:52 +00008045 EllipsisLoc = C->getEllipsisLoc();
8046 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008047
Douglas Gregordfca6f52012-02-13 22:00:16 +00008048 // Transform the captured variable.
8049 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008050 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008051 C->getCapturedVar()));
8052 if (!CapturedVar) {
8053 Invalid = true;
8054 continue;
8055 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008056
Douglas Gregordfca6f52012-02-13 22:00:16 +00008057 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008058 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008059 }
8060 if (!FinishedExplicitCaptures)
8061 getSema().finishLambdaExplicitCaptures(LSI);
8062
Douglas Gregordfca6f52012-02-13 22:00:16 +00008063
8064 // Enter a new evaluation context to insulate the lambda from any
8065 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008066 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008067
8068 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008069 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008070 /*IsInstantiation=*/true);
8071 return ExprError();
8072 }
8073
8074 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008075 StmtResult Body = getDerived().TransformStmt(E->getBody());
8076 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008077 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008078 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008079 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008080 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008081
Chad Rosier4a9d7952012-08-08 18:46:20 +00008082 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008083 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008084}
8085
8086template<typename Derived>
8087ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008088TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008089 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008090 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8091 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008092 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008093
Douglas Gregorb98b1992009-08-11 05:31:07 +00008094 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008095 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008096 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008097 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008098 &ArgumentChanged))
8099 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008100
Douglas Gregorb98b1992009-08-11 05:31:07 +00008101 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008102 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008103 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008104 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008105
Douglas Gregorb98b1992009-08-11 05:31:07 +00008106 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008107 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008108 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008109 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008110 E->getRParenLoc());
8111}
Mike Stump1eb44332009-09-09 15:08:12 +00008112
Douglas Gregorb98b1992009-08-11 05:31:07 +00008113template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008114ExprResult
John McCall865d4472009-11-19 22:55:06 +00008115TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008116 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008117 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008118 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008119 Expr *OldBase;
8120 QualType BaseType;
8121 QualType ObjectType;
8122 if (!E->isImplicitAccess()) {
8123 OldBase = E->getBase();
8124 Base = getDerived().TransformExpr(OldBase);
8125 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008126 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008127
John McCallaa81e162009-12-01 22:10:20 +00008128 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008129 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008130 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008131 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008132 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008133 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008134 ObjectTy,
8135 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008136 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008137 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008138
John McCallb3d87482010-08-24 05:47:05 +00008139 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008140 BaseType = ((Expr*) Base.get())->getType();
8141 } else {
8142 OldBase = 0;
8143 BaseType = getDerived().TransformType(E->getBaseType());
8144 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8145 }
Mike Stump1eb44332009-09-09 15:08:12 +00008146
Douglas Gregor6cd21982009-10-20 05:58:46 +00008147 // Transform the first part of the nested-name-specifier that qualifies
8148 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008149 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008150 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008151 E->getFirstQualifierFoundInScope(),
8152 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008153
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008154 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008155 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008156 QualifierLoc
8157 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8158 ObjectType,
8159 FirstQualifierInScope);
8160 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008161 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008162 }
Mike Stump1eb44332009-09-09 15:08:12 +00008163
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008164 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8165
John McCall43fed0d2010-11-12 08:19:04 +00008166 // TODO: If this is a conversion-function-id, verify that the
8167 // destination type name (if present) resolves the same way after
8168 // instantiation as it did in the local scope.
8169
Abramo Bagnara25777432010-08-11 22:01:17 +00008170 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008171 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008172 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008173 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008174
John McCallaa81e162009-12-01 22:10:20 +00008175 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008176 // This is a reference to a member without an explicitly-specified
8177 // template argument list. Optimize for this common case.
8178 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008179 Base.get() == OldBase &&
8180 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008181 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008182 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008183 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008184 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008185
John McCall9ae2f072010-08-23 23:25:46 +00008186 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008187 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008188 E->isArrow(),
8189 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008190 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008191 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008192 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008193 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008194 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008195 }
8196
John McCalld5532b62009-11-23 01:53:49 +00008197 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008198 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8199 E->getNumTemplateArgs(),
8200 TransArgs))
8201 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008202
John McCall9ae2f072010-08-23 23:25:46 +00008203 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008204 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008205 E->isArrow(),
8206 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008207 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008208 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008209 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008210 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008211 &TransArgs);
8212}
8213
8214template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008215ExprResult
John McCall454feb92009-12-08 09:21:05 +00008216TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008217 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008218 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008219 QualType BaseType;
8220 if (!Old->isImplicitAccess()) {
8221 Base = getDerived().TransformExpr(Old->getBase());
8222 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008223 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008224 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8225 Old->isArrow());
8226 if (Base.isInvalid())
8227 return ExprError();
8228 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008229 } else {
8230 BaseType = getDerived().TransformType(Old->getBaseType());
8231 }
John McCall129e2df2009-11-30 22:42:35 +00008232
Douglas Gregor4c9be892011-02-28 20:01:57 +00008233 NestedNameSpecifierLoc QualifierLoc;
8234 if (Old->getQualifierLoc()) {
8235 QualifierLoc
8236 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8237 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008238 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008239 }
8240
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008241 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8242
Abramo Bagnara25777432010-08-11 22:01:17 +00008243 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008244 Sema::LookupOrdinaryName);
8245
8246 // Transform all the decls.
8247 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8248 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008249 NamedDecl *InstD = static_cast<NamedDecl*>(
8250 getDerived().TransformDecl(Old->getMemberLoc(),
8251 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008252 if (!InstD) {
8253 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8254 // This can happen because of dependent hiding.
8255 if (isa<UsingShadowDecl>(*I))
8256 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008257 else {
8258 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008259 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008260 }
John McCall9f54ad42009-12-10 09:41:52 +00008261 }
John McCall129e2df2009-11-30 22:42:35 +00008262
8263 // Expand using declarations.
8264 if (isa<UsingDecl>(InstD)) {
8265 UsingDecl *UD = cast<UsingDecl>(InstD);
8266 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8267 E = UD->shadow_end(); I != E; ++I)
8268 R.addDecl(*I);
8269 continue;
8270 }
8271
8272 R.addDecl(InstD);
8273 }
8274
8275 R.resolveKind();
8276
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008277 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008278 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008279 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008280 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008281 Old->getMemberLoc(),
8282 Old->getNamingClass()));
8283 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008284 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008285
Douglas Gregor66c45152010-04-27 16:10:10 +00008286 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008287 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008288
John McCall129e2df2009-11-30 22:42:35 +00008289 TemplateArgumentListInfo TransArgs;
8290 if (Old->hasExplicitTemplateArgs()) {
8291 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8292 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008293 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8294 Old->getNumTemplateArgs(),
8295 TransArgs))
8296 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008297 }
John McCallc2233c52010-01-15 08:34:02 +00008298
8299 // FIXME: to do this check properly, we will need to preserve the
8300 // first-qualifier-in-scope here, just in case we had a dependent
8301 // base (and therefore couldn't do the check) and a
8302 // nested-name-qualifier (and therefore could do the lookup).
8303 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008304
John McCall9ae2f072010-08-23 23:25:46 +00008305 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008306 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008307 Old->getOperatorLoc(),
8308 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008309 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008310 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008311 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008312 R,
8313 (Old->hasExplicitTemplateArgs()
8314 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008315}
8316
8317template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008318ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008319TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008320 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008321 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8322 if (SubExpr.isInvalid())
8323 return ExprError();
8324
8325 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008326 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008327
8328 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8329}
8330
8331template<typename Derived>
8332ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008333TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008334 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8335 if (Pattern.isInvalid())
8336 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008337
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008338 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8339 return SemaRef.Owned(E);
8340
Douglas Gregor67fd1252011-01-14 21:20:45 +00008341 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8342 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008343}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008344
8345template<typename Derived>
8346ExprResult
8347TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8348 // If E is not value-dependent, then nothing will change when we transform it.
8349 // Note: This is an instantiation-centric view.
8350 if (!E->isValueDependent())
8351 return SemaRef.Owned(E);
8352
8353 // Note: None of the implementations of TryExpandParameterPacks can ever
8354 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008355 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008356 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8357 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008358 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008359 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008360 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008361 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008362 ShouldExpand, RetainExpansion,
8363 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008364 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008365
Douglas Gregor089e8932011-10-10 18:59:29 +00008366 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008367 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008368
Douglas Gregor089e8932011-10-10 18:59:29 +00008369 NamedDecl *Pack = E->getPack();
8370 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008371 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008372 Pack));
8373 if (!Pack)
8374 return ExprError();
8375 }
8376
Chad Rosier4a9d7952012-08-08 18:46:20 +00008377
Douglas Gregoree8aff02011-01-04 17:33:58 +00008378 // We now know the length of the parameter pack, so build a new expression
8379 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008380 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8381 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008382 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008383}
8384
Douglas Gregorbe230c32011-01-03 17:17:50 +00008385template<typename Derived>
8386ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008387TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8388 SubstNonTypeTemplateParmPackExpr *E) {
8389 // Default behavior is to do nothing with this transformation.
8390 return SemaRef.Owned(E);
8391}
8392
8393template<typename Derived>
8394ExprResult
John McCall91a57552011-07-15 05:09:51 +00008395TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8396 SubstNonTypeTemplateParmExpr *E) {
8397 // Default behavior is to do nothing with this transformation.
8398 return SemaRef.Owned(E);
8399}
8400
8401template<typename Derived>
8402ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008403TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8404 // Default behavior is to do nothing with this transformation.
8405 return SemaRef.Owned(E);
8406}
8407
8408template<typename Derived>
8409ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008410TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8411 MaterializeTemporaryExpr *E) {
8412 return getDerived().TransformExpr(E->GetTemporaryExpr());
8413}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008414
Douglas Gregor03e80032011-06-21 17:03:29 +00008415template<typename Derived>
8416ExprResult
John McCall454feb92009-12-08 09:21:05 +00008417TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008418 return SemaRef.MaybeBindToTemporary(E);
8419}
8420
8421template<typename Derived>
8422ExprResult
8423TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008424 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008425}
8426
8427template<typename Derived>
8428ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008429TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8430 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8431 if (SubExpr.isInvalid())
8432 return ExprError();
8433
8434 if (!getDerived().AlwaysRebuild() &&
8435 SubExpr.get() == E->getSubExpr())
8436 return SemaRef.Owned(E);
8437
8438 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008439}
8440
8441template<typename Derived>
8442ExprResult
8443TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8444 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008445 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008446 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008447 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008448 /*IsCall=*/false, Elements, &ArgChanged))
8449 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008450
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008451 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8452 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008453
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008454 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8455 Elements.data(),
8456 Elements.size());
8457}
8458
8459template<typename Derived>
8460ExprResult
8461TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008462 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008463 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008464 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008465 bool ArgChanged = false;
8466 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8467 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008468
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008469 if (OrigElement.isPackExpansion()) {
8470 // This key/value element is a pack expansion.
8471 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8472 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8473 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8474 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8475
8476 // Determine whether the set of unexpanded parameter packs can
8477 // and should be expanded.
8478 bool Expand = true;
8479 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008480 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8481 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008482 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8483 OrigElement.Value->getLocEnd());
8484 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8485 PatternRange,
8486 Unexpanded,
8487 Expand, RetainExpansion,
8488 NumExpansions))
8489 return ExprError();
8490
8491 if (!Expand) {
8492 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008493 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008494 // expansion.
8495 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8496 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8497 if (Key.isInvalid())
8498 return ExprError();
8499
8500 if (Key.get() != OrigElement.Key)
8501 ArgChanged = true;
8502
8503 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8504 if (Value.isInvalid())
8505 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008506
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008507 if (Value.get() != OrigElement.Value)
8508 ArgChanged = true;
8509
Chad Rosier4a9d7952012-08-08 18:46:20 +00008510 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008511 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8512 };
8513 Elements.push_back(Expansion);
8514 continue;
8515 }
8516
8517 // Record right away that the argument was changed. This needs
8518 // to happen even if the array expands to nothing.
8519 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008520
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008521 // The transform has determined that we should perform an elementwise
8522 // expansion of the pattern. Do so.
8523 for (unsigned I = 0; I != *NumExpansions; ++I) {
8524 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8525 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8526 if (Key.isInvalid())
8527 return ExprError();
8528
8529 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8530 if (Value.isInvalid())
8531 return ExprError();
8532
Chad Rosier4a9d7952012-08-08 18:46:20 +00008533 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008534 Key.get(), Value.get(), SourceLocation(), NumExpansions
8535 };
8536
8537 // If any unexpanded parameter packs remain, we still have a
8538 // pack expansion.
8539 if (Key.get()->containsUnexpandedParameterPack() ||
8540 Value.get()->containsUnexpandedParameterPack())
8541 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008542
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008543 Elements.push_back(Element);
8544 }
8545
8546 // We've finished with this pack expansion.
8547 continue;
8548 }
8549
8550 // Transform and check key.
8551 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8552 if (Key.isInvalid())
8553 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008554
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008555 if (Key.get() != OrigElement.Key)
8556 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008557
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008558 // Transform and check value.
8559 ExprResult Value
8560 = getDerived().TransformExpr(OrigElement.Value);
8561 if (Value.isInvalid())
8562 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008563
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008564 if (Value.get() != OrigElement.Value)
8565 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008566
8567 ObjCDictionaryElement Element = {
David Blaikiedc84cd52013-02-20 22:23:23 +00008568 Key.get(), Value.get(), SourceLocation(), Optional<unsigned>()
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008569 };
8570 Elements.push_back(Element);
8571 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008572
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008573 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8574 return SemaRef.MaybeBindToTemporary(E);
8575
8576 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8577 Elements.data(),
8578 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008579}
8580
Mike Stump1eb44332009-09-09 15:08:12 +00008581template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008582ExprResult
John McCall454feb92009-12-08 09:21:05 +00008583TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008584 TypeSourceInfo *EncodedTypeInfo
8585 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8586 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008587 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008588
Douglas Gregorb98b1992009-08-11 05:31:07 +00008589 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008590 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008591 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008592
8593 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008594 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008595 E->getRParenLoc());
8596}
Mike Stump1eb44332009-09-09 15:08:12 +00008597
Douglas Gregorb98b1992009-08-11 05:31:07 +00008598template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008599ExprResult TreeTransform<Derived>::
8600TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8601 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8602 if (result.isInvalid()) return ExprError();
8603 Expr *subExpr = result.take();
8604
8605 if (!getDerived().AlwaysRebuild() &&
8606 subExpr == E->getSubExpr())
8607 return SemaRef.Owned(E);
8608
8609 return SemaRef.Owned(new(SemaRef.Context)
8610 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8611}
8612
8613template<typename Derived>
8614ExprResult TreeTransform<Derived>::
8615TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008616 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008617 = getDerived().TransformType(E->getTypeInfoAsWritten());
8618 if (!TSInfo)
8619 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008620
John McCallf85e1932011-06-15 23:02:42 +00008621 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008622 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008623 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008624
John McCallf85e1932011-06-15 23:02:42 +00008625 if (!getDerived().AlwaysRebuild() &&
8626 TSInfo == E->getTypeInfoAsWritten() &&
8627 Result.get() == E->getSubExpr())
8628 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008629
John McCallf85e1932011-06-15 23:02:42 +00008630 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008631 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008632 Result.get());
8633}
8634
8635template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008636ExprResult
John McCall454feb92009-12-08 09:21:05 +00008637TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008638 // Transform arguments.
8639 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008640 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008641 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008642 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008643 &ArgChanged))
8644 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008645
Douglas Gregor92e986e2010-04-22 16:44:27 +00008646 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8647 // Class message: transform the receiver type.
8648 TypeSourceInfo *ReceiverTypeInfo
8649 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8650 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008651 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008652
Douglas Gregor92e986e2010-04-22 16:44:27 +00008653 // If nothing changed, just retain the existing message send.
8654 if (!getDerived().AlwaysRebuild() &&
8655 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008656 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008657
8658 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008659 SmallVector<SourceLocation, 16> SelLocs;
8660 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008661 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8662 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008663 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008664 E->getMethodDecl(),
8665 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008666 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008667 E->getRightLoc());
8668 }
8669
8670 // Instance message: transform the receiver
8671 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8672 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008673 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008674 = getDerived().TransformExpr(E->getInstanceReceiver());
8675 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008676 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008677
8678 // If nothing changed, just retain the existing message send.
8679 if (!getDerived().AlwaysRebuild() &&
8680 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008681 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008682
Douglas Gregor92e986e2010-04-22 16:44:27 +00008683 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008684 SmallVector<SourceLocation, 16> SelLocs;
8685 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008686 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008687 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008688 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008689 E->getMethodDecl(),
8690 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008691 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008692 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008693}
8694
Mike Stump1eb44332009-09-09 15:08:12 +00008695template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008696ExprResult
John McCall454feb92009-12-08 09:21:05 +00008697TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008698 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008699}
8700
Mike Stump1eb44332009-09-09 15:08:12 +00008701template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008702ExprResult
John McCall454feb92009-12-08 09:21:05 +00008703TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008704 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008705}
8706
Mike Stump1eb44332009-09-09 15:08:12 +00008707template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008708ExprResult
John McCall454feb92009-12-08 09:21:05 +00008709TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008710 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008711 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008712 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008713 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008714
8715 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008716
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008717 // If nothing changed, just retain the existing expression.
8718 if (!getDerived().AlwaysRebuild() &&
8719 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008720 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008721
John McCall9ae2f072010-08-23 23:25:46 +00008722 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008723 E->getLocation(),
8724 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008725}
8726
Mike Stump1eb44332009-09-09 15:08:12 +00008727template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008728ExprResult
John McCall454feb92009-12-08 09:21:05 +00008729TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008730 // 'super' and types never change. Property never changes. Just
8731 // retain the existing expression.
8732 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008733 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008734
Douglas Gregore3303542010-04-26 20:47:02 +00008735 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008736 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008737 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008738 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008739
Douglas Gregore3303542010-04-26 20:47:02 +00008740 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008741
Douglas Gregore3303542010-04-26 20:47:02 +00008742 // If nothing changed, just retain the existing expression.
8743 if (!getDerived().AlwaysRebuild() &&
8744 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008745 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008746
John McCall12f78a62010-12-02 01:19:52 +00008747 if (E->isExplicitProperty())
8748 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8749 E->getExplicitProperty(),
8750 E->getLocation());
8751
8752 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008753 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008754 E->getImplicitPropertyGetter(),
8755 E->getImplicitPropertySetter(),
8756 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008757}
8758
Mike Stump1eb44332009-09-09 15:08:12 +00008759template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008760ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008761TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8762 // Transform the base expression.
8763 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8764 if (Base.isInvalid())
8765 return ExprError();
8766
8767 // Transform the key expression.
8768 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8769 if (Key.isInvalid())
8770 return ExprError();
8771
8772 // If nothing changed, just retain the existing expression.
8773 if (!getDerived().AlwaysRebuild() &&
8774 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8775 return SemaRef.Owned(E);
8776
Chad Rosier4a9d7952012-08-08 18:46:20 +00008777 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008778 Base.get(), Key.get(),
8779 E->getAtIndexMethodDecl(),
8780 E->setAtIndexMethodDecl());
8781}
8782
8783template<typename Derived>
8784ExprResult
John McCall454feb92009-12-08 09:21:05 +00008785TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008786 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008787 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008788 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008789 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008790
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008791 // If nothing changed, just retain the existing expression.
8792 if (!getDerived().AlwaysRebuild() &&
8793 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008794 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008795
John McCall9ae2f072010-08-23 23:25:46 +00008796 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008797 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008798}
8799
Mike Stump1eb44332009-09-09 15:08:12 +00008800template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008801ExprResult
John McCall454feb92009-12-08 09:21:05 +00008802TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008803 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008804 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008805 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008806 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008807 SubExprs, &ArgumentChanged))
8808 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008809
Douglas Gregorb98b1992009-08-11 05:31:07 +00008810 if (!getDerived().AlwaysRebuild() &&
8811 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008812 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008813
Douglas Gregorb98b1992009-08-11 05:31:07 +00008814 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008815 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008816 E->getRParenLoc());
8817}
8818
Mike Stump1eb44332009-09-09 15:08:12 +00008819template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008820ExprResult
John McCall454feb92009-12-08 09:21:05 +00008821TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008822 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008823
John McCallc6ac9c32011-02-04 18:33:18 +00008824 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8825 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8826
8827 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008828 blockScope->TheDecl->setBlockMissingReturnType(
8829 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008830
Chris Lattner686775d2011-07-20 06:58:45 +00008831 SmallVector<ParmVarDecl*, 4> params;
8832 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008833
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008834 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008835 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8836 oldBlock->param_begin(),
8837 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008838 0, paramTypes, &params)) {
8839 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008840 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008841 }
John McCallc6ac9c32011-02-04 18:33:18 +00008842
8843 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008844 QualType exprResultType =
8845 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008846
8847 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008848 if (exprResultType->isObjCObjectType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008849 getSema().Diag(E->getCaretLocation(),
8850 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008851 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008852 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008853 return ExprError();
8854 }
John McCall711c52b2011-01-05 12:14:39 +00008855
John McCallc6ac9c32011-02-04 18:33:18 +00008856 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008857 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008858 paramTypes.data(),
8859 paramTypes.size(),
8860 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008861 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008862 exprFunctionType->getExtInfo());
8863 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008864
8865 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008866 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008867 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008868
8869 if (!oldBlock->blockMissingReturnType()) {
8870 blockScope->HasImplicitReturnType = false;
8871 blockScope->ReturnType = exprResultType;
8872 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008873
John McCall711c52b2011-01-05 12:14:39 +00008874 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008875 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008876 if (body.isInvalid()) {
8877 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008878 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008879 }
John McCall711c52b2011-01-05 12:14:39 +00008880
John McCallc6ac9c32011-02-04 18:33:18 +00008881#ifndef NDEBUG
8882 // In builds with assertions, make sure that we captured everything we
8883 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008884 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8885 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8886 e = oldBlock->capture_end(); i != e; ++i) {
8887 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008888
Douglas Gregorfc921372011-05-20 15:32:55 +00008889 // Ignore parameter packs.
8890 if (isa<ParmVarDecl>(oldCapture) &&
8891 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8892 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008893
Douglas Gregorfc921372011-05-20 15:32:55 +00008894 VarDecl *newCapture =
8895 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8896 oldCapture));
8897 assert(blockScope->CaptureMap.count(newCapture));
8898 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008899 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008900 }
8901#endif
8902
8903 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8904 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008905}
8906
Mike Stump1eb44332009-09-09 15:08:12 +00008907template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008908ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008909TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008910 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008911}
Eli Friedman276b0612011-10-11 02:20:01 +00008912
8913template<typename Derived>
8914ExprResult
8915TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008916 QualType RetTy = getDerived().TransformType(E->getType());
8917 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008918 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008919 SubExprs.reserve(E->getNumSubExprs());
8920 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8921 SubExprs, &ArgumentChanged))
8922 return ExprError();
8923
8924 if (!getDerived().AlwaysRebuild() &&
8925 !ArgumentChanged)
8926 return SemaRef.Owned(E);
8927
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008928 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008929 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008930}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008931
Douglas Gregorb98b1992009-08-11 05:31:07 +00008932//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008933// Type reconstruction
8934//===----------------------------------------------------------------------===//
8935
Mike Stump1eb44332009-09-09 15:08:12 +00008936template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008937QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8938 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008939 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008940 getDerived().getBaseEntity());
8941}
8942
Mike Stump1eb44332009-09-09 15:08:12 +00008943template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008944QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8945 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008946 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008947 getDerived().getBaseEntity());
8948}
8949
Mike Stump1eb44332009-09-09 15:08:12 +00008950template<typename Derived>
8951QualType
John McCall85737a72009-10-30 00:06:24 +00008952TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8953 bool WrittenAsLValue,
8954 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008955 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008956 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008957}
8958
8959template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008960QualType
John McCall85737a72009-10-30 00:06:24 +00008961TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8962 QualType ClassType,
8963 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008964 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008965 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008966}
8967
8968template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008969QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008970TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8971 ArrayType::ArraySizeModifier SizeMod,
8972 const llvm::APInt *Size,
8973 Expr *SizeExpr,
8974 unsigned IndexTypeQuals,
8975 SourceRange BracketsRange) {
8976 if (SizeExpr || !Size)
8977 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8978 IndexTypeQuals, BracketsRange,
8979 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008980
8981 QualType Types[] = {
8982 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8983 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8984 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008985 };
8986 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8987 QualType SizeType;
8988 for (unsigned I = 0; I != NumTypes; ++I)
8989 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8990 SizeType = Types[I];
8991 break;
8992 }
Mike Stump1eb44332009-09-09 15:08:12 +00008993
Eli Friedman01f276d2012-01-25 23:20:27 +00008994 // Note that we can return a VariableArrayType here in the case where
8995 // the element type was a dependent VariableArrayType.
8996 IntegerLiteral *ArraySize
8997 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8998 /*FIXME*/BracketsRange.getBegin());
8999 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009000 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00009001 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009002}
Mike Stump1eb44332009-09-09 15:08:12 +00009003
Douglas Gregor577f75a2009-08-04 16:50:30 +00009004template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009005QualType
9006TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009007 ArrayType::ArraySizeModifier SizeMod,
9008 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009009 unsigned IndexTypeQuals,
9010 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009011 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009012 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009013}
9014
9015template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009016QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009017TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009018 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009019 unsigned IndexTypeQuals,
9020 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009021 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009022 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009023}
Mike Stump1eb44332009-09-09 15:08:12 +00009024
Douglas Gregor577f75a2009-08-04 16:50:30 +00009025template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009026QualType
9027TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009028 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009029 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009030 unsigned IndexTypeQuals,
9031 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009032 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009033 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009034 IndexTypeQuals, BracketsRange);
9035}
9036
9037template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009038QualType
9039TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009040 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009041 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009042 unsigned IndexTypeQuals,
9043 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009044 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009045 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009046 IndexTypeQuals, BracketsRange);
9047}
9048
9049template<typename Derived>
9050QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009051 unsigned NumElements,
9052 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009053 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009054 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009055}
Mike Stump1eb44332009-09-09 15:08:12 +00009056
Douglas Gregor577f75a2009-08-04 16:50:30 +00009057template<typename Derived>
9058QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9059 unsigned NumElements,
9060 SourceLocation AttributeLoc) {
9061 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9062 NumElements, true);
9063 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009064 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9065 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009066 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009067}
Mike Stump1eb44332009-09-09 15:08:12 +00009068
Douglas Gregor577f75a2009-08-04 16:50:30 +00009069template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009070QualType
9071TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009072 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009073 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009074 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009075}
Mike Stump1eb44332009-09-09 15:08:12 +00009076
Douglas Gregor577f75a2009-08-04 16:50:30 +00009077template<typename Derived>
9078QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00009079 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009080 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00009081 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009082 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00009083 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00009084 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00009085 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00009086 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009087 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009088 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009089 getDerived().getBaseEntity(),
9090 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009091}
Mike Stump1eb44332009-09-09 15:08:12 +00009092
Douglas Gregor577f75a2009-08-04 16:50:30 +00009093template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009094QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9095 return SemaRef.Context.getFunctionNoProtoType(T);
9096}
9097
9098template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009099QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9100 assert(D && "no decl found");
9101 if (D->isInvalidDecl()) return QualType();
9102
Douglas Gregor92e986e2010-04-22 16:44:27 +00009103 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009104 TypeDecl *Ty;
9105 if (isa<UsingDecl>(D)) {
9106 UsingDecl *Using = cast<UsingDecl>(D);
9107 assert(Using->isTypeName() &&
9108 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9109
9110 // A valid resolved using typename decl points to exactly one type decl.
9111 assert(++Using->shadow_begin() == Using->shadow_end());
9112 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009113
John McCalled976492009-12-04 22:46:56 +00009114 } else {
9115 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9116 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9117 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9118 }
9119
9120 return SemaRef.Context.getTypeDeclType(Ty);
9121}
9122
9123template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009124QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9125 SourceLocation Loc) {
9126 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009127}
9128
9129template<typename Derived>
9130QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9131 return SemaRef.Context.getTypeOfType(Underlying);
9132}
9133
9134template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009135QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9136 SourceLocation Loc) {
9137 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009138}
9139
9140template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009141QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9142 UnaryTransformType::UTTKind UKind,
9143 SourceLocation Loc) {
9144 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9145}
9146
9147template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009148QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009149 TemplateName Template,
9150 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009151 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009152 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009153}
Mike Stump1eb44332009-09-09 15:08:12 +00009154
Douglas Gregordcee1a12009-08-06 05:28:30 +00009155template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009156QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9157 SourceLocation KWLoc) {
9158 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9159}
9160
9161template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009162TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009163TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009164 bool TemplateKW,
9165 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009166 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009167 Template);
9168}
9169
9170template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009171TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009172TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9173 const IdentifierInfo &Name,
9174 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009175 QualType ObjectType,
9176 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009177 UnqualifiedId TemplateName;
9178 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009179 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009180 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009181 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009182 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009183 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009184 /*EnteringContext=*/false,
9185 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009186 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009187}
Mike Stump1eb44332009-09-09 15:08:12 +00009188
Douglas Gregorb98b1992009-08-11 05:31:07 +00009189template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009190TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009191TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009192 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009193 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009194 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009195 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009196 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009197 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009198 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009199 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009200 Sema::TemplateTy Template;
9201 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009202 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009203 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009204 /*EnteringContext=*/false,
9205 Template);
9206 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009207}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009208
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009209template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009210ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009211TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9212 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009213 Expr *OrigCallee,
9214 Expr *First,
9215 Expr *Second) {
9216 Expr *Callee = OrigCallee->IgnoreParenCasts();
9217 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009218
Douglas Gregorb98b1992009-08-11 05:31:07 +00009219 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009220 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009221 if (!First->getType()->isOverloadableType() &&
9222 !Second->getType()->isOverloadableType())
9223 return getSema().CreateBuiltinArraySubscriptExpr(First,
9224 Callee->getLocStart(),
9225 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009226 } else if (Op == OO_Arrow) {
9227 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009228 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9229 } else if (Second == 0 || isPostIncDec) {
9230 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009231 // The argument is not of overloadable type, so try to create a
9232 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009233 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009234 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009235
John McCall9ae2f072010-08-23 23:25:46 +00009236 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009237 }
9238 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009239 if (!First->getType()->isOverloadableType() &&
9240 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009241 // Neither of the arguments is an overloadable type, so try to
9242 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009243 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009244 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009245 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009246 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009247 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009248
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009249 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009250 }
9251 }
Mike Stump1eb44332009-09-09 15:08:12 +00009252
9253 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009254 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009255 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009256
John McCall9ae2f072010-08-23 23:25:46 +00009257 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009258 assert(ULE->requiresADL());
9259
9260 // FIXME: Do we have to check
9261 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009262 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009263 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009264 // If we've resolved this to a particular non-member function, just call
9265 // that function. If we resolved it to a member function,
9266 // CreateOverloaded* will find that function for us.
9267 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9268 if (!isa<CXXMethodDecl>(ND))
9269 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009270 }
Mike Stump1eb44332009-09-09 15:08:12 +00009271
Douglas Gregorb98b1992009-08-11 05:31:07 +00009272 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009273 Expr *Args[2] = { First, Second };
9274 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009275
Douglas Gregorb98b1992009-08-11 05:31:07 +00009276 // Create the overloaded operator invocation for unary operators.
9277 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009278 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009279 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009280 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009281 }
Mike Stump1eb44332009-09-09 15:08:12 +00009282
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009283 if (Op == OO_Subscript) {
9284 SourceLocation LBrace;
9285 SourceLocation RBrace;
9286
9287 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9288 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9289 LBrace = SourceLocation::getFromRawEncoding(
9290 NameLoc.CXXOperatorName.BeginOpNameLoc);
9291 RBrace = SourceLocation::getFromRawEncoding(
9292 NameLoc.CXXOperatorName.EndOpNameLoc);
9293 } else {
9294 LBrace = Callee->getLocStart();
9295 RBrace = OpLoc;
9296 }
9297
9298 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9299 First, Second);
9300 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009301
Douglas Gregorb98b1992009-08-11 05:31:07 +00009302 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009303 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009304 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009305 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9306 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009307 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009308
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009309 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009310}
Mike Stump1eb44332009-09-09 15:08:12 +00009311
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009312template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009313ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009314TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009315 SourceLocation OperatorLoc,
9316 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009317 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009318 TypeSourceInfo *ScopeType,
9319 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009320 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009321 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009322 QualType BaseType = Base->getType();
9323 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009324 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009325 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009326 !BaseType->getAs<PointerType>()->getPointeeType()
9327 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009328 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009329 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009330 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009331 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009332 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009333 /*FIXME?*/true);
9334 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009335
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009336 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009337 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9338 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9339 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9340 NameInfo.setNamedTypeInfo(DestroyedType);
9341
Richard Smith6314db92012-05-15 06:15:11 +00009342 // The scope type is now known to be a valid nested name specifier
9343 // component. Tack it on to the end of the nested name specifier.
9344 if (ScopeType)
9345 SS.Extend(SemaRef.Context, SourceLocation(),
9346 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009347
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009348 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009349 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009350 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009351 SS, TemplateKWLoc,
9352 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009353 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009354 /*TemplateArgs*/ 0);
9355}
9356
Douglas Gregor577f75a2009-08-04 16:50:30 +00009357} // end namespace clang
9358
9359#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H