blob: 835609585ebbbf4435e6f8358ab2915e2da396d6 [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,
Jordan Rosebea522f2013-03-08 21:51:21 +0000716 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +0000717 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump1eb44332009-09-09 15:08:12 +0000718
John McCalla2becad2009-10-21 00:40:46 +0000719 /// \brief Build a new unprototyped function type.
720 QualType RebuildFunctionNoProtoType(QualType ResultType);
721
John McCalled976492009-12-04 22:46:56 +0000722 /// \brief Rebuild an unresolved typename type, given the decl that
723 /// the UnresolvedUsingTypenameDecl was transformed to.
724 QualType RebuildUnresolvedUsingType(Decl *D);
725
Douglas Gregor577f75a2009-08-04 16:50:30 +0000726 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000727 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000728 return SemaRef.Context.getTypeDeclType(Typedef);
729 }
730
731 /// \brief Build a new class/struct/union type.
732 QualType RebuildRecordType(RecordDecl *Record) {
733 return SemaRef.Context.getTypeDeclType(Record);
734 }
735
736 /// \brief Build a new Enum type.
737 QualType RebuildEnumType(EnumDecl *Enum) {
738 return SemaRef.Context.getTypeDeclType(Enum);
739 }
John McCall7da24312009-09-05 00:15:47 +0000740
Mike Stump1eb44332009-09-09 15:08:12 +0000741 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000742 ///
743 /// By default, performs semantic analysis when building the typeof type.
744 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000745 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000746
Mike Stump1eb44332009-09-09 15:08:12 +0000747 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000748 ///
749 /// By default, builds a new TypeOfType with the given underlying type.
750 QualType RebuildTypeOfType(QualType Underlying);
751
Sean Huntca63c202011-05-24 22:41:36 +0000752 /// \brief Build a new unary transform type.
753 QualType RebuildUnaryTransformType(QualType BaseType,
754 UnaryTransformType::UTTKind UKind,
755 SourceLocation Loc);
756
Mike Stump1eb44332009-09-09 15:08:12 +0000757 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000758 ///
759 /// By default, performs semantic analysis when building the decltype type.
760 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000761 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000762
Richard Smith34b41d92011-02-20 03:19:35 +0000763 /// \brief Build a new C++0x auto type.
764 ///
765 /// By default, builds a new AutoType with the given deduced type.
766 QualType RebuildAutoType(QualType Deduced) {
767 return SemaRef.Context.getAutoType(Deduced);
768 }
769
Douglas Gregor577f75a2009-08-04 16:50:30 +0000770 /// \brief Build a new template specialization type.
771 ///
772 /// By default, performs semantic analysis when building the template
773 /// specialization type. Subclasses may override this routine to provide
774 /// different behavior.
775 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000776 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000777 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000778
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000779 /// \brief Build a new parenthesized type.
780 ///
781 /// By default, builds a new ParenType type from the inner type.
782 /// Subclasses may override this routine to provide different behavior.
783 QualType RebuildParenType(QualType InnerType) {
784 return SemaRef.Context.getParenType(InnerType);
785 }
786
Douglas Gregor577f75a2009-08-04 16:50:30 +0000787 /// \brief Build a new qualified name type.
788 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000789 /// By default, builds a new ElaboratedType type from the keyword,
790 /// the nested-name-specifier and the named type.
791 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000792 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
793 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000794 NestedNameSpecifierLoc QualifierLoc,
795 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000796 return SemaRef.Context.getElaboratedType(Keyword,
797 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000798 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000799 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000800
801 /// \brief Build a new typename type that refers to a template-id.
802 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000803 /// By default, builds a new DependentNameType type from the
804 /// nested-name-specifier and the given type. Subclasses may override
805 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000806 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000807 ElaboratedTypeKeyword Keyword,
808 NestedNameSpecifierLoc QualifierLoc,
809 const IdentifierInfo *Name,
810 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000811 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000812 // Rebuild the template name.
813 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000814 CXXScopeSpec SS;
815 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000816 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000817 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000818
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000819 if (InstName.isNull())
820 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000821
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000822 // If it's still dependent, make a dependent specialization.
823 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000824 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
825 QualifierLoc.getNestedNameSpecifier(),
826 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000827 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000828
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000829 // Otherwise, make an elaborated type wrapping a non-dependent
830 // specialization.
831 QualType T =
832 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
833 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000834
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000835 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
836 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000837
838 return SemaRef.Context.getElaboratedType(Keyword,
839 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000840 T);
841 }
842
Douglas Gregor577f75a2009-08-04 16:50:30 +0000843 /// \brief Build a new typename type that refers to an identifier.
844 ///
845 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000846 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000847 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000848 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000849 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000850 NestedNameSpecifierLoc QualifierLoc,
851 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000852 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000853 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000854 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000855
Douglas Gregor2494dd02011-03-01 01:34:45 +0000856 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000857 // If the name is still dependent, just build a new dependent name type.
858 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000859 return SemaRef.Context.getDependentNameType(Keyword,
860 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000861 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000862 }
863
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000864 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000865 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000866 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000867
868 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
869
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000870 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000871 // into a non-dependent elaborated-type-specifier. Find the tag we're
872 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000873 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000874 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
875 if (!DC)
876 return QualType();
877
John McCall56138762010-05-27 06:40:31 +0000878 if (SemaRef.RequireCompleteDeclContext(SS, DC))
879 return QualType();
880
Douglas Gregor40336422010-03-31 22:19:08 +0000881 TagDecl *Tag = 0;
882 SemaRef.LookupQualifiedName(Result, DC);
883 switch (Result.getResultKind()) {
884 case LookupResult::NotFound:
885 case LookupResult::NotFoundInCurrentInstantiation:
886 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000887
Douglas Gregor40336422010-03-31 22:19:08 +0000888 case LookupResult::Found:
889 Tag = Result.getAsSingle<TagDecl>();
890 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000891
Douglas Gregor40336422010-03-31 22:19:08 +0000892 case LookupResult::FoundOverloaded:
893 case LookupResult::FoundUnresolvedValue:
894 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000895
Douglas Gregor40336422010-03-31 22:19:08 +0000896 case LookupResult::Ambiguous:
897 // Let the LookupResult structure handle ambiguities.
898 return QualType();
899 }
900
901 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000902 // Check where the name exists but isn't a tag type and use that to emit
903 // better diagnostics.
904 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
905 SemaRef.LookupQualifiedName(Result, DC);
906 switch (Result.getResultKind()) {
907 case LookupResult::Found:
908 case LookupResult::FoundOverloaded:
909 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000910 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000911 unsigned Kind = 0;
912 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000913 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
914 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000915 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
916 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
917 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000918 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000919 default:
920 // FIXME: Would be nice to highlight just the source range.
921 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
922 << Kind << Id << DC;
923 break;
924 }
Douglas Gregor40336422010-03-31 22:19:08 +0000925 return QualType();
926 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000927
Richard Trieubbf34c02011-06-10 03:11:26 +0000928 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
929 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000930 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000931 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
932 return QualType();
933 }
934
935 // Build the elaborated-type-specifier type.
936 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000937 return SemaRef.Context.getElaboratedType(Keyword,
938 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000939 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000940 }
Mike Stump1eb44332009-09-09 15:08:12 +0000941
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000942 /// \brief Build a new pack expansion type.
943 ///
944 /// By default, builds a new PackExpansionType type from the given pattern.
945 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000946 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000947 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000948 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +0000949 Optional<unsigned> NumExpansions) {
Douglas Gregorcded4f62011-01-14 17:04:44 +0000950 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
951 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000952 }
953
Eli Friedmanb001de72011-10-06 23:00:33 +0000954 /// \brief Build a new atomic type given its value type.
955 ///
956 /// By default, performs semantic analysis when building the atomic type.
957 /// Subclasses may override this routine to provide different behavior.
958 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
959
Douglas Gregord1067e52009-08-06 06:41:21 +0000960 /// \brief Build a new template name given a nested name specifier, a flag
961 /// indicating whether the "template" keyword was provided, and the template
962 /// that the template name refers to.
963 ///
964 /// By default, builds the new template name directly. Subclasses may override
965 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000966 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000967 bool TemplateKW,
968 TemplateDecl *Template);
969
Douglas Gregord1067e52009-08-06 06:41:21 +0000970 /// \brief Build a new template name given a nested name specifier and the
971 /// name that is referred to as a template.
972 ///
973 /// By default, performs semantic analysis to determine whether the name can
974 /// be resolved to a specific template, then builds the appropriate kind of
975 /// template name. Subclasses may override this routine to provide different
976 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000977 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
978 const IdentifierInfo &Name,
979 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000980 QualType ObjectType,
981 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000982
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000983 /// \brief Build a new template name given a nested name specifier and the
984 /// overloaded operator name that is referred to as a template.
985 ///
986 /// By default, performs semantic analysis to determine whether the name can
987 /// be resolved to a specific template, then builds the appropriate kind of
988 /// template name. Subclasses may override this routine to provide different
989 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000990 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000991 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000992 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000993 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000994
995 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +0000996 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000997 ///
998 /// By default, performs semantic analysis to determine whether the name can
999 /// be resolved to a specific template, then builds the appropriate kind of
1000 /// template name. Subclasses may override this routine to provide different
1001 /// behavior.
1002 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1003 const TemplateArgument &ArgPack) {
1004 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1005 }
1006
Douglas Gregor43959a92009-08-20 07:17:43 +00001007 /// \brief Build a new compound statement.
1008 ///
1009 /// By default, performs semantic analysis to build the new statement.
1010 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001011 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001012 MultiStmtArg Statements,
1013 SourceLocation RBraceLoc,
1014 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001015 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001016 IsStmtExpr);
1017 }
1018
1019 /// \brief Build a new case statement.
1020 ///
1021 /// By default, performs semantic analysis to build the new statement.
1022 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001023 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001024 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001025 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001026 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001027 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001028 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001029 ColonLoc);
1030 }
Mike Stump1eb44332009-09-09 15:08:12 +00001031
Douglas Gregor43959a92009-08-20 07:17:43 +00001032 /// \brief Attach the body to a new case statement.
1033 ///
1034 /// By default, performs semantic analysis to build the new statement.
1035 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001036 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001037 getSema().ActOnCaseStmtBody(S, Body);
1038 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001039 }
Mike Stump1eb44332009-09-09 15:08:12 +00001040
Douglas Gregor43959a92009-08-20 07:17:43 +00001041 /// \brief Build a new default statement.
1042 ///
1043 /// By default, performs semantic analysis to build the new statement.
1044 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001045 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001046 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001047 Stmt *SubStmt) {
1048 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001049 /*CurScope=*/0);
1050 }
Mike Stump1eb44332009-09-09 15:08:12 +00001051
Douglas Gregor43959a92009-08-20 07:17:43 +00001052 /// \brief Build a new label statement.
1053 ///
1054 /// By default, performs semantic analysis to build the new statement.
1055 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001056 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1057 SourceLocation ColonLoc, Stmt *SubStmt) {
1058 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001059 }
Mike Stump1eb44332009-09-09 15:08:12 +00001060
Richard Smith534986f2012-04-14 00:33:13 +00001061 /// \brief Build a new label statement.
1062 ///
1063 /// By default, performs semantic analysis to build the new statement.
1064 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001065 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1066 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001067 Stmt *SubStmt) {
1068 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1069 }
1070
Douglas Gregor43959a92009-08-20 07:17:43 +00001071 /// \brief Build a new "if" statement.
1072 ///
1073 /// By default, performs semantic analysis to build the new statement.
1074 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001075 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001076 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001077 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001078 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001079 }
Mike Stump1eb44332009-09-09 15:08:12 +00001080
Douglas Gregor43959a92009-08-20 07:17:43 +00001081 /// \brief Start building a new switch statement.
1082 ///
1083 /// By default, performs semantic analysis to build the new statement.
1084 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001085 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001086 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001087 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001088 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001089 }
Mike Stump1eb44332009-09-09 15:08:12 +00001090
Douglas Gregor43959a92009-08-20 07:17:43 +00001091 /// \brief Attach the body to the switch statement.
1092 ///
1093 /// By default, performs semantic analysis to build the new statement.
1094 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001095 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001096 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001097 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001098 }
1099
1100 /// \brief Build a new while statement.
1101 ///
1102 /// By default, performs semantic analysis to build the new statement.
1103 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001104 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1105 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001106 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001107 }
Mike Stump1eb44332009-09-09 15:08:12 +00001108
Douglas Gregor43959a92009-08-20 07:17:43 +00001109 /// \brief Build a new do-while statement.
1110 ///
1111 /// By default, performs semantic analysis to build the new statement.
1112 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001113 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001114 SourceLocation WhileLoc, SourceLocation LParenLoc,
1115 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001116 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1117 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001118 }
1119
1120 /// \brief Build a new for statement.
1121 ///
1122 /// By default, performs semantic analysis to build the new statement.
1123 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001124 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001125 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001126 VarDecl *CondVar, Sema::FullExprArg Inc,
1127 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001128 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001129 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001130 }
Mike Stump1eb44332009-09-09 15:08:12 +00001131
Douglas Gregor43959a92009-08-20 07:17:43 +00001132 /// \brief Build a new goto statement.
1133 ///
1134 /// By default, performs semantic analysis to build the new statement.
1135 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001136 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1137 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001138 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001139 }
1140
1141 /// \brief Build a new indirect goto statement.
1142 ///
1143 /// By default, performs semantic analysis to build the new statement.
1144 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001145 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001146 SourceLocation StarLoc,
1147 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001148 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001149 }
Mike Stump1eb44332009-09-09 15:08:12 +00001150
Douglas Gregor43959a92009-08-20 07:17:43 +00001151 /// \brief Build a new return statement.
1152 ///
1153 /// By default, performs semantic analysis to build the new statement.
1154 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001155 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001156 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001157 }
Mike Stump1eb44332009-09-09 15:08:12 +00001158
Douglas Gregor43959a92009-08-20 07:17:43 +00001159 /// \brief Build a new declaration statement.
1160 ///
1161 /// By default, performs semantic analysis to build the new statement.
1162 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001163 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001164 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001165 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001166 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1167 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001168 }
Mike Stump1eb44332009-09-09 15:08:12 +00001169
Anders Carlsson703e3942010-01-24 05:50:09 +00001170 /// \brief Build a new inline asm statement.
1171 ///
1172 /// By default, performs semantic analysis to build the new statement.
1173 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001174 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1175 bool IsVolatile, unsigned NumOutputs,
1176 unsigned NumInputs, IdentifierInfo **Names,
1177 MultiExprArg Constraints, MultiExprArg Exprs,
1178 Expr *AsmString, MultiExprArg Clobbers,
1179 SourceLocation RParenLoc) {
1180 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1181 NumInputs, Names, Constraints, Exprs,
1182 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001183 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001184
Chad Rosier8cd64b42012-06-11 20:47:18 +00001185 /// \brief Build a new MS style inline asm statement.
1186 ///
1187 /// By default, performs semantic analysis to build the new statement.
1188 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001189 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
1190 ArrayRef<Token> AsmToks, SourceLocation EndLoc) {
Chad Rosier7bd092b2012-08-15 16:53:30 +00001191 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001192 }
1193
James Dennett699c9042012-06-15 07:13:21 +00001194 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001195 ///
1196 /// By default, performs semantic analysis to build the new statement.
1197 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001198 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001199 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001200 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001201 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001202 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001203 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001204 }
1205
Douglas Gregorbe270a02010-04-26 17:57:08 +00001206 /// \brief Rebuild an Objective-C exception declaration.
1207 ///
1208 /// By default, performs semantic analysis to build the new declaration.
1209 /// Subclasses may override this routine to provide different behavior.
1210 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1211 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001212 return getSema().BuildObjCExceptionDecl(TInfo, T,
1213 ExceptionDecl->getInnerLocStart(),
1214 ExceptionDecl->getLocation(),
1215 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001216 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001217
James Dennett699c9042012-06-15 07:13:21 +00001218 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001219 ///
1220 /// By default, performs semantic analysis to build the new statement.
1221 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001222 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001223 SourceLocation RParenLoc,
1224 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001225 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001226 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001227 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001228 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001229
James Dennett699c9042012-06-15 07:13:21 +00001230 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001231 ///
1232 /// By default, performs semantic analysis to build the new statement.
1233 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001234 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001235 Stmt *Body) {
1236 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001237 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001238
James Dennett699c9042012-06-15 07:13:21 +00001239 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001240 ///
1241 /// By default, performs semantic analysis to build the new statement.
1242 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001243 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001244 Expr *Operand) {
1245 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001246 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001247
James Dennett699c9042012-06-15 07:13:21 +00001248 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001249 ///
1250 /// By default, performs semantic analysis to build the new statement.
1251 /// Subclasses may override this routine to provide different behavior.
1252 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1253 Expr *object) {
1254 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1255 }
1256
James Dennett699c9042012-06-15 07:13:21 +00001257 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001258 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001259 /// By default, performs semantic analysis to build the new statement.
1260 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001261 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001262 Expr *Object, Stmt *Body) {
1263 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001264 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001265
James Dennett699c9042012-06-15 07:13:21 +00001266 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001267 ///
1268 /// By default, performs semantic analysis to build the new statement.
1269 /// Subclasses may override this routine to provide different behavior.
1270 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1271 Stmt *Body) {
1272 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1273 }
John McCall990567c2011-07-27 01:07:15 +00001274
Douglas Gregorc3203e72010-04-22 23:10:45 +00001275 /// \brief Build a new Objective-C fast enumeration statement.
1276 ///
1277 /// By default, performs semantic analysis to build the new statement.
1278 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001279 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001280 Stmt *Element,
1281 Expr *Collection,
1282 SourceLocation RParenLoc,
1283 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001284 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001285 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001286 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001287 RParenLoc);
1288 if (ForEachStmt.isInvalid())
1289 return StmtError();
1290
1291 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001292 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001293
Douglas Gregor43959a92009-08-20 07:17:43 +00001294 /// \brief Build a new C++ exception declaration.
1295 ///
1296 /// By default, performs semantic analysis to build the new decaration.
1297 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001298 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001299 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001300 SourceLocation StartLoc,
1301 SourceLocation IdLoc,
1302 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001303 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1304 StartLoc, IdLoc, Id);
1305 if (Var)
1306 getSema().CurContext->addDecl(Var);
1307 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001308 }
1309
1310 /// \brief Build a new C++ catch statement.
1311 ///
1312 /// By default, performs semantic analysis to build the new statement.
1313 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001314 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001315 VarDecl *ExceptionDecl,
1316 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001317 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1318 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001319 }
Mike Stump1eb44332009-09-09 15:08:12 +00001320
Douglas Gregor43959a92009-08-20 07:17:43 +00001321 /// \brief Build a new C++ try statement.
1322 ///
1323 /// By default, performs semantic analysis to build the new statement.
1324 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001325 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001326 Stmt *TryBlock,
1327 MultiStmtArg Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001328 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001329 }
Mike Stump1eb44332009-09-09 15:08:12 +00001330
Richard Smithad762fc2011-04-14 22:09:26 +00001331 /// \brief Build a new C++0x range-based for statement.
1332 ///
1333 /// By default, performs semantic analysis to build the new statement.
1334 /// Subclasses may override this routine to provide different behavior.
1335 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1336 SourceLocation ColonLoc,
1337 Stmt *Range, Stmt *BeginEnd,
1338 Expr *Cond, Expr *Inc,
1339 Stmt *LoopVar,
1340 SourceLocation RParenLoc) {
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001341 // If we've just learned that the range is actually an Objective-C
1342 // collection, treat this as an Objective-C fast enumeration loop.
1343 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1344 if (RangeStmt->isSingleDecl()) {
1345 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
1346 Expr *RangeExpr = RangeVar->getInit();
1347 if (!RangeExpr->isTypeDependent() &&
1348 RangeExpr->getType()->isObjCObjectPointerType())
1349 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1350 RParenLoc);
1351 }
1352 }
1353 }
1354
Richard Smithad762fc2011-04-14 22:09:26 +00001355 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001356 Cond, Inc, LoopVar, RParenLoc,
1357 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001358 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001359
1360 /// \brief Build a new C++0x range-based for statement.
1361 ///
1362 /// By default, performs semantic analysis to build the new statement.
1363 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001364 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001365 bool IsIfExists,
1366 NestedNameSpecifierLoc QualifierLoc,
1367 DeclarationNameInfo NameInfo,
1368 Stmt *Nested) {
1369 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1370 QualifierLoc, NameInfo, Nested);
1371 }
1372
Richard Smithad762fc2011-04-14 22:09:26 +00001373 /// \brief Attach body to a C++0x range-based for statement.
1374 ///
1375 /// By default, performs semantic analysis to finish the new statement.
1376 /// Subclasses may override this routine to provide different behavior.
1377 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1378 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1379 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001380
John Wiegley28bbe4b2011-04-28 01:08:34 +00001381 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1382 SourceLocation TryLoc,
1383 Stmt *TryBlock,
1384 Stmt *Handler) {
1385 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1386 }
1387
1388 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1389 Expr *FilterExpr,
1390 Stmt *Block) {
1391 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1392 }
1393
1394 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1395 Stmt *Block) {
1396 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1397 }
1398
Douglas Gregorb98b1992009-08-11 05:31:07 +00001399 /// \brief Build a new expression that references a declaration.
1400 ///
1401 /// By default, performs semantic analysis to build the new expression.
1402 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001403 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001404 LookupResult &R,
1405 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001406 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1407 }
1408
1409
1410 /// \brief Build a new expression that references a declaration.
1411 ///
1412 /// By default, performs semantic analysis to build the new expression.
1413 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001414 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001415 ValueDecl *VD,
1416 const DeclarationNameInfo &NameInfo,
1417 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001418 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001419 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001420
1421 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001422
1423 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001424 }
Mike Stump1eb44332009-09-09 15:08:12 +00001425
Douglas Gregorb98b1992009-08-11 05:31:07 +00001426 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001427 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001428 /// By default, performs semantic analysis to build the new expression.
1429 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001430 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001431 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001432 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001433 }
1434
Douglas Gregora71d8192009-09-04 17:36:40 +00001435 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001436 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001437 /// By default, performs semantic analysis to build the new expression.
1438 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001439 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001440 SourceLocation OperatorLoc,
1441 bool isArrow,
1442 CXXScopeSpec &SS,
1443 TypeSourceInfo *ScopeType,
1444 SourceLocation CCLoc,
1445 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001446 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001447
Douglas Gregorb98b1992009-08-11 05:31:07 +00001448 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001449 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001450 /// 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 RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001453 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001454 Expr *SubExpr) {
1455 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001456 }
Mike Stump1eb44332009-09-09 15:08:12 +00001457
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001458 /// \brief Build a new builtin offsetof expression.
1459 ///
1460 /// By default, performs semantic analysis to build the new expression.
1461 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001462 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001463 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001464 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001465 unsigned NumComponents,
1466 SourceLocation RParenLoc) {
1467 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1468 NumComponents, RParenLoc);
1469 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001470
1471 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001472 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001473 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001474 /// By default, performs semantic analysis to build the new expression.
1475 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001476 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1477 SourceLocation OpLoc,
1478 UnaryExprOrTypeTrait ExprKind,
1479 SourceRange R) {
1480 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001481 }
1482
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001483 /// \brief Build a new sizeof, alignof or vec step expression with an
1484 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001485 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001486 /// By default, performs semantic analysis to build the new expression.
1487 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001488 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1489 UnaryExprOrTypeTrait ExprKind,
1490 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001491 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001492 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001494 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001495
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001496 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001497 }
Mike Stump1eb44332009-09-09 15:08:12 +00001498
Douglas Gregorb98b1992009-08-11 05:31:07 +00001499 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001500 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001501 /// By default, performs semantic analysis to build the new expression.
1502 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001503 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001504 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001505 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001506 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001507 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1508 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001509 RBracketLoc);
1510 }
1511
1512 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001513 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001514 /// By default, performs semantic analysis to build the new expression.
1515 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001516 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001517 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001518 SourceLocation RParenLoc,
1519 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001520 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001521 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001522 }
1523
1524 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001525 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001526 /// By default, performs semantic analysis to build the new expression.
1527 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001528 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001529 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001530 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001531 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001532 const DeclarationNameInfo &MemberNameInfo,
1533 ValueDecl *Member,
1534 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001535 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001536 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001537 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1538 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001539 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001540 // We have a reference to an unnamed field. This is always the
1541 // base of an anonymous struct/union member access, i.e. the
1542 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001543 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001544 assert(Member->getType()->isRecordType() &&
1545 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001546
Richard Smith9138b4e2011-10-26 19:06:56 +00001547 BaseResult =
1548 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001549 QualifierLoc.getNestedNameSpecifier(),
1550 FoundDecl, Member);
1551 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001552 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001553 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001554 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001555 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001556 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001557 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001558 cast<FieldDecl>(Member)->getType(),
1559 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001560 return getSema().Owned(ME);
1561 }
Mike Stump1eb44332009-09-09 15:08:12 +00001562
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001563 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001564 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001565
John Wiegley429bb272011-04-08 18:41:53 +00001566 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001567 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001568
John McCall6bb80172010-03-30 21:47:33 +00001569 // FIXME: this involves duplicating earlier analysis in a lot of
1570 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001571 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001572 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001573 R.resolveKind();
1574
John McCall9ae2f072010-08-23 23:25:46 +00001575 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001576 SS, TemplateKWLoc,
1577 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001578 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001579 }
Mike Stump1eb44332009-09-09 15:08:12 +00001580
Douglas Gregorb98b1992009-08-11 05:31:07 +00001581 /// \brief Build a new binary 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 RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001586 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001587 Expr *LHS, Expr *RHS) {
1588 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001589 }
1590
1591 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001592 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001593 /// By default, performs semantic analysis to build the new expression.
1594 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001595 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001596 SourceLocation QuestionLoc,
1597 Expr *LHS,
1598 SourceLocation ColonLoc,
1599 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001600 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1601 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 }
1603
Douglas Gregorb98b1992009-08-11 05:31:07 +00001604 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001605 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001606 /// By default, performs semantic analysis to build the new expression.
1607 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001608 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001609 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001610 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001611 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001612 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001613 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001614 }
Mike Stump1eb44332009-09-09 15:08:12 +00001615
Douglas Gregorb98b1992009-08-11 05:31:07 +00001616 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001617 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001618 /// By default, performs semantic analysis to build the new expression.
1619 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001620 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001621 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001622 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001623 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001624 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001625 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001626 }
Mike Stump1eb44332009-09-09 15:08:12 +00001627
Douglas Gregorb98b1992009-08-11 05:31:07 +00001628 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001629 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001630 /// By default, performs semantic analysis to build the new expression.
1631 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001632 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001633 SourceLocation OpLoc,
1634 SourceLocation AccessorLoc,
1635 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001636
John McCall129e2df2009-11-30 22:42:35 +00001637 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001638 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001639 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001640 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001641 SS, SourceLocation(),
1642 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001643 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001644 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001645 }
Mike Stump1eb44332009-09-09 15:08:12 +00001646
Douglas Gregorb98b1992009-08-11 05:31:07 +00001647 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001648 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001649 /// By default, performs semantic analysis to build the new expression.
1650 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001651 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001652 MultiExprArg Inits,
1653 SourceLocation RBraceLoc,
1654 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001655 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001656 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001657 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001658 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001659
Douglas Gregore48319a2009-11-09 17:16:50 +00001660 // Patch in the result type we were given, which may have been computed
1661 // when the initial InitListExpr was built.
1662 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1663 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001664 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001665 }
Mike Stump1eb44332009-09-09 15:08:12 +00001666
Douglas Gregorb98b1992009-08-11 05:31:07 +00001667 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001668 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001669 /// By default, performs semantic analysis to build the new expression.
1670 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001671 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001672 MultiExprArg ArrayExprs,
1673 SourceLocation EqualOrColonLoc,
1674 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001675 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001676 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001677 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001678 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001679 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001680 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001681
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001682 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001683 }
Mike Stump1eb44332009-09-09 15:08:12 +00001684
Douglas Gregorb98b1992009-08-11 05:31:07 +00001685 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001686 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001687 /// By default, builds the implicit value initialization without performing
1688 /// any semantic analysis. Subclasses may override this routine to provide
1689 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001690 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001691 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1692 }
Mike Stump1eb44332009-09-09 15:08:12 +00001693
Douglas Gregorb98b1992009-08-11 05:31:07 +00001694 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001695 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001696 /// By default, performs semantic analysis to build the new expression.
1697 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001698 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001699 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001700 SourceLocation RParenLoc) {
1701 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001702 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001703 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001704 }
1705
1706 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001707 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001708 /// By default, performs semantic analysis to build the new expression.
1709 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001710 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001711 MultiExprArg SubExprs,
1712 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001713 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
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 address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001717 ///
1718 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001719 /// rather than attempting to map the label statement itself.
1720 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001721 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001722 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001723 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
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 GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001727 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001728 /// 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 RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001731 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001732 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001733 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001734 }
Mike Stump1eb44332009-09-09 15:08:12 +00001735
Douglas Gregorb98b1992009-08-11 05:31:07 +00001736 /// \brief Build a new __builtin_choose_expr expression.
1737 ///
1738 /// By default, performs semantic analysis to build the new expression.
1739 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001740 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001741 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001742 SourceLocation RParenLoc) {
1743 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001744 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001745 RParenLoc);
1746 }
Mike Stump1eb44332009-09-09 15:08:12 +00001747
Peter Collingbournef111d932011-04-15 00:35:48 +00001748 /// \brief Build a new generic selection expression.
1749 ///
1750 /// By default, performs semantic analysis to build the new expression.
1751 /// Subclasses may override this routine to provide different behavior.
1752 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1753 SourceLocation DefaultLoc,
1754 SourceLocation RParenLoc,
1755 Expr *ControllingExpr,
1756 TypeSourceInfo **Types,
1757 Expr **Exprs,
1758 unsigned NumAssocs) {
1759 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1760 ControllingExpr, Types, Exprs,
1761 NumAssocs);
1762 }
1763
Douglas Gregorb98b1992009-08-11 05:31:07 +00001764 /// \brief Build a new overloaded operator call expression.
1765 ///
1766 /// By default, performs semantic analysis to build the new expression.
1767 /// The semantic analysis provides the behavior of template instantiation,
1768 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001769 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001770 /// argument-dependent lookup, etc. Subclasses may override this routine to
1771 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001772 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001773 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001774 Expr *Callee,
1775 Expr *First,
1776 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001777
1778 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001779 /// reinterpret_cast.
1780 ///
1781 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001782 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001783 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001784 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001785 Stmt::StmtClass Class,
1786 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001787 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001788 SourceLocation RAngleLoc,
1789 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001790 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791 SourceLocation RParenLoc) {
1792 switch (Class) {
1793 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001794 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001795 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001796 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001797
1798 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001799 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001800 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001801 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001802
Douglas Gregorb98b1992009-08-11 05:31:07 +00001803 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001804 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001805 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001806 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001807 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001808
Douglas Gregorb98b1992009-08-11 05:31:07 +00001809 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001810 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001811 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001812 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001813
Douglas Gregorb98b1992009-08-11 05:31:07 +00001814 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001815 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001816 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001817 }
Mike Stump1eb44332009-09-09 15:08:12 +00001818
Douglas Gregorb98b1992009-08-11 05:31:07 +00001819 /// \brief Build a new C++ static_cast expression.
1820 ///
1821 /// By default, performs semantic analysis to build the new expression.
1822 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001823 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001824 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001825 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001826 SourceLocation RAngleLoc,
1827 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001828 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001829 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001830 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001831 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001832 SourceRange(LAngleLoc, RAngleLoc),
1833 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001834 }
1835
1836 /// \brief Build a new C++ dynamic_cast expression.
1837 ///
1838 /// By default, performs semantic analysis to build the new expression.
1839 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001840 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001841 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001842 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001843 SourceLocation RAngleLoc,
1844 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001845 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001846 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001847 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001848 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001849 SourceRange(LAngleLoc, RAngleLoc),
1850 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001851 }
1852
1853 /// \brief Build a new C++ reinterpret_cast expression.
1854 ///
1855 /// By default, performs semantic analysis to build the new expression.
1856 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001857 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001858 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001859 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001860 SourceLocation RAngleLoc,
1861 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001862 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001863 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001864 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001865 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001866 SourceRange(LAngleLoc, RAngleLoc),
1867 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001868 }
1869
1870 /// \brief Build a new C++ const_cast expression.
1871 ///
1872 /// By default, performs semantic analysis to build the new expression.
1873 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001874 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001875 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001876 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001877 SourceLocation RAngleLoc,
1878 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001879 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001880 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001881 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001882 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001883 SourceRange(LAngleLoc, RAngleLoc),
1884 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001885 }
Mike Stump1eb44332009-09-09 15:08:12 +00001886
Douglas Gregorb98b1992009-08-11 05:31:07 +00001887 /// \brief Build a new C++ functional-style cast expression.
1888 ///
1889 /// By default, performs semantic analysis to build the new expression.
1890 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001891 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1892 SourceLocation LParenLoc,
1893 Expr *Sub,
1894 SourceLocation RParenLoc) {
1895 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001896 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001897 RParenLoc);
1898 }
Mike Stump1eb44332009-09-09 15:08:12 +00001899
Douglas Gregorb98b1992009-08-11 05:31:07 +00001900 /// \brief Build a new C++ typeid(type) expression.
1901 ///
1902 /// By default, performs semantic analysis to build the new expression.
1903 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001904 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001905 SourceLocation TypeidLoc,
1906 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001907 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001908 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001909 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001910 }
Mike Stump1eb44332009-09-09 15:08:12 +00001911
Francois Pichet01b7c302010-09-08 12:20:18 +00001912
Douglas Gregorb98b1992009-08-11 05:31:07 +00001913 /// \brief Build a new C++ typeid(expr) expression.
1914 ///
1915 /// By default, performs semantic analysis to build the new expression.
1916 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001917 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001918 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001919 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001920 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001921 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001922 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001923 }
1924
Francois Pichet01b7c302010-09-08 12:20:18 +00001925 /// \brief Build a new C++ __uuidof(type) expression.
1926 ///
1927 /// By default, performs semantic analysis to build the new expression.
1928 /// Subclasses may override this routine to provide different behavior.
1929 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1930 SourceLocation TypeidLoc,
1931 TypeSourceInfo *Operand,
1932 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001933 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00001934 RParenLoc);
1935 }
1936
1937 /// \brief Build a new C++ __uuidof(expr) expression.
1938 ///
1939 /// By default, performs semantic analysis to build the new expression.
1940 /// Subclasses may override this routine to provide different behavior.
1941 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1942 SourceLocation TypeidLoc,
1943 Expr *Operand,
1944 SourceLocation RParenLoc) {
1945 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1946 RParenLoc);
1947 }
1948
Douglas Gregorb98b1992009-08-11 05:31:07 +00001949 /// \brief Build a new C++ "this" expression.
1950 ///
1951 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001952 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001953 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001954 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001955 QualType ThisType,
1956 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001957 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001958 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001959 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1960 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001961 }
1962
1963 /// \brief Build a new C++ throw expression.
1964 ///
1965 /// By default, performs semantic analysis to build the new expression.
1966 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001967 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1968 bool IsThrownVariableInScope) {
1969 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001970 }
1971
1972 /// \brief Build a new C++ default-argument expression.
1973 ///
1974 /// By default, builds a new default-argument expression, which does not
1975 /// require any semantic analysis. Subclasses may override this routine to
1976 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001977 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001978 ParmVarDecl *Param) {
1979 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1980 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001981 }
1982
1983 /// \brief Build a new C++ zero-initialization expression.
1984 ///
1985 /// By default, performs semantic analysis to build the new expression.
1986 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001987 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1988 SourceLocation LParenLoc,
1989 SourceLocation RParenLoc) {
1990 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Benjamin Kramer5354e772012-08-23 23:38:35 +00001991 MultiExprArg(), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001992 }
Mike Stump1eb44332009-09-09 15:08:12 +00001993
Douglas Gregorb98b1992009-08-11 05:31:07 +00001994 /// \brief Build a new C++ "new" expression.
1995 ///
1996 /// By default, performs semantic analysis to build the new expression.
1997 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001998 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001999 bool UseGlobal,
2000 SourceLocation PlacementLParen,
2001 MultiExprArg PlacementArgs,
2002 SourceLocation PlacementRParen,
2003 SourceRange TypeIdParens,
2004 QualType AllocatedType,
2005 TypeSourceInfo *AllocatedTypeInfo,
2006 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002007 SourceRange DirectInitRange,
2008 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00002009 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002010 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002011 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002012 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002013 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002014 AllocatedType,
2015 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002016 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002017 DirectInitRange,
2018 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002019 }
Mike Stump1eb44332009-09-09 15:08:12 +00002020
Douglas Gregorb98b1992009-08-11 05:31:07 +00002021 /// \brief Build a new C++ "delete" expression.
2022 ///
2023 /// By default, performs semantic analysis to build the new expression.
2024 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002025 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002026 bool IsGlobalDelete,
2027 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002028 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002029 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002030 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002031 }
Mike Stump1eb44332009-09-09 15:08:12 +00002032
Douglas Gregorb98b1992009-08-11 05:31:07 +00002033 /// \brief Build a new unary type trait expression.
2034 ///
2035 /// By default, performs semantic analysis to build the new expression.
2036 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002037 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002038 SourceLocation StartLoc,
2039 TypeSourceInfo *T,
2040 SourceLocation RParenLoc) {
2041 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002042 }
2043
Francois Pichet6ad6f282010-12-07 00:08:36 +00002044 /// \brief Build a new binary type trait expression.
2045 ///
2046 /// By default, performs semantic analysis to build the new expression.
2047 /// Subclasses may override this routine to provide different behavior.
2048 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2049 SourceLocation StartLoc,
2050 TypeSourceInfo *LhsT,
2051 TypeSourceInfo *RhsT,
2052 SourceLocation RParenLoc) {
2053 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2054 }
2055
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002056 /// \brief Build a new type trait expression.
2057 ///
2058 /// By default, performs semantic analysis to build the new expression.
2059 /// Subclasses may override this routine to provide different behavior.
2060 ExprResult RebuildTypeTrait(TypeTrait Trait,
2061 SourceLocation StartLoc,
2062 ArrayRef<TypeSourceInfo *> Args,
2063 SourceLocation RParenLoc) {
2064 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2065 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002066
John Wiegley21ff2e52011-04-28 00:16:57 +00002067 /// \brief Build a new array type trait expression.
2068 ///
2069 /// By default, performs semantic analysis to build the new expression.
2070 /// Subclasses may override this routine to provide different behavior.
2071 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2072 SourceLocation StartLoc,
2073 TypeSourceInfo *TSInfo,
2074 Expr *DimExpr,
2075 SourceLocation RParenLoc) {
2076 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2077 }
2078
John Wiegley55262202011-04-25 06:54:41 +00002079 /// \brief Build a new expression trait expression.
2080 ///
2081 /// By default, performs semantic analysis to build the new expression.
2082 /// Subclasses may override this routine to provide different behavior.
2083 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2084 SourceLocation StartLoc,
2085 Expr *Queried,
2086 SourceLocation RParenLoc) {
2087 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2088 }
2089
Mike Stump1eb44332009-09-09 15:08:12 +00002090 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002091 /// expression.
2092 ///
2093 /// By default, performs semantic analysis to build the new expression.
2094 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002095 ExprResult RebuildDependentScopeDeclRefExpr(
2096 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002097 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002098 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002099 const TemplateArgumentListInfo *TemplateArgs,
2100 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002101 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002102 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002103
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002104 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002105 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002106 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002107
Richard Smithefeeccf2012-10-21 03:28:35 +00002108 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2109 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002110 }
2111
2112 /// \brief Build a new template-id expression.
2113 ///
2114 /// By default, performs semantic analysis to build the new expression.
2115 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002116 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002117 SourceLocation TemplateKWLoc,
2118 LookupResult &R,
2119 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002120 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002121 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2122 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002123 }
2124
2125 /// \brief Build a new object-construction expression.
2126 ///
2127 /// By default, performs semantic analysis to build the new expression.
2128 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002129 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002130 SourceLocation Loc,
2131 CXXConstructorDecl *Constructor,
2132 bool IsElidable,
2133 MultiExprArg Args,
2134 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002135 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002136 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002137 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002138 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002139 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002140 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002141 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002142 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002143
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002144 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002145 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002146 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002147 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002148 RequiresZeroInit, ConstructKind,
2149 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002150 }
2151
2152 /// \brief Build a new object-construction expression.
2153 ///
2154 /// By default, performs semantic analysis to build the new expression.
2155 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002156 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2157 SourceLocation LParenLoc,
2158 MultiExprArg Args,
2159 SourceLocation RParenLoc) {
2160 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002161 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002162 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002163 RParenLoc);
2164 }
2165
2166 /// \brief Build a new object-construction expression.
2167 ///
2168 /// By default, performs semantic analysis to build the new expression.
2169 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002170 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2171 SourceLocation LParenLoc,
2172 MultiExprArg Args,
2173 SourceLocation RParenLoc) {
2174 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002175 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002176 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002177 RParenLoc);
2178 }
Mike Stump1eb44332009-09-09 15:08:12 +00002179
Douglas Gregorb98b1992009-08-11 05:31:07 +00002180 /// \brief Build a new member reference expression.
2181 ///
2182 /// By default, performs semantic analysis to build the new expression.
2183 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002184 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002185 QualType BaseType,
2186 bool IsArrow,
2187 SourceLocation OperatorLoc,
2188 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002189 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002190 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002191 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002192 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002193 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002194 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002195
John McCall9ae2f072010-08-23 23:25:46 +00002196 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002197 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002198 SS, TemplateKWLoc,
2199 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002200 MemberNameInfo,
2201 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002202 }
2203
John McCall129e2df2009-11-30 22:42:35 +00002204 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002205 ///
2206 /// By default, performs semantic analysis to build the new expression.
2207 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002208 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2209 SourceLocation OperatorLoc,
2210 bool IsArrow,
2211 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002212 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002213 NamedDecl *FirstQualifierInScope,
2214 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002215 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002216 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002217 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002218
John McCall9ae2f072010-08-23 23:25:46 +00002219 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002220 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002221 SS, TemplateKWLoc,
2222 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002223 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002224 }
Mike Stump1eb44332009-09-09 15:08:12 +00002225
Sebastian Redl2e156222010-09-10 20:55:43 +00002226 /// \brief Build a new noexcept expression.
2227 ///
2228 /// By default, performs semantic analysis to build the new expression.
2229 /// Subclasses may override this routine to provide different behavior.
2230 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2231 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2232 }
2233
Douglas Gregoree8aff02011-01-04 17:33:58 +00002234 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002235 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2236 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002237 SourceLocation RParenLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002238 Optional<unsigned> Length) {
Douglas Gregor089e8932011-10-10 18:59:29 +00002239 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002240 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2241 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002242 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002243
2244 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2245 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002246 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002247 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002248
Patrick Beardeb382ec2012-04-19 00:25:12 +00002249 /// \brief Build a new Objective-C boxed expression.
2250 ///
2251 /// By default, performs semantic analysis to build the new expression.
2252 /// Subclasses may override this routine to provide different behavior.
2253 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2254 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2255 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002256
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002257 /// \brief Build a new Objective-C array literal.
2258 ///
2259 /// By default, performs semantic analysis to build the new expression.
2260 /// Subclasses may override this routine to provide different behavior.
2261 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2262 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002263 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002264 MultiExprArg(Elements, NumElements));
2265 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002266
2267 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002268 Expr *Base, Expr *Key,
2269 ObjCMethodDecl *getterMethod,
2270 ObjCMethodDecl *setterMethod) {
2271 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2272 getterMethod, setterMethod);
2273 }
2274
2275 /// \brief Build a new Objective-C dictionary literal.
2276 ///
2277 /// By default, performs semantic analysis to build the new expression.
2278 /// Subclasses may override this routine to provide different behavior.
2279 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2280 ObjCDictionaryElement *Elements,
2281 unsigned NumElements) {
2282 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2283 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002284
James Dennett699c9042012-06-15 07:13:21 +00002285 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002286 ///
2287 /// By default, performs semantic analysis to build the new expression.
2288 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002289 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002290 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002291 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002292 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002293 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002294 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002295
Douglas Gregor92e986e2010-04-22 16:44:27 +00002296 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002297 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002298 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002299 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002300 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002301 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002302 MultiExprArg Args,
2303 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002304 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2305 ReceiverTypeInfo->getType(),
2306 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002307 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002308 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002309 }
2310
2311 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002312 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002313 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002314 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002315 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002316 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002317 MultiExprArg Args,
2318 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002319 return SemaRef.BuildInstanceMessage(Receiver,
2320 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002321 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002322 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002323 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002324 }
2325
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002326 /// \brief Build a new Objective-C ivar reference expression.
2327 ///
2328 /// By default, performs semantic analysis to build the new expression.
2329 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002330 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002331 SourceLocation IvarLoc,
2332 bool IsArrow, bool IsFreeIvar) {
2333 // FIXME: We lose track of the IsFreeIvar bit.
2334 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002335 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002336 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2337 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002338 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002339 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002340 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002341 false);
John Wiegley429bb272011-04-08 18:41:53 +00002342 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002343 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002344
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002345 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002346 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002347
John Wiegley429bb272011-04-08 18:41:53 +00002348 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002349 /*FIXME:*/IvarLoc, IsArrow,
2350 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002351 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002352 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002353 /*TemplateArgs=*/0);
2354 }
Douglas Gregore3303542010-04-26 20:47:02 +00002355
2356 /// \brief Build a new Objective-C property reference expression.
2357 ///
2358 /// By default, performs semantic analysis to build the new expression.
2359 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002360 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002361 ObjCPropertyDecl *Property,
2362 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002363 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002364 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002365 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2366 Sema::LookupMemberName);
2367 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002368 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002369 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002370 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002371 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002372 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002373
Douglas Gregore3303542010-04-26 20:47:02 +00002374 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002375 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002376
John Wiegley429bb272011-04-08 18:41:53 +00002377 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002378 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002379 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002380 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002381 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002382 /*TemplateArgs=*/0);
2383 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002384
John McCall12f78a62010-12-02 01:19:52 +00002385 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002386 ///
2387 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002388 /// Subclasses may override this routine to provide different behavior.
2389 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2390 ObjCMethodDecl *Getter,
2391 ObjCMethodDecl *Setter,
2392 SourceLocation PropertyLoc) {
2393 // Since these expressions can only be value-dependent, we do not
2394 // need to perform semantic analysis again.
2395 return Owned(
2396 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2397 VK_LValue, OK_ObjCProperty,
2398 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002399 }
2400
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002401 /// \brief Build a new Objective-C "isa" expression.
2402 ///
2403 /// By default, performs semantic analysis to build the new expression.
2404 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002405 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002406 SourceLocation OpLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002407 bool IsArrow) {
2408 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002409 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002410 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2411 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002412 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002413 OpLoc,
John McCalld226f652010-08-21 09:40:31 +00002414 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002415 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002416 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002417
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002418 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002419 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002420
John Wiegley429bb272011-04-08 18:41:53 +00002421 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002422 OpLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002423 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002424 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002425 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002426 /*TemplateArgs=*/0);
2427 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002428
Douglas Gregorb98b1992009-08-11 05:31:07 +00002429 /// \brief Build a new shuffle vector expression.
2430 ///
2431 /// By default, performs semantic analysis to build the new expression.
2432 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002433 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002434 MultiExprArg SubExprs,
2435 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002436 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002437 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002438 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2439 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2440 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002441 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002442
Douglas Gregorb98b1992009-08-11 05:31:07 +00002443 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002444 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002445 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2446 SemaRef.Context.BuiltinFnTy,
2447 VK_RValue, BuiltinLoc);
2448 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2449 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2450 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002451
2452 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002453 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002454 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002455 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002456 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002457 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002458
Douglas Gregorb98b1992009-08-11 05:31:07 +00002459 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002460 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002461 }
John McCall43fed0d2010-11-12 08:19:04 +00002462
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002463 /// \brief Build a new template argument pack expansion.
2464 ///
2465 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002466 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002467 /// different behavior.
2468 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002469 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002470 Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002471 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002472 case TemplateArgument::Expression: {
2473 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002474 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2475 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002476 if (Result.isInvalid())
2477 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002478
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002479 return TemplateArgumentLoc(Result.get(), Result.get());
2480 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002481
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002482 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002483 return TemplateArgumentLoc(TemplateArgument(
2484 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002485 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002486 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002487 Pattern.getTemplateNameLoc(),
2488 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002489
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002490 case TemplateArgument::Null:
2491 case TemplateArgument::Integral:
2492 case TemplateArgument::Declaration:
2493 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002494 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002495 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002496 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002497
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002498 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002499 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002500 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002501 EllipsisLoc,
2502 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002503 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2504 Expansion);
2505 break;
2506 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002507
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002508 return TemplateArgumentLoc();
2509 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002510
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002511 /// \brief Build a new expression pack expansion.
2512 ///
2513 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002514 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002515 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002516 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002517 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002518 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002519 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002520
2521 /// \brief Build a new atomic operation expression.
2522 ///
2523 /// By default, performs semantic analysis to build the new expression.
2524 /// Subclasses may override this routine to provide different behavior.
2525 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2526 MultiExprArg SubExprs,
2527 QualType RetTy,
2528 AtomicExpr::AtomicOp Op,
2529 SourceLocation RParenLoc) {
2530 // Just create the expression; there is not any interesting semantic
2531 // analysis here because we can't actually build an AtomicExpr until
2532 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002533 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002534 RParenLoc);
2535 }
2536
John McCall43fed0d2010-11-12 08:19:04 +00002537private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002538 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2539 QualType ObjectType,
2540 NamedDecl *FirstQualifierInScope,
2541 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002542
2543 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2544 QualType ObjectType,
2545 NamedDecl *FirstQualifierInScope,
2546 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002547};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002548
Douglas Gregor43959a92009-08-20 07:17:43 +00002549template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002550StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002551 if (!S)
2552 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002553
Douglas Gregor43959a92009-08-20 07:17:43 +00002554 switch (S->getStmtClass()) {
2555 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002556
Douglas Gregor43959a92009-08-20 07:17:43 +00002557 // Transform individual statement nodes
2558#define STMT(Node, Parent) \
2559 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002560#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002561#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002562#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002563
Douglas Gregor43959a92009-08-20 07:17:43 +00002564 // Transform expressions by calling TransformExpr.
2565#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002566#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002567#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002568#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002569 {
John McCall60d7b3a2010-08-24 06:29:42 +00002570 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002571 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002572 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002573
Richard Smith41956372013-01-14 22:39:08 +00002574 return getSema().ActOnExprStmt(E);
Douglas Gregor43959a92009-08-20 07:17:43 +00002575 }
Mike Stump1eb44332009-09-09 15:08:12 +00002576 }
2577
John McCall3fa5cae2010-10-26 07:05:15 +00002578 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002579}
Mike Stump1eb44332009-09-09 15:08:12 +00002580
2581
Douglas Gregor670444e2009-08-04 22:27:00 +00002582template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002583ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002584 if (!E)
2585 return SemaRef.Owned(E);
2586
2587 switch (E->getStmtClass()) {
2588 case Stmt::NoStmtClass: break;
2589#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002590#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002591#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002592 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002593#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002594 }
2595
John McCall3fa5cae2010-10-26 07:05:15 +00002596 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002597}
2598
2599template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002600ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2601 bool CXXDirectInit) {
2602 // Initializers are instantiated like expressions, except that various outer
2603 // layers are stripped.
2604 if (!Init)
2605 return SemaRef.Owned(Init);
2606
2607 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2608 Init = ExprTemp->getSubExpr();
2609
2610 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2611 Init = Binder->getSubExpr();
2612
2613 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2614 Init = ICE->getSubExprAsWritten();
2615
Richard Smith5cf15892012-12-21 08:13:35 +00002616 // If this is not a direct-initializer, we only need to reconstruct
2617 // InitListExprs. Other forms of copy-initialization will be a no-op if
2618 // the initializer is already the right type.
2619 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2620 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2621 return getDerived().TransformExpr(Init);
2622
2623 // Revert value-initialization back to empty parens.
2624 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2625 SourceRange Parens = VIE->getSourceRange();
2626 return getDerived().RebuildParenListExpr(Parens.getBegin(), MultiExprArg(),
2627 Parens.getEnd());
2628 }
2629
2630 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2631 if (isa<ImplicitValueInitExpr>(Init))
2632 return getDerived().RebuildParenListExpr(SourceLocation(), MultiExprArg(),
2633 SourceLocation());
2634
2635 // Revert initialization by constructor back to a parenthesized or braced list
2636 // of expressions. Any other form of initializer can just be reused directly.
2637 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002638 return getDerived().TransformExpr(Init);
2639
2640 SmallVector<Expr*, 8> NewArgs;
2641 bool ArgChanged = false;
2642 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2643 /*IsCall*/true, NewArgs, &ArgChanged))
2644 return ExprError();
2645
2646 // If this was list initialization, revert to list form.
2647 if (Construct->isListInitialization())
2648 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2649 Construct->getLocEnd(),
2650 Construct->getType());
2651
Richard Smithc83c2302012-12-19 01:39:02 +00002652 // Build a ParenListExpr to represent anything else.
2653 SourceRange Parens = Construct->getParenRange();
2654 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2655 Parens.getEnd());
2656}
2657
2658template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002659bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2660 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002661 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002662 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002663 bool *ArgChanged) {
2664 for (unsigned I = 0; I != NumInputs; ++I) {
2665 // If requested, drop call arguments that need to be dropped.
2666 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2667 if (ArgChanged)
2668 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002669
Douglas Gregoraa165f82011-01-03 19:04:46 +00002670 break;
2671 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002672
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002673 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2674 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002675
Chris Lattner686775d2011-07-20 06:58:45 +00002676 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002677 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2678 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002679
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002680 // Determine whether the set of unexpanded parameter packs can and should
2681 // be expanded.
2682 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002683 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00002684 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2685 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002686 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2687 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002688 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002689 Expand, RetainExpansion,
2690 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002691 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002692
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002693 if (!Expand) {
2694 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002695 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002696 // expansion.
2697 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2698 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2699 if (OutPattern.isInvalid())
2700 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002701
2702 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002703 Expansion->getEllipsisLoc(),
2704 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002705 if (Out.isInvalid())
2706 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002707
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002708 if (ArgChanged)
2709 *ArgChanged = true;
2710 Outputs.push_back(Out.get());
2711 continue;
2712 }
John McCallc8fc90a2011-07-06 07:30:07 +00002713
2714 // Record right away that the argument was changed. This needs
2715 // to happen even if the array expands to nothing.
2716 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002717
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002718 // The transform has determined that we should perform an elementwise
2719 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002720 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002721 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2722 ExprResult Out = getDerived().TransformExpr(Pattern);
2723 if (Out.isInvalid())
2724 return true;
2725
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002726 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002727 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2728 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002729 if (Out.isInvalid())
2730 return true;
2731 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002732
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002733 Outputs.push_back(Out.get());
2734 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002735
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002736 continue;
2737 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002738
Richard Smithc83c2302012-12-19 01:39:02 +00002739 ExprResult Result =
2740 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2741 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002742 if (Result.isInvalid())
2743 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002744
Douglas Gregoraa165f82011-01-03 19:04:46 +00002745 if (Result.get() != Inputs[I] && ArgChanged)
2746 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002747
2748 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002749 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002750
Douglas Gregoraa165f82011-01-03 19:04:46 +00002751 return false;
2752}
2753
2754template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002755NestedNameSpecifierLoc
2756TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2757 NestedNameSpecifierLoc NNS,
2758 QualType ObjectType,
2759 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002760 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002761 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002762 Qualifier = Qualifier.getPrefix())
2763 Qualifiers.push_back(Qualifier);
2764
2765 CXXScopeSpec SS;
2766 while (!Qualifiers.empty()) {
2767 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2768 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002769
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002770 switch (QNNS->getKind()) {
2771 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002772 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002773 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002774 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002775 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002776 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002777 FirstQualifierInScope, false))
2778 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002779
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002780 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002781
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002782 case NestedNameSpecifier::Namespace: {
2783 NamespaceDecl *NS
2784 = cast_or_null<NamespaceDecl>(
2785 getDerived().TransformDecl(
2786 Q.getLocalBeginLoc(),
2787 QNNS->getAsNamespace()));
2788 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2789 break;
2790 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002791
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002792 case NestedNameSpecifier::NamespaceAlias: {
2793 NamespaceAliasDecl *Alias
2794 = cast_or_null<NamespaceAliasDecl>(
2795 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2796 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002797 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002798 Q.getLocalEndLoc());
2799 break;
2800 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002801
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002802 case NestedNameSpecifier::Global:
2803 // There is no meaningful transformation that one could perform on the
2804 // global scope.
2805 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2806 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002807
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002808 case NestedNameSpecifier::TypeSpecWithTemplate:
2809 case NestedNameSpecifier::TypeSpec: {
2810 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2811 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002812
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002813 if (!TL)
2814 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002815
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002816 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002817 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002818 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002819 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002820 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002821 if (TL.getType()->isEnumeralType())
2822 SemaRef.Diag(TL.getBeginLoc(),
2823 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002824 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2825 Q.getLocalEndLoc());
2826 break;
2827 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002828 // If the nested-name-specifier is an invalid type def, don't emit an
2829 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002830 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2831 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002832 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002833 << TL.getType() << SS.getRange();
2834 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002835 return NestedNameSpecifierLoc();
2836 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002837 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002838
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002839 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002840 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002841 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002842 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002843
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002844 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002845 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002846 !getDerived().AlwaysRebuild())
2847 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002848
2849 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002850 // nested-name-specifier, do so.
2851 if (SS.location_size() == NNS.getDataLength() &&
2852 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2853 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2854
2855 // Allocate new nested-name-specifier location information.
2856 return SS.getWithLocInContext(SemaRef.Context);
2857}
2858
2859template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002860DeclarationNameInfo
2861TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002862::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002863 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002864 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002865 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002866
2867 switch (Name.getNameKind()) {
2868 case DeclarationName::Identifier:
2869 case DeclarationName::ObjCZeroArgSelector:
2870 case DeclarationName::ObjCOneArgSelector:
2871 case DeclarationName::ObjCMultiArgSelector:
2872 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002873 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002874 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002875 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002876
Douglas Gregor81499bb2009-09-03 22:13:48 +00002877 case DeclarationName::CXXConstructorName:
2878 case DeclarationName::CXXDestructorName:
2879 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002880 TypeSourceInfo *NewTInfo;
2881 CanQualType NewCanTy;
2882 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002883 NewTInfo = getDerived().TransformType(OldTInfo);
2884 if (!NewTInfo)
2885 return DeclarationNameInfo();
2886 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002887 }
2888 else {
2889 NewTInfo = 0;
2890 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002891 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002892 if (NewT.isNull())
2893 return DeclarationNameInfo();
2894 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2895 }
Mike Stump1eb44332009-09-09 15:08:12 +00002896
Abramo Bagnara25777432010-08-11 22:01:17 +00002897 DeclarationName NewName
2898 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2899 NewCanTy);
2900 DeclarationNameInfo NewNameInfo(NameInfo);
2901 NewNameInfo.setName(NewName);
2902 NewNameInfo.setNamedTypeInfo(NewTInfo);
2903 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002904 }
Mike Stump1eb44332009-09-09 15:08:12 +00002905 }
2906
David Blaikieb219cfc2011-09-23 05:06:16 +00002907 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002908}
2909
2910template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002911TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002912TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2913 TemplateName Name,
2914 SourceLocation NameLoc,
2915 QualType ObjectType,
2916 NamedDecl *FirstQualifierInScope) {
2917 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2918 TemplateDecl *Template = QTN->getTemplateDecl();
2919 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002920
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002921 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002922 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002923 Template));
2924 if (!TransTemplate)
2925 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002926
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002927 if (!getDerived().AlwaysRebuild() &&
2928 SS.getScopeRep() == QTN->getQualifier() &&
2929 TransTemplate == Template)
2930 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002931
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002932 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2933 TransTemplate);
2934 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002935
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002936 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2937 if (SS.getScopeRep()) {
2938 // These apply to the scope specifier, not the template.
2939 ObjectType = QualType();
2940 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002941 }
2942
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002943 if (!getDerived().AlwaysRebuild() &&
2944 SS.getScopeRep() == DTN->getQualifier() &&
2945 ObjectType.isNull())
2946 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002947
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002948 if (DTN->isIdentifier()) {
2949 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002950 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002951 NameLoc,
2952 ObjectType,
2953 FirstQualifierInScope);
2954 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002955
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002956 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2957 ObjectType);
2958 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002959
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002960 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2961 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002962 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002963 Template));
2964 if (!TransTemplate)
2965 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002966
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002967 if (!getDerived().AlwaysRebuild() &&
2968 TransTemplate == Template)
2969 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002970
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002971 return TemplateName(TransTemplate);
2972 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002973
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002974 if (SubstTemplateTemplateParmPackStorage *SubstPack
2975 = Name.getAsSubstTemplateTemplateParmPack()) {
2976 TemplateTemplateParmDecl *TransParam
2977 = cast_or_null<TemplateTemplateParmDecl>(
2978 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2979 if (!TransParam)
2980 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002981
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002982 if (!getDerived().AlwaysRebuild() &&
2983 TransParam == SubstPack->getParameterPack())
2984 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002985
2986 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002987 SubstPack->getArgumentPack());
2988 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002989
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002990 // These should be getting filtered out before they reach the AST.
2991 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002992}
2993
2994template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002995void TreeTransform<Derived>::InventTemplateArgumentLoc(
2996 const TemplateArgument &Arg,
2997 TemplateArgumentLoc &Output) {
2998 SourceLocation Loc = getDerived().getBaseLocation();
2999 switch (Arg.getKind()) {
3000 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003001 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00003002 break;
3003
3004 case TemplateArgument::Type:
3005 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00003006 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00003007
John McCall833ca992009-10-29 08:12:44 +00003008 break;
3009
Douglas Gregor788cd062009-11-11 01:00:40 +00003010 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003011 case TemplateArgument::TemplateExpansion: {
3012 NestedNameSpecifierLocBuilder Builder;
3013 TemplateName Template = Arg.getAsTemplate();
3014 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3015 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3016 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3017 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003018
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003019 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003020 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003021 Builder.getWithLocInContext(SemaRef.Context),
3022 Loc);
3023 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003024 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003025 Builder.getWithLocInContext(SemaRef.Context),
3026 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003027
Douglas Gregor788cd062009-11-11 01:00:40 +00003028 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003029 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003030
John McCall833ca992009-10-29 08:12:44 +00003031 case TemplateArgument::Expression:
3032 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3033 break;
3034
3035 case TemplateArgument::Declaration:
3036 case TemplateArgument::Integral:
3037 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003038 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003039 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003040 break;
3041 }
3042}
3043
3044template<typename Derived>
3045bool TreeTransform<Derived>::TransformTemplateArgument(
3046 const TemplateArgumentLoc &Input,
3047 TemplateArgumentLoc &Output) {
3048 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003049 switch (Arg.getKind()) {
3050 case TemplateArgument::Null:
3051 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003052 case TemplateArgument::Pack:
3053 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003054 case TemplateArgument::NullPtr:
3055 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003056
Douglas Gregor670444e2009-08-04 22:27:00 +00003057 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003058 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003059 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003060 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003061
3062 DI = getDerived().TransformType(DI);
3063 if (!DI) return true;
3064
3065 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3066 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003067 }
Mike Stump1eb44332009-09-09 15:08:12 +00003068
Douglas Gregor788cd062009-11-11 01:00:40 +00003069 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003070 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3071 if (QualifierLoc) {
3072 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3073 if (!QualifierLoc)
3074 return true;
3075 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003076
Douglas Gregor1d752d72011-03-02 18:46:51 +00003077 CXXScopeSpec SS;
3078 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003079 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003080 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3081 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003082 if (Template.isNull())
3083 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003084
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003085 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003086 Input.getTemplateNameLoc());
3087 return false;
3088 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003089
3090 case TemplateArgument::TemplateExpansion:
3091 llvm_unreachable("Caller should expand pack expansions");
3092
Douglas Gregor670444e2009-08-04 22:27:00 +00003093 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003094 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003095 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003096 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003097
John McCall833ca992009-10-29 08:12:44 +00003098 Expr *InputExpr = Input.getSourceExpression();
3099 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3100
Chris Lattner223de242011-04-25 20:37:58 +00003101 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003102 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003103 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003104 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003105 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003106 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003107 }
Mike Stump1eb44332009-09-09 15:08:12 +00003108
Douglas Gregor670444e2009-08-04 22:27:00 +00003109 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003110 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003111}
3112
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003113/// \brief Iterator adaptor that invents template argument location information
3114/// for each of the template arguments in its underlying iterator.
3115template<typename Derived, typename InputIterator>
3116class TemplateArgumentLocInventIterator {
3117 TreeTransform<Derived> &Self;
3118 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003119
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003120public:
3121 typedef TemplateArgumentLoc value_type;
3122 typedef TemplateArgumentLoc reference;
3123 typedef typename std::iterator_traits<InputIterator>::difference_type
3124 difference_type;
3125 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003126
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003127 class pointer {
3128 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003129
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003130 public:
3131 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003132
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003133 const TemplateArgumentLoc *operator->() const { return &Arg; }
3134 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003135
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003136 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003137
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003138 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3139 InputIterator Iter)
3140 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003141
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003142 TemplateArgumentLocInventIterator &operator++() {
3143 ++Iter;
3144 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003145 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003146
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003147 TemplateArgumentLocInventIterator operator++(int) {
3148 TemplateArgumentLocInventIterator Old(*this);
3149 ++(*this);
3150 return Old;
3151 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003152
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003153 reference operator*() const {
3154 TemplateArgumentLoc Result;
3155 Self.InventTemplateArgumentLoc(*Iter, Result);
3156 return Result;
3157 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003158
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003159 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003160
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003161 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3162 const TemplateArgumentLocInventIterator &Y) {
3163 return X.Iter == Y.Iter;
3164 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003165
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003166 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3167 const TemplateArgumentLocInventIterator &Y) {
3168 return X.Iter != Y.Iter;
3169 }
3170};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003171
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003172template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003173template<typename InputIterator>
3174bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3175 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003176 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003177 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003178 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003179 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003180
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003181 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3182 // Unpack argument packs, which we translate them into separate
3183 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003184 // FIXME: We could do much better if we could guarantee that the
3185 // TemplateArgumentLocInfo for the pack expansion would be usable for
3186 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003187 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003188 TemplateArgument::pack_iterator>
3189 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003190 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003191 In.getArgument().pack_begin()),
3192 PackLocIterator(*this,
3193 In.getArgument().pack_end()),
3194 Outputs))
3195 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003196
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003197 continue;
3198 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003199
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003200 if (In.getArgument().isPackExpansion()) {
3201 // We have a pack expansion, for which we will be substituting into
3202 // the pattern.
3203 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003204 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003205 TemplateArgumentLoc Pattern
Chad Rosier4a9d7952012-08-08 18:46:20 +00003206 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
Douglas Gregorcded4f62011-01-14 17:04:44 +00003207 getSema().Context);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003208
Chris Lattner686775d2011-07-20 06:58:45 +00003209 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003210 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3211 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003212
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003213 // Determine whether the set of unexpanded parameter packs can and should
3214 // be expanded.
3215 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003216 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003217 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003218 if (getDerived().TryExpandParameterPacks(Ellipsis,
3219 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003220 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003221 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003222 RetainExpansion,
3223 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003224 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003225
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003226 if (!Expand) {
3227 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003228 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003229 // expansion.
3230 TemplateArgumentLoc OutPattern;
3231 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3232 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3233 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003234
Douglas Gregorcded4f62011-01-14 17:04:44 +00003235 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3236 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003237 if (Out.getArgument().isNull())
3238 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003239
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003240 Outputs.addArgument(Out);
3241 continue;
3242 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003243
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003244 // The transform has determined that we should perform an elementwise
3245 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003246 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003247 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3248
3249 if (getDerived().TransformTemplateArgument(Pattern, Out))
3250 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003251
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003252 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003253 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3254 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003255 if (Out.getArgument().isNull())
3256 return true;
3257 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003258
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003259 Outputs.addArgument(Out);
3260 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003261
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003262 // If we're supposed to retain a pack expansion, do so by temporarily
3263 // forgetting the partially-substituted parameter pack.
3264 if (RetainExpansion) {
3265 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003266
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003267 if (getDerived().TransformTemplateArgument(Pattern, Out))
3268 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003269
Douglas Gregorcded4f62011-01-14 17:04:44 +00003270 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3271 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003272 if (Out.getArgument().isNull())
3273 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003274
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003275 Outputs.addArgument(Out);
3276 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003277
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003278 continue;
3279 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003280
3281 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003282 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003283 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003284
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003285 Outputs.addArgument(Out);
3286 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003287
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003288 return false;
3289
3290}
3291
Douglas Gregor577f75a2009-08-04 16:50:30 +00003292//===----------------------------------------------------------------------===//
3293// Type transformation
3294//===----------------------------------------------------------------------===//
3295
3296template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003297QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003298 if (getDerived().AlreadyTransformed(T))
3299 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003300
John McCalla2becad2009-10-21 00:40:46 +00003301 // Temporary workaround. All of these transformations should
3302 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003303 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3304 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003305
John McCall43fed0d2010-11-12 08:19:04 +00003306 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003307
John McCalla2becad2009-10-21 00:40:46 +00003308 if (!NewDI)
3309 return QualType();
3310
3311 return NewDI->getType();
3312}
3313
3314template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003315TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003316 // Refine the base location to the type's location.
3317 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3318 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003319 if (getDerived().AlreadyTransformed(DI->getType()))
3320 return DI;
3321
3322 TypeLocBuilder TLB;
3323
3324 TypeLoc TL = DI->getTypeLoc();
3325 TLB.reserve(TL.getFullDataSize());
3326
John McCall43fed0d2010-11-12 08:19:04 +00003327 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003328 if (Result.isNull())
3329 return 0;
3330
John McCalla93c9342009-12-07 02:54:59 +00003331 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003332}
3333
3334template<typename Derived>
3335QualType
John McCall43fed0d2010-11-12 08:19:04 +00003336TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003337 switch (T.getTypeLocClass()) {
3338#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003339#define TYPELOC(CLASS, PARENT) \
3340 case TypeLoc::CLASS: \
3341 return getDerived().Transform##CLASS##Type(TLB, \
3342 T.castAs<CLASS##TypeLoc>());
John McCalla2becad2009-10-21 00:40:46 +00003343#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003344 }
Mike Stump1eb44332009-09-09 15:08:12 +00003345
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003346 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003347}
3348
3349/// FIXME: By default, this routine adds type qualifiers only to types
3350/// that can have qualifiers, and silently suppresses those qualifiers
3351/// that are not permitted (e.g., qualifiers on reference or function
3352/// types). This is the right thing for template instantiation, but
3353/// probably not for other clients.
3354template<typename Derived>
3355QualType
3356TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003357 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003358 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003359
John McCall43fed0d2010-11-12 08:19:04 +00003360 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003361 if (Result.isNull())
3362 return QualType();
3363
3364 // Silently suppress qualifiers if the result type can't be qualified.
3365 // FIXME: this is the right thing for template instantiation, but
3366 // probably not for other clients.
3367 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003368 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003369
John McCallf85e1932011-06-15 23:02:42 +00003370 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003371 // resulting type.
3372 if (Quals.hasObjCLifetime()) {
3373 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3374 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003375 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003376 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003377 // A lifetime qualifier applied to a substituted template parameter
3378 // overrides the lifetime qualifier from the template argument.
Douglas Gregor92d13872013-01-17 23:59:28 +00003379 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003380 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003381 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3382 QualType Replacement = SubstTypeParam->getReplacementType();
3383 Qualifiers Qs = Replacement.getQualifiers();
3384 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003385 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003386 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3387 Qs);
3388 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003389 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003390 Replacement);
3391 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003392 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3393 // 'auto' types behave the same way as template parameters.
3394 QualType Deduced = AutoTy->getDeducedType();
3395 Qualifiers Qs = Deduced.getQualifiers();
3396 Qs.removeObjCLifetime();
3397 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3398 Qs);
3399 Result = SemaRef.Context.getAutoType(Deduced);
3400 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003401 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003402 // Otherwise, complain about the addition of a qualifier to an
3403 // already-qualified type.
3404 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003405 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003406 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003407
Douglas Gregore559ca12011-06-17 22:11:49 +00003408 Quals.removeObjCLifetime();
3409 }
3410 }
3411 }
John McCall28654742010-06-05 06:41:15 +00003412 if (!Quals.empty()) {
3413 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smith9807a2e2013-03-27 23:36:39 +00003414 // BuildQualifiedType might not add qualifiers if they are invalid.
3415 if (Result.hasLocalQualifiers())
3416 TLB.push<QualifiedTypeLoc>(Result);
John McCall28654742010-06-05 06:41:15 +00003417 // No location information to preserve.
3418 }
John McCalla2becad2009-10-21 00:40:46 +00003419
3420 return Result;
3421}
3422
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003423template<typename Derived>
3424TypeLoc
3425TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3426 QualType ObjectType,
3427 NamedDecl *UnqualLookup,
3428 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003429 QualType T = TL.getType();
3430 if (getDerived().AlreadyTransformed(T))
3431 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003432
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003433 TypeLocBuilder TLB;
3434 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003435
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003436 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003437 TemplateSpecializationTypeLoc SpecTL =
3438 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003439
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003440 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003441 getDerived().TransformTemplateName(SS,
3442 SpecTL.getTypePtr()->getTemplateName(),
3443 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003444 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003445 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003446 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003447
3448 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003449 Template);
3450 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003451 DependentTemplateSpecializationTypeLoc SpecTL =
3452 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003453
Douglas Gregora88f09f2011-02-28 17:23:35 +00003454 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003455 = getDerived().RebuildTemplateName(SS,
3456 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003457 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003458 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003459 if (Template.isNull())
3460 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003461
3462 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003463 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003464 Template,
3465 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003466 } else {
3467 // Nothing special needs to be done for these.
3468 Result = getDerived().TransformType(TLB, TL);
3469 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003470
3471 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003472 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003473
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003474 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3475}
3476
Douglas Gregorb71d8212011-03-02 18:32:08 +00003477template<typename Derived>
3478TypeSourceInfo *
3479TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3480 QualType ObjectType,
3481 NamedDecl *UnqualLookup,
3482 CXXScopeSpec &SS) {
3483 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003484
Douglas Gregorb71d8212011-03-02 18:32:08 +00003485 QualType T = TSInfo->getType();
3486 if (getDerived().AlreadyTransformed(T))
3487 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003488
Douglas Gregorb71d8212011-03-02 18:32:08 +00003489 TypeLocBuilder TLB;
3490 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003491
Douglas Gregorb71d8212011-03-02 18:32:08 +00003492 TypeLoc TL = TSInfo->getTypeLoc();
3493 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003494 TemplateSpecializationTypeLoc SpecTL =
3495 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003496
Douglas Gregorb71d8212011-03-02 18:32:08 +00003497 TemplateName Template
3498 = getDerived().TransformTemplateName(SS,
3499 SpecTL.getTypePtr()->getTemplateName(),
3500 SpecTL.getTemplateNameLoc(),
3501 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003502 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003503 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003504
3505 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003506 Template);
3507 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003508 DependentTemplateSpecializationTypeLoc SpecTL =
3509 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003510
Douglas Gregorb71d8212011-03-02 18:32:08 +00003511 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003512 = getDerived().RebuildTemplateName(SS,
3513 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003514 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003515 ObjectType, UnqualLookup);
3516 if (Template.isNull())
3517 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003518
3519 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003520 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003521 Template,
3522 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003523 } else {
3524 // Nothing special needs to be done for these.
3525 Result = getDerived().TransformType(TLB, TL);
3526 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003527
3528 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003529 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003530
Douglas Gregorb71d8212011-03-02 18:32:08 +00003531 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3532}
3533
John McCalla2becad2009-10-21 00:40:46 +00003534template <class TyLoc> static inline
3535QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3536 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3537 NewT.setNameLoc(T.getNameLoc());
3538 return T.getType();
3539}
3540
John McCalla2becad2009-10-21 00:40:46 +00003541template<typename Derived>
3542QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003543 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003544 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3545 NewT.setBuiltinLoc(T.getBuiltinLoc());
3546 if (T.needsExtraLocalData())
3547 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3548 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003549}
Mike Stump1eb44332009-09-09 15:08:12 +00003550
Douglas Gregor577f75a2009-08-04 16:50:30 +00003551template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003552QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003553 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003554 // FIXME: recurse?
3555 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003556}
Mike Stump1eb44332009-09-09 15:08:12 +00003557
Douglas Gregor577f75a2009-08-04 16:50:30 +00003558template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003559QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003560 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003561 QualType PointeeType
3562 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003563 if (PointeeType.isNull())
3564 return QualType();
3565
3566 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003567 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003568 // A dependent pointer type 'T *' has is being transformed such
3569 // that an Objective-C class type is being replaced for 'T'. The
3570 // resulting pointer type is an ObjCObjectPointerType, not a
3571 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003572 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003573
John McCallc12c5bb2010-05-15 11:32:37 +00003574 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3575 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003576 return Result;
3577 }
John McCall43fed0d2010-11-12 08:19:04 +00003578
Douglas Gregor92e986e2010-04-22 16:44:27 +00003579 if (getDerived().AlwaysRebuild() ||
3580 PointeeType != TL.getPointeeLoc().getType()) {
3581 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3582 if (Result.isNull())
3583 return QualType();
3584 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003585
John McCallf85e1932011-06-15 23:02:42 +00003586 // Objective-C ARC can add lifetime qualifiers to the type that we're
3587 // pointing to.
3588 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003589
Douglas Gregor92e986e2010-04-22 16:44:27 +00003590 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3591 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003592 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003593}
Mike Stump1eb44332009-09-09 15:08:12 +00003594
3595template<typename Derived>
3596QualType
John McCalla2becad2009-10-21 00:40:46 +00003597TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003598 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003599 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003600 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3601 if (PointeeType.isNull())
3602 return QualType();
3603
3604 QualType Result = TL.getType();
3605 if (getDerived().AlwaysRebuild() ||
3606 PointeeType != TL.getPointeeLoc().getType()) {
3607 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003608 TL.getSigilLoc());
3609 if (Result.isNull())
3610 return QualType();
3611 }
3612
Douglas Gregor39968ad2010-04-22 16:50:51 +00003613 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003614 NewT.setSigilLoc(TL.getSigilLoc());
3615 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003616}
3617
John McCall85737a72009-10-30 00:06:24 +00003618/// Transforms a reference type. Note that somewhat paradoxically we
3619/// don't care whether the type itself is an l-value type or an r-value
3620/// type; we only care if the type was *written* as an l-value type
3621/// or an r-value type.
3622template<typename Derived>
3623QualType
3624TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003625 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003626 const ReferenceType *T = TL.getTypePtr();
3627
3628 // Note that this works with the pointee-as-written.
3629 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3630 if (PointeeType.isNull())
3631 return QualType();
3632
3633 QualType Result = TL.getType();
3634 if (getDerived().AlwaysRebuild() ||
3635 PointeeType != T->getPointeeTypeAsWritten()) {
3636 Result = getDerived().RebuildReferenceType(PointeeType,
3637 T->isSpelledAsLValue(),
3638 TL.getSigilLoc());
3639 if (Result.isNull())
3640 return QualType();
3641 }
3642
John McCallf85e1932011-06-15 23:02:42 +00003643 // Objective-C ARC can add lifetime qualifiers to the type that we're
3644 // referring to.
3645 TLB.TypeWasModifiedSafely(
3646 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3647
John McCall85737a72009-10-30 00:06:24 +00003648 // r-value references can be rebuilt as l-value references.
3649 ReferenceTypeLoc NewTL;
3650 if (isa<LValueReferenceType>(Result))
3651 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3652 else
3653 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3654 NewTL.setSigilLoc(TL.getSigilLoc());
3655
3656 return Result;
3657}
3658
Mike Stump1eb44332009-09-09 15:08:12 +00003659template<typename Derived>
3660QualType
John McCalla2becad2009-10-21 00:40:46 +00003661TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003662 LValueReferenceTypeLoc TL) {
3663 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003664}
3665
Mike Stump1eb44332009-09-09 15:08:12 +00003666template<typename Derived>
3667QualType
John McCalla2becad2009-10-21 00:40:46 +00003668TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003669 RValueReferenceTypeLoc TL) {
3670 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003671}
Mike Stump1eb44332009-09-09 15:08:12 +00003672
Douglas Gregor577f75a2009-08-04 16:50:30 +00003673template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003674QualType
John McCalla2becad2009-10-21 00:40:46 +00003675TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003676 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003677 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003678 if (PointeeType.isNull())
3679 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003680
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003681 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3682 TypeSourceInfo* NewClsTInfo = 0;
3683 if (OldClsTInfo) {
3684 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3685 if (!NewClsTInfo)
3686 return QualType();
3687 }
3688
3689 const MemberPointerType *T = TL.getTypePtr();
3690 QualType OldClsType = QualType(T->getClass(), 0);
3691 QualType NewClsType;
3692 if (NewClsTInfo)
3693 NewClsType = NewClsTInfo->getType();
3694 else {
3695 NewClsType = getDerived().TransformType(OldClsType);
3696 if (NewClsType.isNull())
3697 return QualType();
3698 }
Mike Stump1eb44332009-09-09 15:08:12 +00003699
John McCalla2becad2009-10-21 00:40:46 +00003700 QualType Result = TL.getType();
3701 if (getDerived().AlwaysRebuild() ||
3702 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003703 NewClsType != OldClsType) {
3704 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003705 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003706 if (Result.isNull())
3707 return QualType();
3708 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003709
John McCalla2becad2009-10-21 00:40:46 +00003710 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3711 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003712 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003713
3714 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003715}
3716
Mike Stump1eb44332009-09-09 15:08:12 +00003717template<typename Derived>
3718QualType
John McCalla2becad2009-10-21 00:40:46 +00003719TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003720 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003721 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003722 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003723 if (ElementType.isNull())
3724 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003725
John McCalla2becad2009-10-21 00:40:46 +00003726 QualType Result = TL.getType();
3727 if (getDerived().AlwaysRebuild() ||
3728 ElementType != T->getElementType()) {
3729 Result = getDerived().RebuildConstantArrayType(ElementType,
3730 T->getSizeModifier(),
3731 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003732 T->getIndexTypeCVRQualifiers(),
3733 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003734 if (Result.isNull())
3735 return QualType();
3736 }
Eli Friedman457a3772012-01-25 22:19:07 +00003737
3738 // We might have either a ConstantArrayType or a VariableArrayType now:
3739 // a ConstantArrayType is allowed to have an element type which is a
3740 // VariableArrayType if the type is dependent. Fortunately, all array
3741 // types have the same location layout.
3742 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003743 NewTL.setLBracketLoc(TL.getLBracketLoc());
3744 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003745
John McCalla2becad2009-10-21 00:40:46 +00003746 Expr *Size = TL.getSizeExpr();
3747 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003748 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3749 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003750 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003751 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003752 }
3753 NewTL.setSizeExpr(Size);
3754
3755 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003756}
Mike Stump1eb44332009-09-09 15:08:12 +00003757
Douglas Gregor577f75a2009-08-04 16:50:30 +00003758template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003759QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003760 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003761 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003762 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003763 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003764 if (ElementType.isNull())
3765 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003766
John McCalla2becad2009-10-21 00:40:46 +00003767 QualType Result = TL.getType();
3768 if (getDerived().AlwaysRebuild() ||
3769 ElementType != T->getElementType()) {
3770 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003771 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003772 T->getIndexTypeCVRQualifiers(),
3773 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003774 if (Result.isNull())
3775 return QualType();
3776 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003777
John McCalla2becad2009-10-21 00:40:46 +00003778 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3779 NewTL.setLBracketLoc(TL.getLBracketLoc());
3780 NewTL.setRBracketLoc(TL.getRBracketLoc());
3781 NewTL.setSizeExpr(0);
3782
3783 return Result;
3784}
3785
3786template<typename Derived>
3787QualType
3788TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003789 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003790 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003791 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3792 if (ElementType.isNull())
3793 return QualType();
3794
John McCall60d7b3a2010-08-24 06:29:42 +00003795 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003796 = getDerived().TransformExpr(T->getSizeExpr());
3797 if (SizeResult.isInvalid())
3798 return QualType();
3799
John McCall9ae2f072010-08-23 23:25:46 +00003800 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003801
3802 QualType Result = TL.getType();
3803 if (getDerived().AlwaysRebuild() ||
3804 ElementType != T->getElementType() ||
3805 Size != T->getSizeExpr()) {
3806 Result = getDerived().RebuildVariableArrayType(ElementType,
3807 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003808 Size,
John McCalla2becad2009-10-21 00:40:46 +00003809 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003810 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003811 if (Result.isNull())
3812 return QualType();
3813 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003814
John McCalla2becad2009-10-21 00:40:46 +00003815 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3816 NewTL.setLBracketLoc(TL.getLBracketLoc());
3817 NewTL.setRBracketLoc(TL.getRBracketLoc());
3818 NewTL.setSizeExpr(Size);
3819
3820 return Result;
3821}
3822
3823template<typename Derived>
3824QualType
3825TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003826 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003827 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003828 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3829 if (ElementType.isNull())
3830 return QualType();
3831
Richard Smithf6702a32011-12-20 02:08:33 +00003832 // Array bounds are constant expressions.
3833 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3834 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003835
John McCall3b657512011-01-19 10:06:00 +00003836 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3837 Expr *origSize = TL.getSizeExpr();
3838 if (!origSize) origSize = T->getSizeExpr();
3839
3840 ExprResult sizeResult
3841 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003842 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003843 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003844 return QualType();
3845
John McCall3b657512011-01-19 10:06:00 +00003846 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003847
3848 QualType Result = TL.getType();
3849 if (getDerived().AlwaysRebuild() ||
3850 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003851 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003852 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3853 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003854 size,
John McCalla2becad2009-10-21 00:40:46 +00003855 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003856 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003857 if (Result.isNull())
3858 return QualType();
3859 }
John McCalla2becad2009-10-21 00:40:46 +00003860
3861 // We might have any sort of array type now, but fortunately they
3862 // all have the same location layout.
3863 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3864 NewTL.setLBracketLoc(TL.getLBracketLoc());
3865 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003866 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003867
3868 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003869}
Mike Stump1eb44332009-09-09 15:08:12 +00003870
3871template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003872QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003873 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003874 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003875 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003876
3877 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003878 QualType ElementType = getDerived().TransformType(T->getElementType());
3879 if (ElementType.isNull())
3880 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003881
Richard Smithf6702a32011-12-20 02:08:33 +00003882 // Vector sizes are constant expressions.
3883 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3884 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003885
John McCall60d7b3a2010-08-24 06:29:42 +00003886 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003887 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003888 if (Size.isInvalid())
3889 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003890
John McCalla2becad2009-10-21 00:40:46 +00003891 QualType Result = TL.getType();
3892 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003893 ElementType != T->getElementType() ||
3894 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003895 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003896 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003897 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003898 if (Result.isNull())
3899 return QualType();
3900 }
John McCalla2becad2009-10-21 00:40:46 +00003901
3902 // Result might be dependent or not.
3903 if (isa<DependentSizedExtVectorType>(Result)) {
3904 DependentSizedExtVectorTypeLoc NewTL
3905 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3906 NewTL.setNameLoc(TL.getNameLoc());
3907 } else {
3908 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3909 NewTL.setNameLoc(TL.getNameLoc());
3910 }
3911
3912 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003913}
Mike Stump1eb44332009-09-09 15:08:12 +00003914
3915template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003916QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003917 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003918 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003919 QualType ElementType = getDerived().TransformType(T->getElementType());
3920 if (ElementType.isNull())
3921 return QualType();
3922
John McCalla2becad2009-10-21 00:40:46 +00003923 QualType Result = TL.getType();
3924 if (getDerived().AlwaysRebuild() ||
3925 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003926 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003927 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003928 if (Result.isNull())
3929 return QualType();
3930 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003931
John McCalla2becad2009-10-21 00:40:46 +00003932 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3933 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003934
John McCalla2becad2009-10-21 00:40:46 +00003935 return Result;
3936}
3937
3938template<typename Derived>
3939QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003940 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003941 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003942 QualType ElementType = getDerived().TransformType(T->getElementType());
3943 if (ElementType.isNull())
3944 return QualType();
3945
3946 QualType Result = TL.getType();
3947 if (getDerived().AlwaysRebuild() ||
3948 ElementType != T->getElementType()) {
3949 Result = getDerived().RebuildExtVectorType(ElementType,
3950 T->getNumElements(),
3951 /*FIXME*/ SourceLocation());
3952 if (Result.isNull())
3953 return QualType();
3954 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003955
John McCalla2becad2009-10-21 00:40:46 +00003956 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3957 NewTL.setNameLoc(TL.getNameLoc());
3958
3959 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003960}
Mike Stump1eb44332009-09-09 15:08:12 +00003961
David Blaikiedc84cd52013-02-20 22:23:23 +00003962template <typename Derived>
3963ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
3964 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
3965 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003966 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003967 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003968
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003969 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003970 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003971 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003972 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00003973 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003974
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003975 TypeLocBuilder TLB;
3976 TypeLoc NewTL = OldDI->getTypeLoc();
3977 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003978
3979 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003980 OldExpansionTL.getPatternLoc());
3981 if (Result.isNull())
3982 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003983
3984 Result = RebuildPackExpansionType(Result,
3985 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003986 OldExpansionTL.getEllipsisLoc(),
3987 NumExpansions);
3988 if (Result.isNull())
3989 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003990
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003991 PackExpansionTypeLoc NewExpansionTL
3992 = TLB.push<PackExpansionTypeLoc>(Result);
3993 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3994 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3995 } else
3996 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003997 if (!NewDI)
3998 return 0;
3999
John McCallfb44de92011-05-01 22:35:37 +00004000 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00004001 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00004002
4003 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4004 OldParm->getDeclContext(),
4005 OldParm->getInnerLocStart(),
4006 OldParm->getLocation(),
4007 OldParm->getIdentifier(),
4008 NewDI->getType(),
4009 NewDI,
4010 OldParm->getStorageClass(),
John McCallfb44de92011-05-01 22:35:37 +00004011 /* DefArg */ NULL);
4012 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4013 OldParm->getFunctionScopeIndex() + indexAdjustment);
4014 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004015}
4016
4017template<typename Derived>
4018bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004019 TransformFunctionTypeParams(SourceLocation Loc,
4020 ParmVarDecl **Params, unsigned NumParams,
4021 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004022 SmallVectorImpl<QualType> &OutParamTypes,
4023 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004024 int indexAdjustment = 0;
4025
Douglas Gregora009b592011-01-07 00:20:55 +00004026 for (unsigned i = 0; i != NumParams; ++i) {
4027 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004028 assert(OldParm->getFunctionScopeIndex() == i);
4029
David Blaikiedc84cd52013-02-20 22:23:23 +00004030 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004031 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004032 if (OldParm->isParameterPack()) {
4033 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004034 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004035
Douglas Gregor603cfb42011-01-05 23:12:31 +00004036 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004037 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004038 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004039 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4040 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004041 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4042
Douglas Gregor603cfb42011-01-05 23:12:31 +00004043 // Determine whether we should expand the parameter packs.
4044 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004045 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004046 Optional<unsigned> OrigNumExpansions =
4047 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004048 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004049 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4050 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004051 Unexpanded,
4052 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004053 RetainExpansion,
4054 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004055 return true;
4056 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004057
Douglas Gregor603cfb42011-01-05 23:12:31 +00004058 if (ShouldExpand) {
4059 // Expand the function parameter pack into multiple, separate
4060 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004061 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004062 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004063 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004064 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004065 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004066 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004067 OrigNumExpansions,
4068 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004069 if (!NewParm)
4070 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004071
Douglas Gregora009b592011-01-07 00:20:55 +00004072 OutParamTypes.push_back(NewParm->getType());
4073 if (PVars)
4074 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004075 }
Douglas Gregord3731192011-01-10 07:32:04 +00004076
4077 // If we're supposed to retain a pack expansion, do so by temporarily
4078 // forgetting the partially-substituted parameter pack.
4079 if (RetainExpansion) {
4080 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004081 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004082 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004083 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004084 OrigNumExpansions,
4085 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004086 if (!NewParm)
4087 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004088
Douglas Gregord3731192011-01-10 07:32:04 +00004089 OutParamTypes.push_back(NewParm->getType());
4090 if (PVars)
4091 PVars->push_back(NewParm);
4092 }
4093
John McCallfb44de92011-05-01 22:35:37 +00004094 // The next parameter should have the same adjustment as the
4095 // last thing we pushed, but we post-incremented indexAdjustment
4096 // on every push. Also, if we push nothing, the adjustment should
4097 // go down by one.
4098 indexAdjustment--;
4099
Douglas Gregor603cfb42011-01-05 23:12:31 +00004100 // We're done with the pack expansion.
4101 continue;
4102 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004103
4104 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004105 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004106 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4107 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004108 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004109 NumExpansions,
4110 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004111 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004112 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004113 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004114 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004115
John McCall21ef0fa2010-03-11 09:03:00 +00004116 if (!NewParm)
4117 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004118
Douglas Gregora009b592011-01-07 00:20:55 +00004119 OutParamTypes.push_back(NewParm->getType());
4120 if (PVars)
4121 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004122 continue;
4123 }
John McCall21ef0fa2010-03-11 09:03:00 +00004124
4125 // Deal with the possibility that we don't have a parameter
4126 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004127 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004128 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004129 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004130 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004131 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004132 = dyn_cast<PackExpansionType>(OldType)) {
4133 // We have a function parameter pack that may need to be expanded.
4134 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004135 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004136 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004137
Douglas Gregor603cfb42011-01-05 23:12:31 +00004138 // Determine whether we should expand the parameter packs.
4139 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004140 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004141 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004142 Unexpanded,
4143 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004144 RetainExpansion,
4145 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004146 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004147 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004148
Douglas Gregor603cfb42011-01-05 23:12:31 +00004149 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004150 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004151 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004152 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004153 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4154 QualType NewType = getDerived().TransformType(Pattern);
4155 if (NewType.isNull())
4156 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004157
Douglas Gregora009b592011-01-07 00:20:55 +00004158 OutParamTypes.push_back(NewType);
4159 if (PVars)
4160 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004161 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004162
Douglas Gregor603cfb42011-01-05 23:12:31 +00004163 // We're done with the pack expansion.
4164 continue;
4165 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004166
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004167 // If we're supposed to retain a pack expansion, do so by temporarily
4168 // forgetting the partially-substituted parameter pack.
4169 if (RetainExpansion) {
4170 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4171 QualType NewType = getDerived().TransformType(Pattern);
4172 if (NewType.isNull())
4173 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004174
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004175 OutParamTypes.push_back(NewType);
4176 if (PVars)
4177 PVars->push_back(0);
4178 }
Douglas Gregord3731192011-01-10 07:32:04 +00004179
Chad Rosier4a9d7952012-08-08 18:46:20 +00004180 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004181 // expansion.
4182 OldType = Expansion->getPattern();
4183 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004184 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4185 NewType = getDerived().TransformType(OldType);
4186 } else {
4187 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004188 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004189
Douglas Gregor603cfb42011-01-05 23:12:31 +00004190 if (NewType.isNull())
4191 return true;
4192
4193 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004194 NewType = getSema().Context.getPackExpansionType(NewType,
4195 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004196
Douglas Gregora009b592011-01-07 00:20:55 +00004197 OutParamTypes.push_back(NewType);
4198 if (PVars)
4199 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004200 }
4201
John McCallfb44de92011-05-01 22:35:37 +00004202#ifndef NDEBUG
4203 if (PVars) {
4204 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4205 if (ParmVarDecl *parm = (*PVars)[i])
4206 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004207 }
John McCallfb44de92011-05-01 22:35:37 +00004208#endif
4209
4210 return false;
4211}
John McCall21ef0fa2010-03-11 09:03:00 +00004212
4213template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004214QualType
John McCalla2becad2009-10-21 00:40:46 +00004215TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004216 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004217 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4218}
4219
4220template<typename Derived>
4221QualType
4222TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4223 FunctionProtoTypeLoc TL,
4224 CXXRecordDecl *ThisContext,
4225 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004226 // Transform the parameters and return type.
4227 //
Richard Smithe6975e92012-04-17 00:58:00 +00004228 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004229 // When the function has a trailing return type, we instantiate the
4230 // parameters before the return type, since the return type can then refer
4231 // to the parameters themselves (via decltype, sizeof, etc.).
4232 //
Chris Lattner686775d2011-07-20 06:58:45 +00004233 SmallVector<QualType, 4> ParamTypes;
4234 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004235 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004236
Douglas Gregordab60ad2010-10-01 18:44:50 +00004237 QualType ResultType;
4238
Richard Smith9fbf3272012-08-14 22:51:13 +00004239 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004240 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004241 TL.getParmArray(),
4242 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004243 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004244 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004245 return QualType();
4246
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004247 {
4248 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004249 // If a declaration declares a member function or member function
4250 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004251 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004252 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004253 // declarator.
4254 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004255
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004256 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4257 if (ResultType.isNull())
4258 return QualType();
4259 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004260 }
4261 else {
4262 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4263 if (ResultType.isNull())
4264 return QualType();
4265
Chad Rosier4a9d7952012-08-08 18:46:20 +00004266 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004267 TL.getParmArray(),
4268 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004269 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004270 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004271 return QualType();
4272 }
4273
Richard Smithe6975e92012-04-17 00:58:00 +00004274 // FIXME: Need to transform the exception-specification too.
4275
John McCalla2becad2009-10-21 00:40:46 +00004276 QualType Result = TL.getType();
4277 if (getDerived().AlwaysRebuild() ||
4278 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004279 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004280 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004281 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004282 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004283 if (Result.isNull())
4284 return QualType();
4285 }
Mike Stump1eb44332009-09-09 15:08:12 +00004286
John McCalla2becad2009-10-21 00:40:46 +00004287 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004288 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004289 NewTL.setLParenLoc(TL.getLParenLoc());
4290 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004291 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004292 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4293 NewTL.setArg(i, ParamDecls[i]);
4294
4295 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004296}
Mike Stump1eb44332009-09-09 15:08:12 +00004297
Douglas Gregor577f75a2009-08-04 16:50:30 +00004298template<typename Derived>
4299QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004300 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004301 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004302 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004303 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4304 if (ResultType.isNull())
4305 return QualType();
4306
4307 QualType Result = TL.getType();
4308 if (getDerived().AlwaysRebuild() ||
4309 ResultType != T->getResultType())
4310 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4311
4312 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004313 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004314 NewTL.setLParenLoc(TL.getLParenLoc());
4315 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004316 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004317
4318 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004319}
Mike Stump1eb44332009-09-09 15:08:12 +00004320
John McCalled976492009-12-04 22:46:56 +00004321template<typename Derived> QualType
4322TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004323 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004324 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004325 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004326 if (!D)
4327 return QualType();
4328
4329 QualType Result = TL.getType();
4330 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4331 Result = getDerived().RebuildUnresolvedUsingType(D);
4332 if (Result.isNull())
4333 return QualType();
4334 }
4335
4336 // We might get an arbitrary type spec type back. We should at
4337 // least always get a type spec type, though.
4338 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4339 NewTL.setNameLoc(TL.getNameLoc());
4340
4341 return Result;
4342}
4343
Douglas Gregor577f75a2009-08-04 16:50:30 +00004344template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004345QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004346 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004347 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004348 TypedefNameDecl *Typedef
4349 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4350 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004351 if (!Typedef)
4352 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004353
John McCalla2becad2009-10-21 00:40:46 +00004354 QualType Result = TL.getType();
4355 if (getDerived().AlwaysRebuild() ||
4356 Typedef != T->getDecl()) {
4357 Result = getDerived().RebuildTypedefType(Typedef);
4358 if (Result.isNull())
4359 return QualType();
4360 }
Mike Stump1eb44332009-09-09 15:08:12 +00004361
John McCalla2becad2009-10-21 00:40:46 +00004362 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4363 NewTL.setNameLoc(TL.getNameLoc());
4364
4365 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004366}
Mike Stump1eb44332009-09-09 15:08:12 +00004367
Douglas Gregor577f75a2009-08-04 16:50:30 +00004368template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004369QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004370 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004371 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004372 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4373 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004374
John McCall60d7b3a2010-08-24 06:29:42 +00004375 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004376 if (E.isInvalid())
4377 return QualType();
4378
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004379 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4380 if (E.isInvalid())
4381 return QualType();
4382
John McCalla2becad2009-10-21 00:40:46 +00004383 QualType Result = TL.getType();
4384 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004385 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004386 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004387 if (Result.isNull())
4388 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004389 }
John McCalla2becad2009-10-21 00:40:46 +00004390 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004391
John McCalla2becad2009-10-21 00:40:46 +00004392 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004393 NewTL.setTypeofLoc(TL.getTypeofLoc());
4394 NewTL.setLParenLoc(TL.getLParenLoc());
4395 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004396
4397 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004398}
Mike Stump1eb44332009-09-09 15:08:12 +00004399
4400template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004401QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004402 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004403 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4404 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4405 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004406 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004407
John McCalla2becad2009-10-21 00:40:46 +00004408 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004409 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4410 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004411 if (Result.isNull())
4412 return QualType();
4413 }
Mike Stump1eb44332009-09-09 15:08:12 +00004414
John McCalla2becad2009-10-21 00:40:46 +00004415 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004416 NewTL.setTypeofLoc(TL.getTypeofLoc());
4417 NewTL.setLParenLoc(TL.getLParenLoc());
4418 NewTL.setRParenLoc(TL.getRParenLoc());
4419 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004420
4421 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004422}
Mike Stump1eb44332009-09-09 15:08:12 +00004423
4424template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004425QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004426 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004427 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004428
Douglas Gregor670444e2009-08-04 22:27:00 +00004429 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004430 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4431 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004432
John McCall60d7b3a2010-08-24 06:29:42 +00004433 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004434 if (E.isInvalid())
4435 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004436
Richard Smith76f3f692012-02-22 02:04:18 +00004437 E = getSema().ActOnDecltypeExpression(E.take());
4438 if (E.isInvalid())
4439 return QualType();
4440
John McCalla2becad2009-10-21 00:40:46 +00004441 QualType Result = TL.getType();
4442 if (getDerived().AlwaysRebuild() ||
4443 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004444 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004445 if (Result.isNull())
4446 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004447 }
John McCalla2becad2009-10-21 00:40:46 +00004448 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004449
John McCalla2becad2009-10-21 00:40:46 +00004450 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4451 NewTL.setNameLoc(TL.getNameLoc());
4452
4453 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004454}
4455
4456template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004457QualType TreeTransform<Derived>::TransformUnaryTransformType(
4458 TypeLocBuilder &TLB,
4459 UnaryTransformTypeLoc TL) {
4460 QualType Result = TL.getType();
4461 if (Result->isDependentType()) {
4462 const UnaryTransformType *T = TL.getTypePtr();
4463 QualType NewBase =
4464 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4465 Result = getDerived().RebuildUnaryTransformType(NewBase,
4466 T->getUTTKind(),
4467 TL.getKWLoc());
4468 if (Result.isNull())
4469 return QualType();
4470 }
4471
4472 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4473 NewTL.setKWLoc(TL.getKWLoc());
4474 NewTL.setParensRange(TL.getParensRange());
4475 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4476 return Result;
4477}
4478
4479template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004480QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4481 AutoTypeLoc TL) {
4482 const AutoType *T = TL.getTypePtr();
4483 QualType OldDeduced = T->getDeducedType();
4484 QualType NewDeduced;
4485 if (!OldDeduced.isNull()) {
4486 NewDeduced = getDerived().TransformType(OldDeduced);
4487 if (NewDeduced.isNull())
4488 return QualType();
4489 }
4490
4491 QualType Result = TL.getType();
4492 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4493 Result = getDerived().RebuildAutoType(NewDeduced);
4494 if (Result.isNull())
4495 return QualType();
4496 }
4497
4498 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4499 NewTL.setNameLoc(TL.getNameLoc());
4500
4501 return Result;
4502}
4503
4504template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004505QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004506 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004507 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004508 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004509 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4510 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004511 if (!Record)
4512 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004513
John McCalla2becad2009-10-21 00:40:46 +00004514 QualType Result = TL.getType();
4515 if (getDerived().AlwaysRebuild() ||
4516 Record != T->getDecl()) {
4517 Result = getDerived().RebuildRecordType(Record);
4518 if (Result.isNull())
4519 return QualType();
4520 }
Mike Stump1eb44332009-09-09 15:08:12 +00004521
John McCalla2becad2009-10-21 00:40:46 +00004522 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4523 NewTL.setNameLoc(TL.getNameLoc());
4524
4525 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004526}
Mike Stump1eb44332009-09-09 15:08:12 +00004527
4528template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004529QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004530 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004531 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004532 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004533 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4534 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004535 if (!Enum)
4536 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004537
John McCalla2becad2009-10-21 00:40:46 +00004538 QualType Result = TL.getType();
4539 if (getDerived().AlwaysRebuild() ||
4540 Enum != T->getDecl()) {
4541 Result = getDerived().RebuildEnumType(Enum);
4542 if (Result.isNull())
4543 return QualType();
4544 }
Mike Stump1eb44332009-09-09 15:08:12 +00004545
John McCalla2becad2009-10-21 00:40:46 +00004546 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4547 NewTL.setNameLoc(TL.getNameLoc());
4548
4549 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004550}
John McCall7da24312009-09-05 00:15:47 +00004551
John McCall3cb0ebd2010-03-10 03:28:59 +00004552template<typename Derived>
4553QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4554 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004555 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004556 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4557 TL.getTypePtr()->getDecl());
4558 if (!D) return QualType();
4559
4560 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4561 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4562 return T;
4563}
4564
Douglas Gregor577f75a2009-08-04 16:50:30 +00004565template<typename Derived>
4566QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004567 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004568 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004569 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004570}
4571
Mike Stump1eb44332009-09-09 15:08:12 +00004572template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004573QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004574 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004575 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004576 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004577
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004578 // Substitute into the replacement type, which itself might involve something
4579 // that needs to be transformed. This only tends to occur with default
4580 // template arguments of template template parameters.
4581 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4582 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4583 if (Replacement.isNull())
4584 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004585
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004586 // Always canonicalize the replacement type.
4587 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4588 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004589 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004590 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004591
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004592 // Propagate type-source information.
4593 SubstTemplateTypeParmTypeLoc NewTL
4594 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4595 NewTL.setNameLoc(TL.getNameLoc());
4596 return Result;
4597
John McCall49a832b2009-10-18 09:09:24 +00004598}
4599
4600template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004601QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4602 TypeLocBuilder &TLB,
4603 SubstTemplateTypeParmPackTypeLoc TL) {
4604 return TransformTypeSpecType(TLB, TL);
4605}
4606
4607template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004608QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004609 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004610 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004611 const TemplateSpecializationType *T = TL.getTypePtr();
4612
Douglas Gregor1d752d72011-03-02 18:46:51 +00004613 // The nested-name-specifier never matters in a TemplateSpecializationType,
4614 // because we can't have a dependent nested-name-specifier anyway.
4615 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004616 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004617 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4618 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004619 if (Template.isNull())
4620 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004621
John McCall43fed0d2010-11-12 08:19:04 +00004622 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4623}
4624
Eli Friedmanb001de72011-10-06 23:00:33 +00004625template<typename Derived>
4626QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4627 AtomicTypeLoc TL) {
4628 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4629 if (ValueType.isNull())
4630 return QualType();
4631
4632 QualType Result = TL.getType();
4633 if (getDerived().AlwaysRebuild() ||
4634 ValueType != TL.getValueLoc().getType()) {
4635 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4636 if (Result.isNull())
4637 return QualType();
4638 }
4639
4640 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4641 NewTL.setKWLoc(TL.getKWLoc());
4642 NewTL.setLParenLoc(TL.getLParenLoc());
4643 NewTL.setRParenLoc(TL.getRParenLoc());
4644
4645 return Result;
4646}
4647
Chad Rosier4a9d7952012-08-08 18:46:20 +00004648 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004649 /// container that provides a \c getArgLoc() member function.
4650 ///
4651 /// This iterator is intended to be used with the iterator form of
4652 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4653 template<typename ArgLocContainer>
4654 class TemplateArgumentLocContainerIterator {
4655 ArgLocContainer *Container;
4656 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004657
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004658 public:
4659 typedef TemplateArgumentLoc value_type;
4660 typedef TemplateArgumentLoc reference;
4661 typedef int difference_type;
4662 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004663
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004664 class pointer {
4665 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004666
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004667 public:
4668 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004669
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004670 const TemplateArgumentLoc *operator->() const {
4671 return &Arg;
4672 }
4673 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004674
4675
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004676 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004677
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004678 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4679 unsigned Index)
4680 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004681
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004682 TemplateArgumentLocContainerIterator &operator++() {
4683 ++Index;
4684 return *this;
4685 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004686
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004687 TemplateArgumentLocContainerIterator operator++(int) {
4688 TemplateArgumentLocContainerIterator Old(*this);
4689 ++(*this);
4690 return Old;
4691 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004692
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004693 TemplateArgumentLoc operator*() const {
4694 return Container->getArgLoc(Index);
4695 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004696
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004697 pointer operator->() const {
4698 return pointer(Container->getArgLoc(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.Container == Y.Container && X.Index == Y.Index;
4704 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004705
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004706 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004707 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004708 return !(X == Y);
4709 }
4710 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004711
4712
John McCall43fed0d2010-11-12 08:19:04 +00004713template <typename Derived>
4714QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4715 TypeLocBuilder &TLB,
4716 TemplateSpecializationTypeLoc TL,
4717 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004718 TemplateArgumentListInfo NewTemplateArgs;
4719 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4720 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004721 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4722 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004723 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004724 ArgIterator(TL, TL.getNumArgs()),
4725 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004726 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004727
John McCall833ca992009-10-29 08:12:44 +00004728 // FIXME: maybe don't rebuild if all the template arguments are the same.
4729
4730 QualType Result =
4731 getDerived().RebuildTemplateSpecializationType(Template,
4732 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004733 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004734
4735 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004736 // Specializations of template template parameters are represented as
4737 // TemplateSpecializationTypes, and substitution of type alias templates
4738 // within a dependent context can transform them into
4739 // DependentTemplateSpecializationTypes.
4740 if (isa<DependentTemplateSpecializationType>(Result)) {
4741 DependentTemplateSpecializationTypeLoc NewTL
4742 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004743 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004744 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004745 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004746 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004747 NewTL.setLAngleLoc(TL.getLAngleLoc());
4748 NewTL.setRAngleLoc(TL.getRAngleLoc());
4749 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4750 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4751 return Result;
4752 }
4753
John McCall833ca992009-10-29 08:12:44 +00004754 TemplateSpecializationTypeLoc NewTL
4755 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004756 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004757 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4758 NewTL.setLAngleLoc(TL.getLAngleLoc());
4759 NewTL.setRAngleLoc(TL.getRAngleLoc());
4760 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4761 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004762 }
Mike Stump1eb44332009-09-09 15:08:12 +00004763
John McCall833ca992009-10-29 08:12:44 +00004764 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004765}
Mike Stump1eb44332009-09-09 15:08:12 +00004766
Douglas Gregora88f09f2011-02-28 17:23:35 +00004767template <typename Derived>
4768QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4769 TypeLocBuilder &TLB,
4770 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004771 TemplateName Template,
4772 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004773 TemplateArgumentListInfo NewTemplateArgs;
4774 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4775 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4776 typedef TemplateArgumentLocContainerIterator<
4777 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004778 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004779 ArgIterator(TL, TL.getNumArgs()),
4780 NewTemplateArgs))
4781 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004782
Douglas Gregora88f09f2011-02-28 17:23:35 +00004783 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004784
Douglas Gregora88f09f2011-02-28 17:23:35 +00004785 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4786 QualType Result
4787 = getSema().Context.getDependentTemplateSpecializationType(
4788 TL.getTypePtr()->getKeyword(),
4789 DTN->getQualifier(),
4790 DTN->getIdentifier(),
4791 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004792
Douglas Gregora88f09f2011-02-28 17:23:35 +00004793 DependentTemplateSpecializationTypeLoc NewTL
4794 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004795 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004796 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004797 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004798 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004799 NewTL.setLAngleLoc(TL.getLAngleLoc());
4800 NewTL.setRAngleLoc(TL.getRAngleLoc());
4801 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4802 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4803 return Result;
4804 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004805
4806 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004807 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004808 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004809 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004810
Douglas Gregora88f09f2011-02-28 17:23:35 +00004811 if (!Result.isNull()) {
4812 /// FIXME: Wrap this in an elaborated-type-specifier?
4813 TemplateSpecializationTypeLoc NewTL
4814 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004815 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004816 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004817 NewTL.setLAngleLoc(TL.getLAngleLoc());
4818 NewTL.setRAngleLoc(TL.getRAngleLoc());
4819 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4820 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4821 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004822
Douglas Gregora88f09f2011-02-28 17:23:35 +00004823 return Result;
4824}
4825
Mike Stump1eb44332009-09-09 15:08:12 +00004826template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004827QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004828TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004829 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004830 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004831
Douglas Gregor9e876872011-03-01 18:12:44 +00004832 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004833 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004834 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004835 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004836 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4837 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004838 return QualType();
4839 }
Mike Stump1eb44332009-09-09 15:08:12 +00004840
John McCall43fed0d2010-11-12 08:19:04 +00004841 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4842 if (NamedT.isNull())
4843 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004844
Richard Smith3e4c6c42011-05-05 21:57:07 +00004845 // C++0x [dcl.type.elab]p2:
4846 // If the identifier resolves to a typedef-name or the simple-template-id
4847 // resolves to an alias template specialization, the
4848 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004849 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4850 if (const TemplateSpecializationType *TST =
4851 NamedT->getAs<TemplateSpecializationType>()) {
4852 TemplateName Template = TST->getTemplateName();
4853 if (TypeAliasTemplateDecl *TAT =
4854 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4855 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4856 diag::err_tag_reference_non_tag) << 4;
4857 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4858 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004859 }
4860 }
4861
John McCalla2becad2009-10-21 00:40:46 +00004862 QualType Result = TL.getType();
4863 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004864 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004865 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004866 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004867 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004868 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004869 if (Result.isNull())
4870 return QualType();
4871 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004872
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004873 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004874 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004875 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004876 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004877}
Mike Stump1eb44332009-09-09 15:08:12 +00004878
4879template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004880QualType TreeTransform<Derived>::TransformAttributedType(
4881 TypeLocBuilder &TLB,
4882 AttributedTypeLoc TL) {
4883 const AttributedType *oldType = TL.getTypePtr();
4884 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4885 if (modifiedType.isNull())
4886 return QualType();
4887
4888 QualType result = TL.getType();
4889
4890 // FIXME: dependent operand expressions?
4891 if (getDerived().AlwaysRebuild() ||
4892 modifiedType != oldType->getModifiedType()) {
4893 // TODO: this is really lame; we should really be rebuilding the
4894 // equivalent type from first principles.
4895 QualType equivalentType
4896 = getDerived().TransformType(oldType->getEquivalentType());
4897 if (equivalentType.isNull())
4898 return QualType();
4899 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4900 modifiedType,
4901 equivalentType);
4902 }
4903
4904 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4905 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4906 if (TL.hasAttrOperand())
4907 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4908 if (TL.hasAttrExprOperand())
4909 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4910 else if (TL.hasAttrEnumOperand())
4911 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4912
4913 return result;
4914}
4915
4916template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004917QualType
4918TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4919 ParenTypeLoc TL) {
4920 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4921 if (Inner.isNull())
4922 return QualType();
4923
4924 QualType Result = TL.getType();
4925 if (getDerived().AlwaysRebuild() ||
4926 Inner != TL.getInnerLoc().getType()) {
4927 Result = getDerived().RebuildParenType(Inner);
4928 if (Result.isNull())
4929 return QualType();
4930 }
4931
4932 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4933 NewTL.setLParenLoc(TL.getLParenLoc());
4934 NewTL.setRParenLoc(TL.getRParenLoc());
4935 return Result;
4936}
4937
4938template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004939QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004940 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004941 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004942
Douglas Gregor2494dd02011-03-01 01:34:45 +00004943 NestedNameSpecifierLoc QualifierLoc
4944 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4945 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004946 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004947
John McCall33500952010-06-11 00:33:02 +00004948 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004949 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004950 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004951 QualifierLoc,
4952 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004953 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004954 if (Result.isNull())
4955 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004956
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004957 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4958 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004959 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4960
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004961 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004962 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004963 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004964 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004965 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004966 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004967 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004968 NewTL.setNameLoc(TL.getNameLoc());
4969 }
John McCalla2becad2009-10-21 00:40:46 +00004970 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004971}
Mike Stump1eb44332009-09-09 15:08:12 +00004972
Douglas Gregor577f75a2009-08-04 16:50:30 +00004973template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004974QualType TreeTransform<Derived>::
4975 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004976 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004977 NestedNameSpecifierLoc QualifierLoc;
4978 if (TL.getQualifierLoc()) {
4979 QualifierLoc
4980 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4981 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004982 return QualType();
4983 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004984
John McCall43fed0d2010-11-12 08:19:04 +00004985 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004986 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004987}
4988
4989template<typename Derived>
4990QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004991TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4992 DependentTemplateSpecializationTypeLoc TL,
4993 NestedNameSpecifierLoc QualifierLoc) {
4994 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004995
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004996 TemplateArgumentListInfo NewTemplateArgs;
4997 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4998 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004999
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005000 typedef TemplateArgumentLocContainerIterator<
5001 DependentTemplateSpecializationTypeLoc> ArgIterator;
5002 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5003 ArgIterator(TL, TL.getNumArgs()),
5004 NewTemplateArgs))
5005 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005006
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005007 QualType Result
5008 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5009 QualifierLoc,
5010 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005011 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005012 NewTemplateArgs);
5013 if (Result.isNull())
5014 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005015
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005016 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5017 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005018
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005019 // Copy information relevant to the template specialization.
5020 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005021 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005022 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005023 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005024 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5025 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005026 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005027 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005028
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005029 // Copy information relevant to the elaborated type.
5030 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005031 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005032 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005033 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5034 DependentTemplateSpecializationTypeLoc SpecTL
5035 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005036 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005037 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005038 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005039 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005040 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5041 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005042 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005043 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005044 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005045 TemplateSpecializationTypeLoc SpecTL
5046 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005047 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005048 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005049 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5050 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005051 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005052 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005053 }
5054 return Result;
5055}
5056
5057template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005058QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5059 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005060 QualType Pattern
5061 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005062 if (Pattern.isNull())
5063 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005064
5065 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005066 if (getDerived().AlwaysRebuild() ||
5067 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005068 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005069 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005070 TL.getEllipsisLoc(),
5071 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005072 if (Result.isNull())
5073 return QualType();
5074 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005075
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005076 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5077 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5078 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005079}
5080
5081template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005082QualType
5083TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005084 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005085 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005086 TLB.pushFullCopy(TL);
5087 return TL.getType();
5088}
5089
5090template<typename Derived>
5091QualType
5092TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005093 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005094 // ObjCObjectType is never dependent.
5095 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005096 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005097}
Mike Stump1eb44332009-09-09 15:08:12 +00005098
5099template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005100QualType
5101TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005102 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005103 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005104 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005105 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005106}
5107
Douglas Gregor577f75a2009-08-04 16:50:30 +00005108//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005109// Statement transformation
5110//===----------------------------------------------------------------------===//
5111template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005112StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005113TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005114 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005115}
5116
5117template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005118StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005119TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5120 return getDerived().TransformCompoundStmt(S, false);
5121}
5122
5123template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005124StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005125TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005126 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005127 Sema::CompoundScopeRAII CompoundScope(getSema());
5128
John McCall7114cba2010-08-27 19:56:05 +00005129 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005130 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005131 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005132 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5133 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005134 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005135 if (Result.isInvalid()) {
5136 // Immediately fail if this was a DeclStmt, since it's very
5137 // likely that this will cause problems for future statements.
5138 if (isa<DeclStmt>(*B))
5139 return StmtError();
5140
5141 // Otherwise, just keep processing substatements and fail later.
5142 SubStmtInvalid = true;
5143 continue;
5144 }
Mike Stump1eb44332009-09-09 15:08:12 +00005145
Douglas Gregor43959a92009-08-20 07:17:43 +00005146 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5147 Statements.push_back(Result.takeAs<Stmt>());
5148 }
Mike Stump1eb44332009-09-09 15:08:12 +00005149
John McCall7114cba2010-08-27 19:56:05 +00005150 if (SubStmtInvalid)
5151 return StmtError();
5152
Douglas Gregor43959a92009-08-20 07:17:43 +00005153 if (!getDerived().AlwaysRebuild() &&
5154 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005155 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005156
5157 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005158 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005159 S->getRBracLoc(),
5160 IsStmtExpr);
5161}
Mike Stump1eb44332009-09-09 15:08:12 +00005162
Douglas Gregor43959a92009-08-20 07:17:43 +00005163template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005164StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005165TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005166 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005167 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005168 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5169 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005170
Eli Friedman264c1f82009-11-19 03:14:00 +00005171 // Transform the left-hand case value.
5172 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005173 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005174 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005175 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005176
Eli Friedman264c1f82009-11-19 03:14:00 +00005177 // Transform the right-hand case value (for the GNU case-range extension).
5178 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005179 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005180 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005181 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005182 }
Mike Stump1eb44332009-09-09 15:08:12 +00005183
Douglas Gregor43959a92009-08-20 07:17:43 +00005184 // Build the case statement.
5185 // Case statements are always rebuilt so that they will attached to their
5186 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005187 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005188 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005189 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005190 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005191 S->getColonLoc());
5192 if (Case.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 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005196 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005197 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005198 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005199
Douglas Gregor43959a92009-08-20 07:17:43 +00005200 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005201 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005202}
5203
5204template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005205StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005206TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005207 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005208 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005209 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005210 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005211
Douglas Gregor43959a92009-08-20 07:17:43 +00005212 // Default statements are always rebuilt
5213 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005214 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005215}
Mike Stump1eb44332009-09-09 15:08:12 +00005216
Douglas Gregor43959a92009-08-20 07:17:43 +00005217template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005218StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005219TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005220 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005221 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005222 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005223
Chris Lattner57ad3782011-02-17 20:34:02 +00005224 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5225 S->getDecl());
5226 if (!LD)
5227 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005228
5229
Douglas Gregor43959a92009-08-20 07:17:43 +00005230 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005231 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005232 cast<LabelDecl>(LD), SourceLocation(),
5233 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005234}
Mike Stump1eb44332009-09-09 15:08:12 +00005235
Douglas Gregor43959a92009-08-20 07:17:43 +00005236template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005237StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005238TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5239 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5240 if (SubStmt.isInvalid())
5241 return StmtError();
5242
5243 // TODO: transform attributes
5244 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5245 return S;
5246
5247 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5248 S->getAttrs(),
5249 SubStmt.get());
5250}
5251
5252template<typename Derived>
5253StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005254TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005255 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005256 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005257 VarDecl *ConditionVar = 0;
5258 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005259 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005260 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005261 getDerived().TransformDefinition(
5262 S->getConditionVariable()->getLocation(),
5263 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005264 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005265 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005266 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005267 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005268
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005269 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005270 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005271
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005272 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005273 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005274 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005275 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005276 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005277 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005278
John McCall9ae2f072010-08-23 23:25:46 +00005279 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005280 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005281 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005282
John McCall9ae2f072010-08-23 23:25:46 +00005283 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5284 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005285 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005286
Douglas Gregor43959a92009-08-20 07:17:43 +00005287 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005288 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005289 if (Then.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 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005293 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005294 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005295 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005296
Douglas Gregor43959a92009-08-20 07:17:43 +00005297 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005298 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005299 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005300 Then.get() == S->getThen() &&
5301 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005302 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005303
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005304 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005305 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005306 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005307}
5308
5309template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005310StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005311TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005312 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005313 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005314 VarDecl *ConditionVar = 0;
5315 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005316 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005317 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005318 getDerived().TransformDefinition(
5319 S->getConditionVariable()->getLocation(),
5320 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005321 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005322 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005323 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005324 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005325
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005326 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005327 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005328 }
Mike Stump1eb44332009-09-09 15:08:12 +00005329
Douglas Gregor43959a92009-08-20 07:17:43 +00005330 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005331 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005332 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005333 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005334 if (Switch.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 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005338 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005339 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005340 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005341
Douglas Gregor43959a92009-08-20 07:17:43 +00005342 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005343 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5344 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005345}
Mike Stump1eb44332009-09-09 15:08:12 +00005346
Douglas Gregor43959a92009-08-20 07:17:43 +00005347template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005348StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005349TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005350 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005351 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005352 VarDecl *ConditionVar = 0;
5353 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005354 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005355 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005356 getDerived().TransformDefinition(
5357 S->getConditionVariable()->getLocation(),
5358 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005359 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005360 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005361 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005362 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005363
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005364 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005365 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005366
5367 if (S->getCond()) {
5368 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005369 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005370 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005371 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005372 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005373 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005374 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005375 }
Mike Stump1eb44332009-09-09 15:08:12 +00005376
John McCall9ae2f072010-08-23 23:25:46 +00005377 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5378 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005379 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005380
Douglas Gregor43959a92009-08-20 07:17:43 +00005381 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005382 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005383 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005384 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005385
Douglas Gregor43959a92009-08-20 07:17:43 +00005386 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005387 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005388 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005389 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005390 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005391
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005392 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005393 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005394}
Mike Stump1eb44332009-09-09 15:08:12 +00005395
Douglas Gregor43959a92009-08-20 07:17:43 +00005396template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005397StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005398TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005399 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005400 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005401 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005402 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005403
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005404 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005405 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005406 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005407 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005408
Douglas Gregor43959a92009-08-20 07:17:43 +00005409 if (!getDerived().AlwaysRebuild() &&
5410 Cond.get() == S->getCond() &&
5411 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005412 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005413
John McCall9ae2f072010-08-23 23:25:46 +00005414 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5415 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005416 S->getRParenLoc());
5417}
Mike Stump1eb44332009-09-09 15:08:12 +00005418
Douglas Gregor43959a92009-08-20 07:17:43 +00005419template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005420StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005421TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005422 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005423 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005424 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005425 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005426
Douglas Gregor43959a92009-08-20 07:17:43 +00005427 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005428 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005429 VarDecl *ConditionVar = 0;
5430 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005431 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005432 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005433 getDerived().TransformDefinition(
5434 S->getConditionVariable()->getLocation(),
5435 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005436 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005437 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005438 } else {
5439 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005440
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005441 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005442 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005443
5444 if (S->getCond()) {
5445 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005446 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005447 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005448 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005449 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005450
John McCall9ae2f072010-08-23 23:25:46 +00005451 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005452 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005453 }
Mike Stump1eb44332009-09-09 15:08:12 +00005454
Chad Rosier4a9d7952012-08-08 18:46:20 +00005455 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005456 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005457 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005458
Douglas Gregor43959a92009-08-20 07:17:43 +00005459 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005460 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005461 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005462 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005463
Richard Smith41956372013-01-14 22:39:08 +00005464 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005465 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005466 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005467
Douglas Gregor43959a92009-08-20 07:17:43 +00005468 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005469 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005470 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005471 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005472
Douglas Gregor43959a92009-08-20 07:17:43 +00005473 if (!getDerived().AlwaysRebuild() &&
5474 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005475 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005476 Inc.get() == S->getInc() &&
5477 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005478 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005479
Douglas Gregor43959a92009-08-20 07:17:43 +00005480 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005481 Init.get(), FullCond, ConditionVar,
5482 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005483}
5484
5485template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005486StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005487TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005488 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5489 S->getLabel());
5490 if (!LD)
5491 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005492
Douglas Gregor43959a92009-08-20 07:17:43 +00005493 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005494 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005495 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005496}
5497
5498template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005499StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005500TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005501 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005502 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005503 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005504 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005505
Douglas Gregor43959a92009-08-20 07:17:43 +00005506 if (!getDerived().AlwaysRebuild() &&
5507 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005508 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005509
5510 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005511 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005512}
5513
5514template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005515StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005516TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005517 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005518}
Mike Stump1eb44332009-09-09 15:08:12 +00005519
Douglas Gregor43959a92009-08-20 07:17:43 +00005520template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005521StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005522TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005523 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005524}
Mike Stump1eb44332009-09-09 15:08:12 +00005525
Douglas Gregor43959a92009-08-20 07:17:43 +00005526template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005527StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005528TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005529 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005530 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005531 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005532
Mike Stump1eb44332009-09-09 15:08:12 +00005533 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005534 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005535 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005536}
Mike Stump1eb44332009-09-09 15:08:12 +00005537
Douglas Gregor43959a92009-08-20 07:17:43 +00005538template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005539StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005540TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005541 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005542 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005543 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5544 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005545 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5546 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005547 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005548 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005549
Douglas Gregor43959a92009-08-20 07:17:43 +00005550 if (Transformed != *D)
5551 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005552
Douglas Gregor43959a92009-08-20 07:17:43 +00005553 Decls.push_back(Transformed);
5554 }
Mike Stump1eb44332009-09-09 15:08:12 +00005555
Douglas Gregor43959a92009-08-20 07:17:43 +00005556 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005557 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005558
5559 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005560 S->getStartLoc(), S->getEndLoc());
5561}
Mike Stump1eb44332009-09-09 15:08:12 +00005562
Douglas Gregor43959a92009-08-20 07:17:43 +00005563template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005564StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005565TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005566
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005567 SmallVector<Expr*, 8> Constraints;
5568 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005569 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005570
John McCall60d7b3a2010-08-24 06:29:42 +00005571 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005572 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005573
5574 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005575
Anders Carlsson703e3942010-01-24 05:50:09 +00005576 // Go through the outputs.
5577 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005578 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005579
Anders Carlsson703e3942010-01-24 05:50:09 +00005580 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005581 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005582
Anders Carlsson703e3942010-01-24 05:50:09 +00005583 // Transform the output expr.
5584 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005585 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005586 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005587 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005588
Anders Carlsson703e3942010-01-24 05:50:09 +00005589 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005590
John McCall9ae2f072010-08-23 23:25:46 +00005591 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005592 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005593
Anders Carlsson703e3942010-01-24 05:50:09 +00005594 // Go through the inputs.
5595 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005596 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005597
Anders Carlsson703e3942010-01-24 05:50:09 +00005598 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005599 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005600
Anders Carlsson703e3942010-01-24 05:50:09 +00005601 // Transform the input expr.
5602 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005603 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005604 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005605 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005606
Anders Carlsson703e3942010-01-24 05:50:09 +00005607 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005608
John McCall9ae2f072010-08-23 23:25:46 +00005609 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005610 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005611
Anders Carlsson703e3942010-01-24 05:50:09 +00005612 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005613 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005614
5615 // Go through the clobbers.
5616 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005617 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005618
5619 // No need to transform the asm string literal.
5620 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005621 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5622 S->isVolatile(), S->getNumOutputs(),
5623 S->getNumInputs(), Names.data(),
5624 Constraints, Exprs, AsmString.get(),
5625 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005626}
5627
Chad Rosier8cd64b42012-06-11 20:47:18 +00005628template<typename Derived>
5629StmtResult
5630TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005631 ArrayRef<Token> AsmToks =
5632 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005633
Chad Rosier7bd092b2012-08-15 16:53:30 +00005634 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
5635 AsmToks, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005636}
Douglas Gregor43959a92009-08-20 07:17:43 +00005637
5638template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005639StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005640TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005641 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005642 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005643 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005644 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005645
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005646 // Transform the @catch statements (if present).
5647 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005648 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005649 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005650 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005651 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005652 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005653 if (Catch.get() != S->getCatchStmt(I))
5654 AnyCatchChanged = true;
5655 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005656 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005657
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005658 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005659 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005660 if (S->getFinallyStmt()) {
5661 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5662 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005663 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005664 }
5665
5666 // If nothing changed, just retain this statement.
5667 if (!getDerived().AlwaysRebuild() &&
5668 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005669 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005670 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005671 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005672
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005673 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005674 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005675 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005676}
Mike Stump1eb44332009-09-09 15:08:12 +00005677
Douglas Gregor43959a92009-08-20 07:17:43 +00005678template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005679StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005680TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005681 // Transform the @catch parameter, if there is one.
5682 VarDecl *Var = 0;
5683 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5684 TypeSourceInfo *TSInfo = 0;
5685 if (FromVar->getTypeSourceInfo()) {
5686 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5687 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005688 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005689 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005690
Douglas Gregorbe270a02010-04-26 17:57:08 +00005691 QualType T;
5692 if (TSInfo)
5693 T = TSInfo->getType();
5694 else {
5695 T = getDerived().TransformType(FromVar->getType());
5696 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005697 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005698 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005699
Douglas Gregorbe270a02010-04-26 17:57:08 +00005700 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5701 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005702 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005703 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005704
John McCall60d7b3a2010-08-24 06:29:42 +00005705 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005706 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005707 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005708
5709 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005710 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005711 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005712}
Mike Stump1eb44332009-09-09 15:08:12 +00005713
Douglas Gregor43959a92009-08-20 07:17:43 +00005714template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005715StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005716TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005717 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005718 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005719 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005720 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005721
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005722 // If nothing changed, just retain this statement.
5723 if (!getDerived().AlwaysRebuild() &&
5724 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005725 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005726
5727 // Build a new statement.
5728 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005729 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005730}
Mike Stump1eb44332009-09-09 15:08:12 +00005731
Douglas Gregor43959a92009-08-20 07:17:43 +00005732template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005733StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005734TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005735 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005736 if (S->getThrowExpr()) {
5737 Operand = getDerived().TransformExpr(S->getThrowExpr());
5738 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005739 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005740 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005741
Douglas Gregord1377b22010-04-22 21:44:01 +00005742 if (!getDerived().AlwaysRebuild() &&
5743 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005744 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005745
John McCall9ae2f072010-08-23 23:25:46 +00005746 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005747}
Mike Stump1eb44332009-09-09 15:08:12 +00005748
Douglas Gregor43959a92009-08-20 07:17:43 +00005749template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005750StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005751TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005752 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005753 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005754 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005755 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005756 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005757 Object =
5758 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5759 Object.get());
5760 if (Object.isInvalid())
5761 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005762
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005763 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005764 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005765 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005766 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005767
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005768 // If nothing change, just retain the current statement.
5769 if (!getDerived().AlwaysRebuild() &&
5770 Object.get() == S->getSynchExpr() &&
5771 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005772 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005773
5774 // Build a new statement.
5775 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005776 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005777}
5778
5779template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005780StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005781TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5782 ObjCAutoreleasePoolStmt *S) {
5783 // Transform the body.
5784 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5785 if (Body.isInvalid())
5786 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005787
John McCallf85e1932011-06-15 23:02:42 +00005788 // If nothing changed, just retain this statement.
5789 if (!getDerived().AlwaysRebuild() &&
5790 Body.get() == S->getSubStmt())
5791 return SemaRef.Owned(S);
5792
5793 // Build a new statement.
5794 return getDerived().RebuildObjCAutoreleasePoolStmt(
5795 S->getAtLoc(), Body.get());
5796}
5797
5798template<typename Derived>
5799StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005800TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005801 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005802 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005803 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005804 if (Element.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 collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005808 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005809 if (Collection.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 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005813 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005814 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005815 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005816
Douglas Gregorc3203e72010-04-22 23:10:45 +00005817 // If nothing changed, just retain this statement.
5818 if (!getDerived().AlwaysRebuild() &&
5819 Element.get() == S->getElement() &&
5820 Collection.get() == S->getCollection() &&
5821 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005822 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005823
Douglas Gregorc3203e72010-04-22 23:10:45 +00005824 // Build a new statement.
5825 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005826 Element.get(),
5827 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005828 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005829 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005830}
5831
5832
5833template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005834StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005835TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5836 // Transform the exception declaration, if any.
5837 VarDecl *Var = 0;
5838 if (S->getExceptionDecl()) {
5839 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005840 TypeSourceInfo *T = getDerived().TransformType(
5841 ExceptionDecl->getTypeSourceInfo());
5842 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005843 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005844
Douglas Gregor83cb9422010-09-09 17:09:21 +00005845 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005846 ExceptionDecl->getInnerLocStart(),
5847 ExceptionDecl->getLocation(),
5848 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005849 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005850 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005851 }
Mike Stump1eb44332009-09-09 15:08:12 +00005852
Douglas Gregor43959a92009-08-20 07:17:43 +00005853 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005854 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005855 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005856 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005857
Douglas Gregor43959a92009-08-20 07:17:43 +00005858 if (!getDerived().AlwaysRebuild() &&
5859 !Var &&
5860 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005861 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005862
5863 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5864 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005865 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005866}
Mike Stump1eb44332009-09-09 15:08:12 +00005867
Douglas Gregor43959a92009-08-20 07:17:43 +00005868template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005869StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005870TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5871 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005872 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005873 = getDerived().TransformCompoundStmt(S->getTryBlock());
5874 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005875 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005876
Douglas Gregor43959a92009-08-20 07:17:43 +00005877 // Transform the handlers.
5878 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005879 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00005880 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005881 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005882 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5883 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005884 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005885
Douglas Gregor43959a92009-08-20 07:17:43 +00005886 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5887 Handlers.push_back(Handler.takeAs<Stmt>());
5888 }
Mike Stump1eb44332009-09-09 15:08:12 +00005889
Douglas Gregor43959a92009-08-20 07:17:43 +00005890 if (!getDerived().AlwaysRebuild() &&
5891 TryBlock.get() == S->getTryBlock() &&
5892 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005893 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005894
John McCall9ae2f072010-08-23 23:25:46 +00005895 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005896 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00005897}
Mike Stump1eb44332009-09-09 15:08:12 +00005898
Richard Smithad762fc2011-04-14 22:09:26 +00005899template<typename Derived>
5900StmtResult
5901TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5902 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5903 if (Range.isInvalid())
5904 return StmtError();
5905
5906 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5907 if (BeginEnd.isInvalid())
5908 return StmtError();
5909
5910 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5911 if (Cond.isInvalid())
5912 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005913 if (Cond.get())
5914 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5915 if (Cond.isInvalid())
5916 return StmtError();
5917 if (Cond.get())
5918 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005919
5920 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5921 if (Inc.isInvalid())
5922 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005923 if (Inc.get())
5924 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005925
5926 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5927 if (LoopVar.isInvalid())
5928 return StmtError();
5929
5930 StmtResult NewStmt = S;
5931 if (getDerived().AlwaysRebuild() ||
5932 Range.get() != S->getRangeStmt() ||
5933 BeginEnd.get() != S->getBeginEndStmt() ||
5934 Cond.get() != S->getCond() ||
5935 Inc.get() != S->getInc() ||
5936 LoopVar.get() != S->getLoopVarStmt())
5937 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5938 S->getColonLoc(), Range.get(),
5939 BeginEnd.get(), Cond.get(),
5940 Inc.get(), LoopVar.get(),
5941 S->getRParenLoc());
5942
5943 StmtResult Body = getDerived().TransformStmt(S->getBody());
5944 if (Body.isInvalid())
5945 return StmtError();
5946
5947 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5948 // it now so we have a new statement to attach the body to.
5949 if (Body.get() != S->getBody() && NewStmt.get() == S)
5950 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5951 S->getColonLoc(), Range.get(),
5952 BeginEnd.get(), Cond.get(),
5953 Inc.get(), LoopVar.get(),
5954 S->getRParenLoc());
5955
5956 if (NewStmt.get() == S)
5957 return SemaRef.Owned(S);
5958
5959 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5960}
5961
John Wiegley28bbe4b2011-04-28 01:08:34 +00005962template<typename Derived>
5963StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005964TreeTransform<Derived>::TransformMSDependentExistsStmt(
5965 MSDependentExistsStmt *S) {
5966 // Transform the nested-name-specifier, if any.
5967 NestedNameSpecifierLoc QualifierLoc;
5968 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005969 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00005970 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5971 if (!QualifierLoc)
5972 return StmtError();
5973 }
5974
5975 // Transform the declaration name.
5976 DeclarationNameInfo NameInfo = S->getNameInfo();
5977 if (NameInfo.getName()) {
5978 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5979 if (!NameInfo.getName())
5980 return StmtError();
5981 }
5982
5983 // Check whether anything changed.
5984 if (!getDerived().AlwaysRebuild() &&
5985 QualifierLoc == S->getQualifierLoc() &&
5986 NameInfo.getName() == S->getNameInfo().getName())
5987 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005988
Douglas Gregorba0513d2011-10-25 01:33:02 +00005989 // Determine whether this name exists, if we can.
5990 CXXScopeSpec SS;
5991 SS.Adopt(QualifierLoc);
5992 bool Dependent = false;
5993 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5994 case Sema::IER_Exists:
5995 if (S->isIfExists())
5996 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005997
Douglas Gregorba0513d2011-10-25 01:33:02 +00005998 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5999
6000 case Sema::IER_DoesNotExist:
6001 if (S->isIfNotExists())
6002 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006003
Douglas Gregorba0513d2011-10-25 01:33:02 +00006004 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006005
Douglas Gregorba0513d2011-10-25 01:33:02 +00006006 case Sema::IER_Dependent:
6007 Dependent = true;
6008 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006009
Douglas Gregor65019ac2011-10-25 03:44:56 +00006010 case Sema::IER_Error:
6011 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006012 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006013
Douglas Gregorba0513d2011-10-25 01:33:02 +00006014 // We need to continue with the instantiation, so do so now.
6015 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6016 if (SubStmt.isInvalid())
6017 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006018
Douglas Gregorba0513d2011-10-25 01:33:02 +00006019 // If we have resolved the name, just transform to the substatement.
6020 if (!Dependent)
6021 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006022
Douglas Gregorba0513d2011-10-25 01:33:02 +00006023 // The name is still dependent, so build a dependent expression again.
6024 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6025 S->isIfExists(),
6026 QualifierLoc,
6027 NameInfo,
6028 SubStmt.get());
6029}
6030
6031template<typename Derived>
6032StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006033TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6034 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6035 if(TryBlock.isInvalid()) return StmtError();
6036
6037 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6038 if(!getDerived().AlwaysRebuild() &&
6039 TryBlock.get() == S->getTryBlock() &&
6040 Handler.get() == S->getHandler())
6041 return SemaRef.Owned(S);
6042
6043 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6044 S->getTryLoc(),
6045 TryBlock.take(),
6046 Handler.take());
6047}
6048
6049template<typename Derived>
6050StmtResult
6051TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6052 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6053 if(Block.isInvalid()) return StmtError();
6054
6055 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6056 Block.take());
6057}
6058
6059template<typename Derived>
6060StmtResult
6061TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6062 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6063 if(FilterExpr.isInvalid()) return StmtError();
6064
6065 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6066 if(Block.isInvalid()) return StmtError();
6067
6068 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6069 FilterExpr.take(),
6070 Block.take());
6071}
6072
6073template<typename Derived>
6074StmtResult
6075TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6076 if(isa<SEHFinallyStmt>(Handler))
6077 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6078 else
6079 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6080}
6081
Douglas Gregor43959a92009-08-20 07:17:43 +00006082//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006083// Expression transformation
6084//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006085template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006086ExprResult
John McCall454feb92009-12-08 09:21:05 +00006087TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006088 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006089}
Mike Stump1eb44332009-09-09 15:08:12 +00006090
6091template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006092ExprResult
John McCall454feb92009-12-08 09:21:05 +00006093TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006094 NestedNameSpecifierLoc QualifierLoc;
6095 if (E->getQualifierLoc()) {
6096 QualifierLoc
6097 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6098 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006099 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006100 }
John McCalldbd872f2009-12-08 09:08:17 +00006101
6102 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006103 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6104 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006105 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006106 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006107
John McCallec8045d2010-08-17 21:27:17 +00006108 DeclarationNameInfo NameInfo = E->getNameInfo();
6109 if (NameInfo.getName()) {
6110 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6111 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006112 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006113 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006114
6115 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006116 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006117 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006118 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006119 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006120
6121 // Mark it referenced in the new context regardless.
6122 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006123 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006124
John McCall3fa5cae2010-10-26 07:05:15 +00006125 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006126 }
John McCalldbd872f2009-12-08 09:08:17 +00006127
6128 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006129 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006130 TemplateArgs = &TransArgs;
6131 TransArgs.setLAngleLoc(E->getLAngleLoc());
6132 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006133 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6134 E->getNumTemplateArgs(),
6135 TransArgs))
6136 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006137 }
6138
Chad Rosier4a9d7952012-08-08 18:46:20 +00006139 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006140 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006141}
Mike Stump1eb44332009-09-09 15:08:12 +00006142
Douglas Gregorb98b1992009-08-11 05:31:07 +00006143template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006144ExprResult
John McCall454feb92009-12-08 09:21:05 +00006145TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006146 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006147}
Mike Stump1eb44332009-09-09 15:08:12 +00006148
Douglas Gregorb98b1992009-08-11 05:31:07 +00006149template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006150ExprResult
John McCall454feb92009-12-08 09:21:05 +00006151TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006152 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006153}
Mike Stump1eb44332009-09-09 15:08:12 +00006154
Douglas Gregorb98b1992009-08-11 05:31:07 +00006155template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006156ExprResult
John McCall454feb92009-12-08 09:21:05 +00006157TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006158 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006159}
Mike Stump1eb44332009-09-09 15:08:12 +00006160
Douglas Gregorb98b1992009-08-11 05:31:07 +00006161template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006162ExprResult
John McCall454feb92009-12-08 09:21:05 +00006163TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006164 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006165}
Mike Stump1eb44332009-09-09 15:08:12 +00006166
Douglas Gregorb98b1992009-08-11 05:31:07 +00006167template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006168ExprResult
John McCall454feb92009-12-08 09:21:05 +00006169TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006170 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006171}
6172
6173template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006174ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006175TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis391ca9f2013-04-09 01:17:02 +00006176 if (FunctionDecl *FD = E->getDirectCallee())
6177 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smith9fcce652012-03-07 08:35:16 +00006178 return SemaRef.MaybeBindToTemporary(E);
6179}
6180
6181template<typename Derived>
6182ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006183TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6184 ExprResult ControllingExpr =
6185 getDerived().TransformExpr(E->getControllingExpr());
6186 if (ControllingExpr.isInvalid())
6187 return ExprError();
6188
Chris Lattner686775d2011-07-20 06:58:45 +00006189 SmallVector<Expr *, 4> AssocExprs;
6190 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006191 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6192 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6193 if (TS) {
6194 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6195 if (!AssocType)
6196 return ExprError();
6197 AssocTypes.push_back(AssocType);
6198 } else {
6199 AssocTypes.push_back(0);
6200 }
6201
6202 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6203 if (AssocExpr.isInvalid())
6204 return ExprError();
6205 AssocExprs.push_back(AssocExpr.release());
6206 }
6207
6208 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6209 E->getDefaultLoc(),
6210 E->getRParenLoc(),
6211 ControllingExpr.release(),
6212 AssocTypes.data(),
6213 AssocExprs.data(),
6214 E->getNumAssocs());
6215}
6216
6217template<typename Derived>
6218ExprResult
John McCall454feb92009-12-08 09:21:05 +00006219TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006220 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006221 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006222 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006223
Douglas Gregorb98b1992009-08-11 05:31:07 +00006224 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006225 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006226
John McCall9ae2f072010-08-23 23:25:46 +00006227 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006228 E->getRParen());
6229}
6230
Richard Smithefeeccf2012-10-21 03:28:35 +00006231/// \brief The operand of a unary address-of operator has special rules: it's
6232/// allowed to refer to a non-static member of a class even if there's no 'this'
6233/// object available.
6234template<typename Derived>
6235ExprResult
6236TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6237 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6238 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6239 else
6240 return getDerived().TransformExpr(E);
6241}
6242
Mike Stump1eb44332009-09-09 15:08:12 +00006243template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006244ExprResult
John McCall454feb92009-12-08 09:21:05 +00006245TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00006246 ExprResult SubExpr = TransformAddressOfOperand(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006247 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006248 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006249
Douglas Gregorb98b1992009-08-11 05:31:07 +00006250 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006251 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006252
Douglas Gregorb98b1992009-08-11 05:31:07 +00006253 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6254 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006255 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006256}
Mike Stump1eb44332009-09-09 15:08:12 +00006257
Douglas Gregorb98b1992009-08-11 05:31:07 +00006258template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006259ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006260TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6261 // Transform the type.
6262 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6263 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006264 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006265
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006266 // Transform all of the components into components similar to what the
6267 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006268 // FIXME: It would be slightly more efficient in the non-dependent case to
6269 // just map FieldDecls, rather than requiring the rebuilder to look for
6270 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006271 // template code that we don't care.
6272 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006273 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006274 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006275 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006276 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6277 const Node &ON = E->getComponent(I);
6278 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006279 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006280 Comp.LocStart = ON.getSourceRange().getBegin();
6281 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006282 switch (ON.getKind()) {
6283 case Node::Array: {
6284 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006285 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006286 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006287 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006288
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006289 ExprChanged = ExprChanged || Index.get() != FromIndex;
6290 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006291 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006292 break;
6293 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006294
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006295 case Node::Field:
6296 case Node::Identifier:
6297 Comp.isBrackets = false;
6298 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006299 if (!Comp.U.IdentInfo)
6300 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006301
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006302 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006303
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006304 case Node::Base:
6305 // Will be recomputed during the rebuild.
6306 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006307 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006308
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006309 Components.push_back(Comp);
6310 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006311
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006312 // If nothing changed, retain the existing expression.
6313 if (!getDerived().AlwaysRebuild() &&
6314 Type == E->getTypeSourceInfo() &&
6315 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006316 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006317
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006318 // Build a new offsetof expression.
6319 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6320 Components.data(), Components.size(),
6321 E->getRParenLoc());
6322}
6323
6324template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006325ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006326TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6327 assert(getDerived().AlreadyTransformed(E->getType()) &&
6328 "opaque value expression requires transformation");
6329 return SemaRef.Owned(E);
6330}
6331
6332template<typename Derived>
6333ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006334TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006335 // Rebuild the syntactic form. The original syntactic form has
6336 // opaque-value expressions in it, so strip those away and rebuild
6337 // the result. This is a really awful way of doing this, but the
6338 // better solution (rebuilding the semantic expressions and
6339 // rebinding OVEs as necessary) doesn't work; we'd need
6340 // TreeTransform to not strip away implicit conversions.
6341 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6342 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006343 if (result.isInvalid()) return ExprError();
6344
6345 // If that gives us a pseudo-object result back, the pseudo-object
6346 // expression must have been an lvalue-to-rvalue conversion which we
6347 // should reapply.
6348 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6349 result = SemaRef.checkPseudoObjectRValue(result.take());
6350
6351 return result;
6352}
6353
6354template<typename Derived>
6355ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006356TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6357 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006358 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006359 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006360
John McCalla93c9342009-12-07 02:54:59 +00006361 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006362 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006363 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006364
John McCall5ab75172009-11-04 07:28:41 +00006365 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006366 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006367
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006368 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6369 E->getKind(),
6370 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006371 }
Mike Stump1eb44332009-09-09 15:08:12 +00006372
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006373 // C++0x [expr.sizeof]p1:
6374 // The operand is either an expression, which is an unevaluated operand
6375 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006376 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6377 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006378
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006379 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6380 if (SubExpr.isInvalid())
6381 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006382
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006383 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6384 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006385
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006386 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6387 E->getOperatorLoc(),
6388 E->getKind(),
6389 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006390}
Mike Stump1eb44332009-09-09 15:08:12 +00006391
Douglas Gregorb98b1992009-08-11 05:31:07 +00006392template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006393ExprResult
John McCall454feb92009-12-08 09:21:05 +00006394TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006395 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006396 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006397 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006398
John McCall60d7b3a2010-08-24 06:29:42 +00006399 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006400 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006401 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006402
6403
Douglas Gregorb98b1992009-08-11 05:31:07 +00006404 if (!getDerived().AlwaysRebuild() &&
6405 LHS.get() == E->getLHS() &&
6406 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006407 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006408
John McCall9ae2f072010-08-23 23:25:46 +00006409 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006410 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006411 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006412 E->getRBracketLoc());
6413}
Mike Stump1eb44332009-09-09 15:08:12 +00006414
6415template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006416ExprResult
John McCall454feb92009-12-08 09:21:05 +00006417TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006418 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006419 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006420 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006421 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006422
6423 // Transform arguments.
6424 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006425 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006426 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006427 &ArgChanged))
6428 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006429
Douglas Gregorb98b1992009-08-11 05:31:07 +00006430 if (!getDerived().AlwaysRebuild() &&
6431 Callee.get() == E->getCallee() &&
6432 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006433 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006434
Douglas Gregorb98b1992009-08-11 05:31:07 +00006435 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006436 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006437 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006438 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006439 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006440 E->getRParenLoc());
6441}
Mike Stump1eb44332009-09-09 15:08:12 +00006442
6443template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006444ExprResult
John McCall454feb92009-12-08 09:21:05 +00006445TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006446 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006447 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006448 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006449
Douglas Gregor40d96a62011-02-28 21:54:11 +00006450 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006451 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006452 QualifierLoc
6453 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006454
Douglas Gregor40d96a62011-02-28 21:54:11 +00006455 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006456 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006457 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006458 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006459
Eli Friedmanf595cc42009-12-04 06:40:45 +00006460 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006461 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6462 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006463 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006464 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006465
John McCall6bb80172010-03-30 21:47:33 +00006466 NamedDecl *FoundDecl = E->getFoundDecl();
6467 if (FoundDecl == E->getMemberDecl()) {
6468 FoundDecl = Member;
6469 } else {
6470 FoundDecl = cast_or_null<NamedDecl>(
6471 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6472 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006473 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006474 }
6475
Douglas Gregorb98b1992009-08-11 05:31:07 +00006476 if (!getDerived().AlwaysRebuild() &&
6477 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006478 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006479 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006480 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006481 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006482
Anders Carlsson1f240322009-12-22 05:24:09 +00006483 // Mark it referenced in the new context regardless.
6484 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006485 SemaRef.MarkMemberReferenced(E);
6486
John McCall3fa5cae2010-10-26 07:05:15 +00006487 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006488 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006489
John McCalld5532b62009-11-23 01:53:49 +00006490 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006491 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006492 TransArgs.setLAngleLoc(E->getLAngleLoc());
6493 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006494 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6495 E->getNumTemplateArgs(),
6496 TransArgs))
6497 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006498 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006499
Douglas Gregorb98b1992009-08-11 05:31:07 +00006500 // FIXME: Bogus source location for the operator
6501 SourceLocation FakeOperatorLoc
6502 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6503
John McCallc2233c52010-01-15 08:34:02 +00006504 // FIXME: to do this check properly, we will need to preserve the
6505 // first-qualifier-in-scope here, just in case we had a dependent
6506 // base (and therefore couldn't do the check) and a
6507 // nested-name-qualifier (and therefore could do the lookup).
6508 NamedDecl *FirstQualifierInScope = 0;
6509
John McCall9ae2f072010-08-23 23:25:46 +00006510 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006511 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006512 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006513 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006514 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006515 Member,
John McCall6bb80172010-03-30 21:47:33 +00006516 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006517 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006518 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006519 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006520}
Mike Stump1eb44332009-09-09 15:08:12 +00006521
Douglas Gregorb98b1992009-08-11 05:31:07 +00006522template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006523ExprResult
John McCall454feb92009-12-08 09:21:05 +00006524TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006525 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006526 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006527 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006528
John McCall60d7b3a2010-08-24 06:29:42 +00006529 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006530 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006531 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006532
Douglas Gregorb98b1992009-08-11 05:31:07 +00006533 if (!getDerived().AlwaysRebuild() &&
6534 LHS.get() == E->getLHS() &&
6535 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006536 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006537
Lang Hamesbe9af122012-10-02 04:45:10 +00006538 Sema::FPContractStateRAII FPContractState(getSema());
6539 getSema().FPFeatures.fp_contract = E->isFPContractable();
6540
Douglas Gregorb98b1992009-08-11 05:31:07 +00006541 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006542 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006543}
6544
Mike Stump1eb44332009-09-09 15:08:12 +00006545template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006546ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006547TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006548 CompoundAssignOperator *E) {
6549 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006550}
Mike Stump1eb44332009-09-09 15:08:12 +00006551
Douglas Gregorb98b1992009-08-11 05:31:07 +00006552template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006553ExprResult TreeTransform<Derived>::
6554TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6555 // Just rebuild the common and RHS expressions and see whether we
6556 // get any changes.
6557
6558 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6559 if (commonExpr.isInvalid())
6560 return ExprError();
6561
6562 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6563 if (rhs.isInvalid())
6564 return ExprError();
6565
6566 if (!getDerived().AlwaysRebuild() &&
6567 commonExpr.get() == e->getCommon() &&
6568 rhs.get() == e->getFalseExpr())
6569 return SemaRef.Owned(e);
6570
6571 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6572 e->getQuestionLoc(),
6573 0,
6574 e->getColonLoc(),
6575 rhs.get());
6576}
6577
6578template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006579ExprResult
John McCall454feb92009-12-08 09:21:05 +00006580TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006581 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006582 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006583 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006584
John McCall60d7b3a2010-08-24 06:29:42 +00006585 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006586 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006587 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006588
John McCall60d7b3a2010-08-24 06:29:42 +00006589 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006590 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006591 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006592
Douglas Gregorb98b1992009-08-11 05:31:07 +00006593 if (!getDerived().AlwaysRebuild() &&
6594 Cond.get() == E->getCond() &&
6595 LHS.get() == E->getLHS() &&
6596 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006597 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006598
John McCall9ae2f072010-08-23 23:25:46 +00006599 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006600 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006601 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006602 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006603 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006604}
Mike Stump1eb44332009-09-09 15:08:12 +00006605
6606template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006607ExprResult
John McCall454feb92009-12-08 09:21:05 +00006608TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006609 // Implicit casts are eliminated during transformation, since they
6610 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006611 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006612}
Mike Stump1eb44332009-09-09 15:08:12 +00006613
Douglas Gregorb98b1992009-08-11 05:31:07 +00006614template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006615ExprResult
John McCall454feb92009-12-08 09:21:05 +00006616TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006617 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6618 if (!Type)
6619 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006620
John McCall60d7b3a2010-08-24 06:29:42 +00006621 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006622 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006623 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006624 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006625
Douglas Gregorb98b1992009-08-11 05:31:07 +00006626 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006627 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006628 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006629 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006630
John McCall9d125032010-01-15 18:39:57 +00006631 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006632 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006633 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006634 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635}
Mike Stump1eb44332009-09-09 15:08:12 +00006636
Douglas Gregorb98b1992009-08-11 05:31:07 +00006637template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006638ExprResult
John McCall454feb92009-12-08 09:21:05 +00006639TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006640 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6641 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6642 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006643 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006644
John McCall60d7b3a2010-08-24 06:29:42 +00006645 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006646 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006647 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006648
Douglas Gregorb98b1992009-08-11 05:31:07 +00006649 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006650 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006651 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006652 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006653
John McCall1d7d8d62010-01-19 22:33:45 +00006654 // Note: the expression type doesn't necessarily match the
6655 // type-as-written, but that's okay, because it should always be
6656 // derivable from the initializer.
6657
John McCall42f56b52010-01-18 19:35:47 +00006658 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006659 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006660 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006661}
Mike Stump1eb44332009-09-09 15:08:12 +00006662
Douglas Gregorb98b1992009-08-11 05:31:07 +00006663template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006664ExprResult
John McCall454feb92009-12-08 09:21:05 +00006665TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006666 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006667 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006668 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006669
Douglas Gregorb98b1992009-08-11 05:31:07 +00006670 if (!getDerived().AlwaysRebuild() &&
6671 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006672 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006673
Douglas Gregorb98b1992009-08-11 05:31:07 +00006674 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006675 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006676 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006677 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006678 E->getAccessorLoc(),
6679 E->getAccessor());
6680}
Mike Stump1eb44332009-09-09 15:08:12 +00006681
Douglas Gregorb98b1992009-08-11 05:31:07 +00006682template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006683ExprResult
John McCall454feb92009-12-08 09:21:05 +00006684TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006685 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006686
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006687 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006688 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006689 Inits, &InitChanged))
6690 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006691
Douglas Gregorb98b1992009-08-11 05:31:07 +00006692 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006693 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006694
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006695 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006696 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006697}
Mike Stump1eb44332009-09-09 15:08:12 +00006698
Douglas Gregorb98b1992009-08-11 05:31:07 +00006699template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006700ExprResult
John McCall454feb92009-12-08 09:21:05 +00006701TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006702 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006703
Douglas Gregor43959a92009-08-20 07:17:43 +00006704 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006705 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006706 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006707 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006708
Douglas Gregor43959a92009-08-20 07:17:43 +00006709 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006710 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006711 bool ExprChanged = false;
6712 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6713 DEnd = E->designators_end();
6714 D != DEnd; ++D) {
6715 if (D->isFieldDesignator()) {
6716 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6717 D->getDotLoc(),
6718 D->getFieldLoc()));
6719 continue;
6720 }
Mike Stump1eb44332009-09-09 15:08:12 +00006721
Douglas Gregorb98b1992009-08-11 05:31:07 +00006722 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006723 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006724 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006725 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006726
6727 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006728 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006729
Douglas Gregorb98b1992009-08-11 05:31:07 +00006730 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6731 ArrayExprs.push_back(Index.release());
6732 continue;
6733 }
Mike Stump1eb44332009-09-09 15:08:12 +00006734
Douglas Gregorb98b1992009-08-11 05:31:07 +00006735 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006736 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006737 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6738 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006739 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006740
John McCall60d7b3a2010-08-24 06:29:42 +00006741 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006742 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006743 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006744
6745 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006746 End.get(),
6747 D->getLBracketLoc(),
6748 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006749
Douglas Gregorb98b1992009-08-11 05:31:07 +00006750 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6751 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006752
Douglas Gregorb98b1992009-08-11 05:31:07 +00006753 ArrayExprs.push_back(Start.release());
6754 ArrayExprs.push_back(End.release());
6755 }
Mike Stump1eb44332009-09-09 15:08:12 +00006756
Douglas Gregorb98b1992009-08-11 05:31:07 +00006757 if (!getDerived().AlwaysRebuild() &&
6758 Init.get() == E->getInit() &&
6759 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006760 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006761
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006762 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006763 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006764 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006765}
Mike Stump1eb44332009-09-09 15:08:12 +00006766
Douglas Gregorb98b1992009-08-11 05:31:07 +00006767template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006768ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006769TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006770 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006771 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006772
Douglas Gregor5557b252009-10-28 00:29:27 +00006773 // FIXME: Will we ever have proper type location here? Will we actually
6774 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006775 QualType T = getDerived().TransformType(E->getType());
6776 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006777 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006778
Douglas Gregorb98b1992009-08-11 05:31:07 +00006779 if (!getDerived().AlwaysRebuild() &&
6780 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006781 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006782
Douglas Gregorb98b1992009-08-11 05:31:07 +00006783 return getDerived().RebuildImplicitValueInitExpr(T);
6784}
Mike Stump1eb44332009-09-09 15:08:12 +00006785
Douglas Gregorb98b1992009-08-11 05:31:07 +00006786template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006787ExprResult
John McCall454feb92009-12-08 09:21:05 +00006788TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006789 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6790 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006791 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006792
John McCall60d7b3a2010-08-24 06:29:42 +00006793 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006794 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006795 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006796
Douglas Gregorb98b1992009-08-11 05:31:07 +00006797 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006798 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006799 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006800 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006801
John McCall9ae2f072010-08-23 23:25:46 +00006802 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006803 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006804}
6805
6806template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006807ExprResult
John McCall454feb92009-12-08 09:21:05 +00006808TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006809 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006810 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00006811 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6812 &ArgumentChanged))
6813 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006814
Douglas Gregorb98b1992009-08-11 05:31:07 +00006815 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006816 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006817 E->getRParenLoc());
6818}
Mike Stump1eb44332009-09-09 15:08:12 +00006819
Douglas Gregorb98b1992009-08-11 05:31:07 +00006820/// \brief Transform an address-of-label expression.
6821///
6822/// By default, the transformation of an address-of-label expression always
6823/// rebuilds the expression, so that the label identifier can be resolved to
6824/// the corresponding label statement by semantic analysis.
6825template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006826ExprResult
John McCall454feb92009-12-08 09:21:05 +00006827TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006828 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6829 E->getLabel());
6830 if (!LD)
6831 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006832
Douglas Gregorb98b1992009-08-11 05:31:07 +00006833 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006834 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006835}
Mike Stump1eb44332009-09-09 15:08:12 +00006836
6837template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006838ExprResult
John McCall454feb92009-12-08 09:21:05 +00006839TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006840 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006841 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006842 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006843 if (SubStmt.isInvalid()) {
6844 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006845 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006846 }
Mike Stump1eb44332009-09-09 15:08:12 +00006847
Douglas Gregorb98b1992009-08-11 05:31:07 +00006848 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006849 SubStmt.get() == E->getSubStmt()) {
6850 // Calling this an 'error' is unintuitive, but it does the right thing.
6851 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006852 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006853 }
Mike Stump1eb44332009-09-09 15:08:12 +00006854
6855 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006856 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006857 E->getRParenLoc());
6858}
Mike Stump1eb44332009-09-09 15:08:12 +00006859
Douglas Gregorb98b1992009-08-11 05:31:07 +00006860template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006861ExprResult
John McCall454feb92009-12-08 09:21:05 +00006862TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006863 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006864 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006865 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006866
John McCall60d7b3a2010-08-24 06:29:42 +00006867 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006868 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006869 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006870
John McCall60d7b3a2010-08-24 06:29:42 +00006871 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006872 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006873 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006874
Douglas Gregorb98b1992009-08-11 05:31:07 +00006875 if (!getDerived().AlwaysRebuild() &&
6876 Cond.get() == E->getCond() &&
6877 LHS.get() == E->getLHS() &&
6878 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006879 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006880
Douglas Gregorb98b1992009-08-11 05:31:07 +00006881 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006882 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006883 E->getRParenLoc());
6884}
Mike Stump1eb44332009-09-09 15:08:12 +00006885
Douglas Gregorb98b1992009-08-11 05:31:07 +00006886template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006887ExprResult
John McCall454feb92009-12-08 09:21:05 +00006888TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006889 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006890}
6891
6892template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006893ExprResult
John McCall454feb92009-12-08 09:21:05 +00006894TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006895 switch (E->getOperator()) {
6896 case OO_New:
6897 case OO_Delete:
6898 case OO_Array_New:
6899 case OO_Array_Delete:
6900 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006901
Douglas Gregor668d6d92009-12-13 20:44:55 +00006902 case OO_Call: {
6903 // This is a call to an object's operator().
6904 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6905
6906 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006907 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006908 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006909 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006910
6911 // FIXME: Poor location information
6912 SourceLocation FakeLParenLoc
6913 = SemaRef.PP.getLocForEndOfToken(
6914 static_cast<Expr *>(Object.get())->getLocEnd());
6915
6916 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006917 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006918 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006919 Args))
6920 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006921
John McCall9ae2f072010-08-23 23:25:46 +00006922 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006923 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006924 E->getLocEnd());
6925 }
6926
6927#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6928 case OO_##Name:
6929#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6930#include "clang/Basic/OperatorKinds.def"
6931 case OO_Subscript:
6932 // Handled below.
6933 break;
6934
6935 case OO_Conditional:
6936 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006937
6938 case OO_None:
6939 case NUM_OVERLOADED_OPERATORS:
6940 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006941 }
6942
John McCall60d7b3a2010-08-24 06:29:42 +00006943 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006944 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006945 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006946
Richard Smithefeeccf2012-10-21 03:28:35 +00006947 ExprResult First;
6948 if (E->getOperator() == OO_Amp)
6949 First = getDerived().TransformAddressOfOperand(E->getArg(0));
6950 else
6951 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006952 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006953 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006954
John McCall60d7b3a2010-08-24 06:29:42 +00006955 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006956 if (E->getNumArgs() == 2) {
6957 Second = getDerived().TransformExpr(E->getArg(1));
6958 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006959 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006960 }
Mike Stump1eb44332009-09-09 15:08:12 +00006961
Douglas Gregorb98b1992009-08-11 05:31:07 +00006962 if (!getDerived().AlwaysRebuild() &&
6963 Callee.get() == E->getCallee() &&
6964 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006965 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006966 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006967
Lang Hamesbe9af122012-10-02 04:45:10 +00006968 Sema::FPContractStateRAII FPContractState(getSema());
6969 getSema().FPFeatures.fp_contract = E->isFPContractable();
6970
Douglas Gregorb98b1992009-08-11 05:31:07 +00006971 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6972 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006973 Callee.get(),
6974 First.get(),
6975 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006976}
Mike Stump1eb44332009-09-09 15:08:12 +00006977
Douglas Gregorb98b1992009-08-11 05:31:07 +00006978template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006979ExprResult
John McCall454feb92009-12-08 09:21:05 +00006980TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6981 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006982}
Mike Stump1eb44332009-09-09 15:08:12 +00006983
Douglas Gregorb98b1992009-08-11 05:31:07 +00006984template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006985ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006986TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6987 // Transform the callee.
6988 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6989 if (Callee.isInvalid())
6990 return ExprError();
6991
6992 // Transform exec config.
6993 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6994 if (EC.isInvalid())
6995 return ExprError();
6996
6997 // Transform arguments.
6998 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006999 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007000 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007001 &ArgChanged))
7002 return ExprError();
7003
7004 if (!getDerived().AlwaysRebuild() &&
7005 Callee.get() == E->getCallee() &&
7006 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007007 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00007008
7009 // FIXME: Wrong source location information for the '('.
7010 SourceLocation FakeLParenLoc
7011 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7012 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007013 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007014 E->getRParenLoc(), EC.get());
7015}
7016
7017template<typename Derived>
7018ExprResult
John McCall454feb92009-12-08 09:21:05 +00007019TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007020 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7021 if (!Type)
7022 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007023
John McCall60d7b3a2010-08-24 06:29:42 +00007024 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007025 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007026 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007027 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007028
Douglas Gregorb98b1992009-08-11 05:31:07 +00007029 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007030 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007031 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007032 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007033 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007034 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007035 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007036 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007037 E->getAngleBrackets().getEnd(),
7038 // FIXME. this should be '(' location
7039 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007040 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007041 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007042}
Mike Stump1eb44332009-09-09 15:08:12 +00007043
Douglas Gregorb98b1992009-08-11 05:31:07 +00007044template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007045ExprResult
John McCall454feb92009-12-08 09:21:05 +00007046TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7047 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007048}
Mike Stump1eb44332009-09-09 15:08:12 +00007049
7050template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007051ExprResult
John McCall454feb92009-12-08 09:21:05 +00007052TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7053 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007054}
7055
Douglas Gregorb98b1992009-08-11 05:31:07 +00007056template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007057ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007058TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007059 CXXReinterpretCastExpr *E) {
7060 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007061}
Mike Stump1eb44332009-09-09 15:08:12 +00007062
Douglas Gregorb98b1992009-08-11 05:31:07 +00007063template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007064ExprResult
John McCall454feb92009-12-08 09:21:05 +00007065TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7066 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007067}
Mike Stump1eb44332009-09-09 15:08:12 +00007068
Douglas Gregorb98b1992009-08-11 05:31:07 +00007069template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007070ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007071TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007072 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007073 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7074 if (!Type)
7075 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007076
John McCall60d7b3a2010-08-24 06:29:42 +00007077 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007078 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007079 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007080 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007081
Douglas Gregorb98b1992009-08-11 05:31:07 +00007082 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007083 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007084 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007085 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007086
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007087 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007088 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007089 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007090 E->getRParenLoc());
7091}
Mike Stump1eb44332009-09-09 15:08:12 +00007092
Douglas Gregorb98b1992009-08-11 05:31:07 +00007093template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007094ExprResult
John McCall454feb92009-12-08 09:21:05 +00007095TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007096 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007097 TypeSourceInfo *TInfo
7098 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7099 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007100 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007101
Douglas Gregorb98b1992009-08-11 05:31:07 +00007102 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007103 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007104 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007105
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007106 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7107 E->getLocStart(),
7108 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007109 E->getLocEnd());
7110 }
Mike Stump1eb44332009-09-09 15:08:12 +00007111
Eli Friedmanef331b72012-01-20 01:26:23 +00007112 // We don't know whether the subexpression is potentially evaluated until
7113 // after we perform semantic analysis. We speculatively assume it is
7114 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007115 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007116 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7117 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007118
John McCall60d7b3a2010-08-24 06:29:42 +00007119 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007120 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007121 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007122
Douglas Gregorb98b1992009-08-11 05:31:07 +00007123 if (!getDerived().AlwaysRebuild() &&
7124 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007125 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007126
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007127 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7128 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007129 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007130 E->getLocEnd());
7131}
7132
7133template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007134ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007135TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7136 if (E->isTypeOperand()) {
7137 TypeSourceInfo *TInfo
7138 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7139 if (!TInfo)
7140 return ExprError();
7141
7142 if (!getDerived().AlwaysRebuild() &&
7143 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007144 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007145
Douglas Gregor3c52a212011-03-06 17:40:41 +00007146 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007147 E->getLocStart(),
7148 TInfo,
7149 E->getLocEnd());
7150 }
7151
Francois Pichet01b7c302010-09-08 12:20:18 +00007152 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7153
7154 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7155 if (SubExpr.isInvalid())
7156 return ExprError();
7157
7158 if (!getDerived().AlwaysRebuild() &&
7159 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007160 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007161
7162 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7163 E->getLocStart(),
7164 SubExpr.get(),
7165 E->getLocEnd());
7166}
7167
7168template<typename Derived>
7169ExprResult
John McCall454feb92009-12-08 09:21:05 +00007170TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007171 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007172}
Mike Stump1eb44332009-09-09 15:08:12 +00007173
Douglas Gregorb98b1992009-08-11 05:31:07 +00007174template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007175ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007176TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007177 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007178 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007179}
Mike Stump1eb44332009-09-09 15:08:12 +00007180
Douglas Gregorb98b1992009-08-11 05:31:07 +00007181template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007182ExprResult
John McCall454feb92009-12-08 09:21:05 +00007183TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007184 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007185 QualType T;
7186 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7187 T = MD->getThisType(getSema().Context);
Douglas Gregore4743be2013-03-08 22:43:48 +00007188 else if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(DC)) {
Richard Smith7a614d82011-06-11 17:19:42 +00007189 T = getSema().Context.getPointerType(
Douglas Gregore4743be2013-03-08 22:43:48 +00007190 getSema().Context.getRecordType(Record));
7191 } else {
7192 assert(SemaRef.Context.getDiagnostics().hasErrorOccurred() &&
7193 "this in the wrong scope?");
7194 return ExprError();
7195 }
Mike Stump1eb44332009-09-09 15:08:12 +00007196
Douglas Gregorec79d872012-02-24 17:41:38 +00007197 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7198 // Make sure that we capture 'this'.
7199 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007200 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007201 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007202
Douglas Gregor828a1972010-01-07 23:12:05 +00007203 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007204}
Mike Stump1eb44332009-09-09 15:08:12 +00007205
Douglas Gregorb98b1992009-08-11 05:31:07 +00007206template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007207ExprResult
John McCall454feb92009-12-08 09:21:05 +00007208TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007209 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007210 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007211 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007212
Douglas Gregorb98b1992009-08-11 05:31:07 +00007213 if (!getDerived().AlwaysRebuild() &&
7214 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007215 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007216
Douglas Gregorbca01b42011-07-06 22:04:06 +00007217 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7218 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007219}
Mike Stump1eb44332009-09-09 15:08:12 +00007220
Douglas Gregorb98b1992009-08-11 05:31:07 +00007221template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007222ExprResult
John McCall454feb92009-12-08 09:21:05 +00007223TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007224 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007225 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7226 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007227 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007228 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007229
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007230 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007231 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007232 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007233
Douglas Gregor036aed12009-12-23 23:03:06 +00007234 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007235}
Mike Stump1eb44332009-09-09 15:08:12 +00007236
Douglas Gregorb98b1992009-08-11 05:31:07 +00007237template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007238ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007239TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7240 CXXScalarValueInitExpr *E) {
7241 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7242 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007243 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007244
Douglas Gregorb98b1992009-08-11 05:31:07 +00007245 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007246 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007247 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007248
Chad Rosier4a9d7952012-08-08 18:46:20 +00007249 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007250 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007251 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007252}
Mike Stump1eb44332009-09-09 15:08:12 +00007253
Douglas Gregorb98b1992009-08-11 05:31:07 +00007254template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007255ExprResult
John McCall454feb92009-12-08 09:21:05 +00007256TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007257 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007258 TypeSourceInfo *AllocTypeInfo
7259 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7260 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007261 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007262
Douglas Gregorb98b1992009-08-11 05:31:07 +00007263 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007264 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007265 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007266 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007267
Douglas Gregorb98b1992009-08-11 05:31:07 +00007268 // Transform the placement arguments (if any).
7269 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007270 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007271 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007272 E->getNumPlacementArgs(), true,
7273 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007274 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007275
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007276 // Transform the initializer (if any).
7277 Expr *OldInit = E->getInitializer();
7278 ExprResult NewInit;
7279 if (OldInit)
7280 NewInit = getDerived().TransformExpr(OldInit);
7281 if (NewInit.isInvalid())
7282 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007283
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007284 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007285 FunctionDecl *OperatorNew = 0;
7286 if (E->getOperatorNew()) {
7287 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007288 getDerived().TransformDecl(E->getLocStart(),
7289 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007290 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007291 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007292 }
7293
7294 FunctionDecl *OperatorDelete = 0;
7295 if (E->getOperatorDelete()) {
7296 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007297 getDerived().TransformDecl(E->getLocStart(),
7298 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007299 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007300 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007301 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007302
Douglas Gregorb98b1992009-08-11 05:31:07 +00007303 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007304 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007305 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007306 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007307 OperatorNew == E->getOperatorNew() &&
7308 OperatorDelete == E->getOperatorDelete() &&
7309 !ArgumentChanged) {
7310 // Mark any declarations we need as referenced.
7311 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007312 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007313 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007314 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007315 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007316
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007317 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007318 QualType ElementType
7319 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7320 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7321 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7322 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007323 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007324 }
7325 }
7326 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007327
John McCall3fa5cae2010-10-26 07:05:15 +00007328 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007329 }
Mike Stump1eb44332009-09-09 15:08:12 +00007330
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007331 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007332 if (!ArraySize.get()) {
7333 // If no array size was specified, but the new expression was
7334 // instantiated with an array type (e.g., "new T" where T is
7335 // instantiated with "int[4]"), extract the outer bound from the
7336 // array type as our array size. We do this with constant and
7337 // dependently-sized array types.
7338 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7339 if (!ArrayT) {
7340 // Do nothing
7341 } else if (const ConstantArrayType *ConsArrayT
7342 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007343 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007344 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007345 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007346 SemaRef.Context.getSizeType(),
7347 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007348 AllocType = ConsArrayT->getElementType();
7349 } else if (const DependentSizedArrayType *DepArrayT
7350 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7351 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007352 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007353 AllocType = DepArrayT->getElementType();
7354 }
7355 }
7356 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007357
Douglas Gregorb98b1992009-08-11 05:31:07 +00007358 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7359 E->isGlobalNew(),
7360 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007361 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007362 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007363 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007364 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007365 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007366 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007367 E->getDirectInitRange(),
7368 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007369}
Mike Stump1eb44332009-09-09 15:08:12 +00007370
Douglas Gregorb98b1992009-08-11 05:31:07 +00007371template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007372ExprResult
John McCall454feb92009-12-08 09:21:05 +00007373TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007374 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007375 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007376 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007377
Douglas Gregor1af74512010-02-26 00:38:10 +00007378 // Transform the delete operator, if known.
7379 FunctionDecl *OperatorDelete = 0;
7380 if (E->getOperatorDelete()) {
7381 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007382 getDerived().TransformDecl(E->getLocStart(),
7383 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007384 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007385 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007386 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007387
Douglas Gregorb98b1992009-08-11 05:31:07 +00007388 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007389 Operand.get() == E->getArgument() &&
7390 OperatorDelete == E->getOperatorDelete()) {
7391 // Mark any declarations we need as referenced.
7392 // FIXME: instantiation-specific.
7393 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007394 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007395
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007396 if (!E->getArgument()->isTypeDependent()) {
7397 QualType Destroyed = SemaRef.Context.getBaseElementType(
7398 E->getDestroyedType());
7399 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7400 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007401 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007402 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007403 }
7404 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007405
John McCall3fa5cae2010-10-26 07:05:15 +00007406 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007407 }
Mike Stump1eb44332009-09-09 15:08:12 +00007408
Douglas Gregorb98b1992009-08-11 05:31:07 +00007409 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7410 E->isGlobalDelete(),
7411 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007412 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007413}
Mike Stump1eb44332009-09-09 15:08:12 +00007414
Douglas Gregorb98b1992009-08-11 05:31:07 +00007415template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007416ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007417TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007418 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007419 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007420 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007421 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007422
John McCallb3d87482010-08-24 05:47:05 +00007423 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007424 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007425 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007426 E->getOperatorLoc(),
7427 E->isArrow()? tok::arrow : tok::period,
7428 ObjectTypePtr,
7429 MayBePseudoDestructor);
7430 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007431 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007432
John McCallb3d87482010-08-24 05:47:05 +00007433 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007434 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7435 if (QualifierLoc) {
7436 QualifierLoc
7437 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7438 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007439 return ExprError();
7440 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007441 CXXScopeSpec SS;
7442 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007443
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007444 PseudoDestructorTypeStorage Destroyed;
7445 if (E->getDestroyedTypeInfo()) {
7446 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007447 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007448 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007449 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007450 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007451 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007452 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007453 // We aren't likely to be able to resolve the identifier down to a type
7454 // now anyway, so just retain the identifier.
7455 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7456 E->getDestroyedTypeLoc());
7457 } else {
7458 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007459 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007460 *E->getDestroyedTypeIdentifier(),
7461 E->getDestroyedTypeLoc(),
7462 /*Scope=*/0,
7463 SS, ObjectTypePtr,
7464 false);
7465 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007466 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007467
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007468 Destroyed
7469 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7470 E->getDestroyedTypeLoc());
7471 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007472
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007473 TypeSourceInfo *ScopeTypeInfo = 0;
7474 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007475 CXXScopeSpec EmptySS;
7476 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7477 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007478 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007479 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007480 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007481
John McCall9ae2f072010-08-23 23:25:46 +00007482 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007483 E->getOperatorLoc(),
7484 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007485 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007486 ScopeTypeInfo,
7487 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007488 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007489 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007490}
Mike Stump1eb44332009-09-09 15:08:12 +00007491
Douglas Gregora71d8192009-09-04 17:36:40 +00007492template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007493ExprResult
John McCallba135432009-11-21 08:51:07 +00007494TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007495 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007496 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7497 Sema::LookupOrdinaryName);
7498
7499 // Transform all the decls.
7500 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7501 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007502 NamedDecl *InstD = static_cast<NamedDecl*>(
7503 getDerived().TransformDecl(Old->getNameLoc(),
7504 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007505 if (!InstD) {
7506 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7507 // This can happen because of dependent hiding.
7508 if (isa<UsingShadowDecl>(*I))
7509 continue;
7510 else
John McCallf312b1e2010-08-26 23:41:50 +00007511 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007512 }
John McCallf7a1a742009-11-24 19:00:30 +00007513
7514 // Expand using declarations.
7515 if (isa<UsingDecl>(InstD)) {
7516 UsingDecl *UD = cast<UsingDecl>(InstD);
7517 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7518 E = UD->shadow_end(); I != E; ++I)
7519 R.addDecl(*I);
7520 continue;
7521 }
7522
7523 R.addDecl(InstD);
7524 }
7525
7526 // Resolve a kind, but don't do any further analysis. If it's
7527 // ambiguous, the callee needs to deal with it.
7528 R.resolveKind();
7529
7530 // Rebuild the nested-name qualifier, if present.
7531 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007532 if (Old->getQualifierLoc()) {
7533 NestedNameSpecifierLoc QualifierLoc
7534 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7535 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007536 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007537
Douglas Gregor4c9be892011-02-28 20:01:57 +00007538 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007539 }
7540
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007541 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007542 CXXRecordDecl *NamingClass
7543 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7544 Old->getNameLoc(),
7545 Old->getNamingClass()));
7546 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007547 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007548
Douglas Gregor66c45152010-04-27 16:10:10 +00007549 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007550 }
7551
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007552 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7553
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007554 // If we have neither explicit template arguments, nor the template keyword,
7555 // it's a normal declaration name.
7556 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007557 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7558
7559 // If we have template arguments, rebuild them, then rebuild the
7560 // templateid expression.
7561 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007562 if (Old->hasExplicitTemplateArgs() &&
7563 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007564 Old->getNumTemplateArgs(),
7565 TransArgs))
7566 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007567
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007568 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007569 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007570}
Mike Stump1eb44332009-09-09 15:08:12 +00007571
Douglas Gregorb98b1992009-08-11 05:31:07 +00007572template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007573ExprResult
John McCall454feb92009-12-08 09:21:05 +00007574TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007575 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7576 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007577 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007578
Douglas Gregorb98b1992009-08-11 05:31:07 +00007579 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007580 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007581 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007582
Mike Stump1eb44332009-09-09 15:08:12 +00007583 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007584 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007585 T,
7586 E->getLocEnd());
7587}
Mike Stump1eb44332009-09-09 15:08:12 +00007588
Douglas Gregorb98b1992009-08-11 05:31:07 +00007589template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007590ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007591TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7592 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7593 if (!LhsT)
7594 return ExprError();
7595
7596 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7597 if (!RhsT)
7598 return ExprError();
7599
7600 if (!getDerived().AlwaysRebuild() &&
7601 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7602 return SemaRef.Owned(E);
7603
7604 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7605 E->getLocStart(),
7606 LhsT, RhsT,
7607 E->getLocEnd());
7608}
7609
7610template<typename Derived>
7611ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007612TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7613 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007614 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007615 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7616 TypeSourceInfo *From = E->getArg(I);
7617 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007618 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007619 TypeLocBuilder TLB;
7620 TLB.reserve(FromTL.getFullDataSize());
7621 QualType To = getDerived().TransformType(TLB, FromTL);
7622 if (To.isNull())
7623 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007624
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007625 if (To == From->getType())
7626 Args.push_back(From);
7627 else {
7628 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7629 ArgChanged = true;
7630 }
7631 continue;
7632 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007633
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007634 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007635
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007636 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007637 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007638 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7639 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7640 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007641
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007642 // Determine whether the set of unexpanded parameter packs can and should
7643 // be expanded.
7644 bool Expand = true;
7645 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007646 Optional<unsigned> OrigNumExpansions =
7647 ExpansionTL.getTypePtr()->getNumExpansions();
7648 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007649 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7650 PatternTL.getSourceRange(),
7651 Unexpanded,
7652 Expand, RetainExpansion,
7653 NumExpansions))
7654 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007655
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007656 if (!Expand) {
7657 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007658 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007659 // expansion.
7660 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007661
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007662 TypeLocBuilder TLB;
7663 TLB.reserve(From->getTypeLoc().getFullDataSize());
7664
7665 QualType To = getDerived().TransformType(TLB, PatternTL);
7666 if (To.isNull())
7667 return ExprError();
7668
Chad Rosier4a9d7952012-08-08 18:46:20 +00007669 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007670 PatternTL.getSourceRange(),
7671 ExpansionTL.getEllipsisLoc(),
7672 NumExpansions);
7673 if (To.isNull())
7674 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007675
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007676 PackExpansionTypeLoc ToExpansionTL
7677 = TLB.push<PackExpansionTypeLoc>(To);
7678 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7679 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7680 continue;
7681 }
7682
7683 // Expand the pack expansion by substituting for each argument in the
7684 // pack(s).
7685 for (unsigned I = 0; I != *NumExpansions; ++I) {
7686 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7687 TypeLocBuilder TLB;
7688 TLB.reserve(PatternTL.getFullDataSize());
7689 QualType To = getDerived().TransformType(TLB, PatternTL);
7690 if (To.isNull())
7691 return ExprError();
7692
7693 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7694 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007695
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007696 if (!RetainExpansion)
7697 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007698
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007699 // If we're supposed to retain a pack expansion, do so by temporarily
7700 // forgetting the partially-substituted parameter pack.
7701 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7702
7703 TypeLocBuilder TLB;
7704 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007705
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007706 QualType To = getDerived().TransformType(TLB, PatternTL);
7707 if (To.isNull())
7708 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007709
7710 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007711 PatternTL.getSourceRange(),
7712 ExpansionTL.getEllipsisLoc(),
7713 NumExpansions);
7714 if (To.isNull())
7715 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007716
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007717 PackExpansionTypeLoc ToExpansionTL
7718 = TLB.push<PackExpansionTypeLoc>(To);
7719 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7720 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7721 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007722
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007723 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7724 return SemaRef.Owned(E);
7725
7726 return getDerived().RebuildTypeTrait(E->getTrait(),
7727 E->getLocStart(),
7728 Args,
7729 E->getLocEnd());
7730}
7731
7732template<typename Derived>
7733ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007734TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7735 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7736 if (!T)
7737 return ExprError();
7738
7739 if (!getDerived().AlwaysRebuild() &&
7740 T == E->getQueriedTypeSourceInfo())
7741 return SemaRef.Owned(E);
7742
7743 ExprResult SubExpr;
7744 {
7745 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7746 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7747 if (SubExpr.isInvalid())
7748 return ExprError();
7749
7750 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7751 return SemaRef.Owned(E);
7752 }
7753
7754 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7755 E->getLocStart(),
7756 T,
7757 SubExpr.get(),
7758 E->getLocEnd());
7759}
7760
7761template<typename Derived>
7762ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007763TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7764 ExprResult SubExpr;
7765 {
7766 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7767 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7768 if (SubExpr.isInvalid())
7769 return ExprError();
7770
7771 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7772 return SemaRef.Owned(E);
7773 }
7774
7775 return getDerived().RebuildExpressionTrait(
7776 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7777}
7778
7779template<typename Derived>
7780ExprResult
John McCall865d4472009-11-19 22:55:06 +00007781TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007782 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00007783 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
7784}
7785
7786template<typename Derived>
7787ExprResult
7788TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
7789 DependentScopeDeclRefExpr *E,
7790 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007791 NestedNameSpecifierLoc QualifierLoc
7792 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7793 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007794 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007795 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007796
John McCall43fed0d2010-11-12 08:19:04 +00007797 // TODO: If this is a conversion-function-id, verify that the
7798 // destination type name (if present) resolves the same way after
7799 // instantiation as it did in the local scope.
7800
Abramo Bagnara25777432010-08-11 22:01:17 +00007801 DeclarationNameInfo NameInfo
7802 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7803 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007804 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007805
John McCallf7a1a742009-11-24 19:00:30 +00007806 if (!E->hasExplicitTemplateArgs()) {
7807 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007808 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007809 // Note: it is sufficient to compare the Name component of NameInfo:
7810 // if name has not changed, DNLoc has not changed either.
7811 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007812 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007813
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007814 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007815 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007816 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007817 /*TemplateArgs*/ 0,
7818 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007819 }
John McCalld5532b62009-11-23 01:53:49 +00007820
7821 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007822 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7823 E->getNumTemplateArgs(),
7824 TransArgs))
7825 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007826
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007827 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007828 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007829 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007830 &TransArgs,
7831 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007832}
7833
7834template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007835ExprResult
John McCall454feb92009-12-08 09:21:05 +00007836TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00007837 // CXXConstructExprs other than for list-initialization and
7838 // CXXTemporaryObjectExpr are always implicit, so when we have
7839 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00007840 if ((E->getNumArgs() == 1 ||
7841 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00007842 (!getDerived().DropCallArgument(E->getArg(0))) &&
7843 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00007844 return getDerived().TransformExpr(E->getArg(0));
7845
Douglas Gregorb98b1992009-08-11 05:31:07 +00007846 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7847
7848 QualType T = getDerived().TransformType(E->getType());
7849 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007850 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007851
7852 CXXConstructorDecl *Constructor
7853 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007854 getDerived().TransformDecl(E->getLocStart(),
7855 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007856 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007857 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007858
Douglas Gregorb98b1992009-08-11 05:31:07 +00007859 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007860 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007861 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007862 &ArgumentChanged))
7863 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007864
Douglas Gregorb98b1992009-08-11 05:31:07 +00007865 if (!getDerived().AlwaysRebuild() &&
7866 T == E->getType() &&
7867 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007868 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007869 // Mark the constructor as referenced.
7870 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007871 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007872 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007873 }
Mike Stump1eb44332009-09-09 15:08:12 +00007874
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007875 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7876 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007877 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007878 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00007879 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007880 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007881 E->getConstructionKind(),
7882 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007883}
Mike Stump1eb44332009-09-09 15:08:12 +00007884
Douglas Gregorb98b1992009-08-11 05:31:07 +00007885/// \brief Transform a C++ temporary-binding expression.
7886///
Douglas Gregor51326552009-12-24 18:51:59 +00007887/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7888/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007889template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007890ExprResult
John McCall454feb92009-12-08 09:21:05 +00007891TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007892 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007893}
Mike Stump1eb44332009-09-09 15:08:12 +00007894
John McCall4765fa02010-12-06 08:20:24 +00007895/// \brief Transform a C++ expression that contains cleanups that should
7896/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007897///
John McCall4765fa02010-12-06 08:20:24 +00007898/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007899/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007900template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007901ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007902TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007903 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007904}
Mike Stump1eb44332009-09-09 15:08:12 +00007905
Douglas Gregorb98b1992009-08-11 05:31:07 +00007906template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007907ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007908TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007909 CXXTemporaryObjectExpr *E) {
7910 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7911 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007912 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007913
Douglas Gregorb98b1992009-08-11 05:31:07 +00007914 CXXConstructorDecl *Constructor
7915 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00007916 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007917 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007918 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007919 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007920
Douglas Gregorb98b1992009-08-11 05:31:07 +00007921 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007922 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007923 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007924 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007925 &ArgumentChanged))
7926 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007927
Douglas Gregorb98b1992009-08-11 05:31:07 +00007928 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007929 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007930 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007931 !ArgumentChanged) {
7932 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007933 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007934 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007935 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007936
Richard Smithc83c2302012-12-19 01:39:02 +00007937 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00007938 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7939 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007940 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007941 E->getLocEnd());
7942}
Mike Stump1eb44332009-09-09 15:08:12 +00007943
Douglas Gregorb98b1992009-08-11 05:31:07 +00007944template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007945ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007946TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007947 // Transform the type of the lambda parameters and start the definition of
7948 // the lambda itself.
7949 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00007950 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00007951 if (!MethodTy)
7952 return ExprError();
7953
Eli Friedman8da8a662012-09-19 01:18:11 +00007954 // Create the local class that will describe the lambda.
7955 CXXRecordDecl *Class
7956 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7957 MethodTy,
7958 /*KnownDependent=*/false);
7959 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7960
Douglas Gregorc6889e72012-02-14 22:28:59 +00007961 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007962 SmallVector<QualType, 4> ParamTypes;
7963 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00007964 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7965 E->getCallOperator()->param_begin(),
7966 E->getCallOperator()->param_size(),
7967 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00007968 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00007969
Douglas Gregordfca6f52012-02-13 22:00:16 +00007970 // Build the call operator.
7971 CXXMethodDecl *CallOperator
7972 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007973 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007974 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007975 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007976 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00007977
Richard Smith612409e2012-07-25 03:56:55 +00007978 return getDerived().TransformLambdaScope(E, CallOperator);
7979}
7980
7981template<typename Derived>
7982ExprResult
7983TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
7984 CXXMethodDecl *CallOperator) {
Douglas Gregord5387e82012-02-14 00:00:48 +00007985 // Introduce the context of the call operator.
7986 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7987
Douglas Gregordfca6f52012-02-13 22:00:16 +00007988 // Enter the scope of the lambda.
7989 sema::LambdaScopeInfo *LSI
7990 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7991 E->getCaptureDefault(),
7992 E->hasExplicitParameters(),
7993 E->hasExplicitResultType(),
7994 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007995
Douglas Gregordfca6f52012-02-13 22:00:16 +00007996 // Transform captures.
Richard Smith612409e2012-07-25 03:56:55 +00007997 bool Invalid = false;
Douglas Gregordfca6f52012-02-13 22:00:16 +00007998 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007999 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008000 CEnd = E->capture_end();
8001 C != CEnd; ++C) {
8002 // When we hit the first implicit capture, tell Sema that we've finished
8003 // the list of explicit captures.
8004 if (!FinishedExplicitCaptures && C->isImplicit()) {
8005 getSema().finishLambdaExplicitCaptures(LSI);
8006 FinishedExplicitCaptures = true;
8007 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008008
Douglas Gregordfca6f52012-02-13 22:00:16 +00008009 // Capturing 'this' is trivial.
8010 if (C->capturesThis()) {
8011 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8012 continue;
8013 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008014
Douglas Gregora7365242012-02-14 19:27:52 +00008015 // Determine the capture kind for Sema.
8016 Sema::TryCaptureKind Kind
8017 = C->isImplicit()? Sema::TryCapture_Implicit
8018 : C->getCaptureKind() == LCK_ByCopy
8019 ? Sema::TryCapture_ExplicitByVal
8020 : Sema::TryCapture_ExplicitByRef;
8021 SourceLocation EllipsisLoc;
8022 if (C->isPackExpansion()) {
8023 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8024 bool ShouldExpand = false;
8025 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008026 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008027 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8028 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008029 Unexpanded,
8030 ShouldExpand, RetainExpansion,
8031 NumExpansions))
8032 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008033
Douglas Gregora7365242012-02-14 19:27:52 +00008034 if (ShouldExpand) {
8035 // The transform has determined that we should perform an expansion;
8036 // transform and capture each of the arguments.
8037 // expansion of the pattern. Do so.
8038 VarDecl *Pack = C->getCapturedVar();
8039 for (unsigned I = 0; I != *NumExpansions; ++I) {
8040 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8041 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008042 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008043 Pack));
8044 if (!CapturedVar) {
8045 Invalid = true;
8046 continue;
8047 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008048
Douglas Gregora7365242012-02-14 19:27:52 +00008049 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008050 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8051 }
Douglas Gregora7365242012-02-14 19:27:52 +00008052 continue;
8053 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008054
Douglas Gregora7365242012-02-14 19:27:52 +00008055 EllipsisLoc = C->getEllipsisLoc();
8056 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008057
Douglas Gregordfca6f52012-02-13 22:00:16 +00008058 // Transform the captured variable.
8059 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008060 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008061 C->getCapturedVar()));
8062 if (!CapturedVar) {
8063 Invalid = true;
8064 continue;
8065 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008066
Douglas Gregordfca6f52012-02-13 22:00:16 +00008067 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008068 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008069 }
8070 if (!FinishedExplicitCaptures)
8071 getSema().finishLambdaExplicitCaptures(LSI);
8072
Douglas Gregordfca6f52012-02-13 22:00:16 +00008073
8074 // Enter a new evaluation context to insulate the lambda from any
8075 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008076 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008077
8078 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008079 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008080 /*IsInstantiation=*/true);
8081 return ExprError();
8082 }
8083
8084 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008085 StmtResult Body = getDerived().TransformStmt(E->getBody());
8086 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008087 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008088 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008089 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008090 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008091
Chad Rosier4a9d7952012-08-08 18:46:20 +00008092 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008093 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008094}
8095
8096template<typename Derived>
8097ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008098TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008099 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008100 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8101 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008102 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008103
Douglas Gregorb98b1992009-08-11 05:31:07 +00008104 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008105 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008106 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008107 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008108 &ArgumentChanged))
8109 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008110
Douglas Gregorb98b1992009-08-11 05:31:07 +00008111 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008112 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008113 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008114 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008115
Douglas Gregorb98b1992009-08-11 05:31:07 +00008116 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008117 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008118 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008119 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008120 E->getRParenLoc());
8121}
Mike Stump1eb44332009-09-09 15:08:12 +00008122
Douglas Gregorb98b1992009-08-11 05:31:07 +00008123template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008124ExprResult
John McCall865d4472009-11-19 22:55:06 +00008125TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008126 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008127 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008128 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008129 Expr *OldBase;
8130 QualType BaseType;
8131 QualType ObjectType;
8132 if (!E->isImplicitAccess()) {
8133 OldBase = E->getBase();
8134 Base = getDerived().TransformExpr(OldBase);
8135 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008136 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008137
John McCallaa81e162009-12-01 22:10:20 +00008138 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008139 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008140 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008141 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008142 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008143 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008144 ObjectTy,
8145 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008146 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008147 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008148
John McCallb3d87482010-08-24 05:47:05 +00008149 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008150 BaseType = ((Expr*) Base.get())->getType();
8151 } else {
8152 OldBase = 0;
8153 BaseType = getDerived().TransformType(E->getBaseType());
8154 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8155 }
Mike Stump1eb44332009-09-09 15:08:12 +00008156
Douglas Gregor6cd21982009-10-20 05:58:46 +00008157 // Transform the first part of the nested-name-specifier that qualifies
8158 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008159 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008160 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008161 E->getFirstQualifierFoundInScope(),
8162 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008163
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008164 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008165 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008166 QualifierLoc
8167 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8168 ObjectType,
8169 FirstQualifierInScope);
8170 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008171 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008172 }
Mike Stump1eb44332009-09-09 15:08:12 +00008173
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008174 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8175
John McCall43fed0d2010-11-12 08:19:04 +00008176 // TODO: If this is a conversion-function-id, verify that the
8177 // destination type name (if present) resolves the same way after
8178 // instantiation as it did in the local scope.
8179
Abramo Bagnara25777432010-08-11 22:01:17 +00008180 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008181 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008182 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008183 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008184
John McCallaa81e162009-12-01 22:10:20 +00008185 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008186 // This is a reference to a member without an explicitly-specified
8187 // template argument list. Optimize for this common case.
8188 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008189 Base.get() == OldBase &&
8190 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008191 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008192 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008193 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008194 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008195
John McCall9ae2f072010-08-23 23:25:46 +00008196 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008197 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008198 E->isArrow(),
8199 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008200 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008201 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008202 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008203 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008204 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008205 }
8206
John McCalld5532b62009-11-23 01:53:49 +00008207 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008208 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8209 E->getNumTemplateArgs(),
8210 TransArgs))
8211 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008212
John McCall9ae2f072010-08-23 23:25:46 +00008213 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008214 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008215 E->isArrow(),
8216 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008217 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008218 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008219 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008220 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008221 &TransArgs);
8222}
8223
8224template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008225ExprResult
John McCall454feb92009-12-08 09:21:05 +00008226TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008227 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008228 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008229 QualType BaseType;
8230 if (!Old->isImplicitAccess()) {
8231 Base = getDerived().TransformExpr(Old->getBase());
8232 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008233 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008234 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8235 Old->isArrow());
8236 if (Base.isInvalid())
8237 return ExprError();
8238 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008239 } else {
8240 BaseType = getDerived().TransformType(Old->getBaseType());
8241 }
John McCall129e2df2009-11-30 22:42:35 +00008242
Douglas Gregor4c9be892011-02-28 20:01:57 +00008243 NestedNameSpecifierLoc QualifierLoc;
8244 if (Old->getQualifierLoc()) {
8245 QualifierLoc
8246 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8247 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008248 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008249 }
8250
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008251 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8252
Abramo Bagnara25777432010-08-11 22:01:17 +00008253 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008254 Sema::LookupOrdinaryName);
8255
8256 // Transform all the decls.
8257 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8258 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008259 NamedDecl *InstD = static_cast<NamedDecl*>(
8260 getDerived().TransformDecl(Old->getMemberLoc(),
8261 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008262 if (!InstD) {
8263 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8264 // This can happen because of dependent hiding.
8265 if (isa<UsingShadowDecl>(*I))
8266 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008267 else {
8268 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008269 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008270 }
John McCall9f54ad42009-12-10 09:41:52 +00008271 }
John McCall129e2df2009-11-30 22:42:35 +00008272
8273 // Expand using declarations.
8274 if (isa<UsingDecl>(InstD)) {
8275 UsingDecl *UD = cast<UsingDecl>(InstD);
8276 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8277 E = UD->shadow_end(); I != E; ++I)
8278 R.addDecl(*I);
8279 continue;
8280 }
8281
8282 R.addDecl(InstD);
8283 }
8284
8285 R.resolveKind();
8286
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008287 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008288 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008289 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008290 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008291 Old->getMemberLoc(),
8292 Old->getNamingClass()));
8293 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008294 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008295
Douglas Gregor66c45152010-04-27 16:10:10 +00008296 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008297 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008298
John McCall129e2df2009-11-30 22:42:35 +00008299 TemplateArgumentListInfo TransArgs;
8300 if (Old->hasExplicitTemplateArgs()) {
8301 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8302 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008303 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8304 Old->getNumTemplateArgs(),
8305 TransArgs))
8306 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008307 }
John McCallc2233c52010-01-15 08:34:02 +00008308
8309 // FIXME: to do this check properly, we will need to preserve the
8310 // first-qualifier-in-scope here, just in case we had a dependent
8311 // base (and therefore couldn't do the check) and a
8312 // nested-name-qualifier (and therefore could do the lookup).
8313 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008314
John McCall9ae2f072010-08-23 23:25:46 +00008315 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008316 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008317 Old->getOperatorLoc(),
8318 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008319 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008320 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008321 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008322 R,
8323 (Old->hasExplicitTemplateArgs()
8324 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008325}
8326
8327template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008328ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008329TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008330 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008331 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8332 if (SubExpr.isInvalid())
8333 return ExprError();
8334
8335 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008336 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008337
8338 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8339}
8340
8341template<typename Derived>
8342ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008343TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008344 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8345 if (Pattern.isInvalid())
8346 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008347
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008348 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8349 return SemaRef.Owned(E);
8350
Douglas Gregor67fd1252011-01-14 21:20:45 +00008351 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8352 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008353}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008354
8355template<typename Derived>
8356ExprResult
8357TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8358 // If E is not value-dependent, then nothing will change when we transform it.
8359 // Note: This is an instantiation-centric view.
8360 if (!E->isValueDependent())
8361 return SemaRef.Owned(E);
8362
8363 // Note: None of the implementations of TryExpandParameterPacks can ever
8364 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008365 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008366 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8367 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008368 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008369 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008370 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008371 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008372 ShouldExpand, RetainExpansion,
8373 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008374 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008375
Douglas Gregor089e8932011-10-10 18:59:29 +00008376 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008377 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008378
Douglas Gregor089e8932011-10-10 18:59:29 +00008379 NamedDecl *Pack = E->getPack();
8380 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008381 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008382 Pack));
8383 if (!Pack)
8384 return ExprError();
8385 }
8386
Chad Rosier4a9d7952012-08-08 18:46:20 +00008387
Douglas Gregoree8aff02011-01-04 17:33:58 +00008388 // We now know the length of the parameter pack, so build a new expression
8389 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008390 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8391 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008392 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008393}
8394
Douglas Gregorbe230c32011-01-03 17:17:50 +00008395template<typename Derived>
8396ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008397TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8398 SubstNonTypeTemplateParmPackExpr *E) {
8399 // Default behavior is to do nothing with this transformation.
8400 return SemaRef.Owned(E);
8401}
8402
8403template<typename Derived>
8404ExprResult
John McCall91a57552011-07-15 05:09:51 +00008405TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8406 SubstNonTypeTemplateParmExpr *E) {
8407 // Default behavior is to do nothing with this transformation.
8408 return SemaRef.Owned(E);
8409}
8410
8411template<typename Derived>
8412ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008413TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8414 // Default behavior is to do nothing with this transformation.
8415 return SemaRef.Owned(E);
8416}
8417
8418template<typename Derived>
8419ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008420TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8421 MaterializeTemporaryExpr *E) {
8422 return getDerived().TransformExpr(E->GetTemporaryExpr());
8423}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008424
Douglas Gregor03e80032011-06-21 17:03:29 +00008425template<typename Derived>
8426ExprResult
John McCall454feb92009-12-08 09:21:05 +00008427TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008428 return SemaRef.MaybeBindToTemporary(E);
8429}
8430
8431template<typename Derived>
8432ExprResult
8433TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008434 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008435}
8436
8437template<typename Derived>
8438ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008439TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8440 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8441 if (SubExpr.isInvalid())
8442 return ExprError();
8443
8444 if (!getDerived().AlwaysRebuild() &&
8445 SubExpr.get() == E->getSubExpr())
8446 return SemaRef.Owned(E);
8447
8448 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008449}
8450
8451template<typename Derived>
8452ExprResult
8453TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8454 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008455 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008456 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008457 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008458 /*IsCall=*/false, Elements, &ArgChanged))
8459 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008460
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008461 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8462 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008463
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008464 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8465 Elements.data(),
8466 Elements.size());
8467}
8468
8469template<typename Derived>
8470ExprResult
8471TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008472 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008473 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008474 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008475 bool ArgChanged = false;
8476 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8477 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008478
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008479 if (OrigElement.isPackExpansion()) {
8480 // This key/value element is a pack expansion.
8481 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8482 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8483 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8484 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8485
8486 // Determine whether the set of unexpanded parameter packs can
8487 // and should be expanded.
8488 bool Expand = true;
8489 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008490 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8491 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008492 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8493 OrigElement.Value->getLocEnd());
8494 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8495 PatternRange,
8496 Unexpanded,
8497 Expand, RetainExpansion,
8498 NumExpansions))
8499 return ExprError();
8500
8501 if (!Expand) {
8502 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008503 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008504 // expansion.
8505 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8506 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8507 if (Key.isInvalid())
8508 return ExprError();
8509
8510 if (Key.get() != OrigElement.Key)
8511 ArgChanged = true;
8512
8513 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8514 if (Value.isInvalid())
8515 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008516
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008517 if (Value.get() != OrigElement.Value)
8518 ArgChanged = true;
8519
Chad Rosier4a9d7952012-08-08 18:46:20 +00008520 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008521 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8522 };
8523 Elements.push_back(Expansion);
8524 continue;
8525 }
8526
8527 // Record right away that the argument was changed. This needs
8528 // to happen even if the array expands to nothing.
8529 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008530
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008531 // The transform has determined that we should perform an elementwise
8532 // expansion of the pattern. Do so.
8533 for (unsigned I = 0; I != *NumExpansions; ++I) {
8534 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8535 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8536 if (Key.isInvalid())
8537 return ExprError();
8538
8539 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8540 if (Value.isInvalid())
8541 return ExprError();
8542
Chad Rosier4a9d7952012-08-08 18:46:20 +00008543 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008544 Key.get(), Value.get(), SourceLocation(), NumExpansions
8545 };
8546
8547 // If any unexpanded parameter packs remain, we still have a
8548 // pack expansion.
8549 if (Key.get()->containsUnexpandedParameterPack() ||
8550 Value.get()->containsUnexpandedParameterPack())
8551 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008552
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008553 Elements.push_back(Element);
8554 }
8555
8556 // We've finished with this pack expansion.
8557 continue;
8558 }
8559
8560 // Transform and check key.
8561 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8562 if (Key.isInvalid())
8563 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008564
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008565 if (Key.get() != OrigElement.Key)
8566 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008567
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008568 // Transform and check value.
8569 ExprResult Value
8570 = getDerived().TransformExpr(OrigElement.Value);
8571 if (Value.isInvalid())
8572 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008573
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008574 if (Value.get() != OrigElement.Value)
8575 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008576
8577 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00008578 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008579 };
8580 Elements.push_back(Element);
8581 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008582
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008583 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8584 return SemaRef.MaybeBindToTemporary(E);
8585
8586 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8587 Elements.data(),
8588 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008589}
8590
Mike Stump1eb44332009-09-09 15:08:12 +00008591template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008592ExprResult
John McCall454feb92009-12-08 09:21:05 +00008593TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008594 TypeSourceInfo *EncodedTypeInfo
8595 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8596 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008597 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008598
Douglas Gregorb98b1992009-08-11 05:31:07 +00008599 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008600 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008601 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008602
8603 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008604 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008605 E->getRParenLoc());
8606}
Mike Stump1eb44332009-09-09 15:08:12 +00008607
Douglas Gregorb98b1992009-08-11 05:31:07 +00008608template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008609ExprResult TreeTransform<Derived>::
8610TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8611 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8612 if (result.isInvalid()) return ExprError();
8613 Expr *subExpr = result.take();
8614
8615 if (!getDerived().AlwaysRebuild() &&
8616 subExpr == E->getSubExpr())
8617 return SemaRef.Owned(E);
8618
8619 return SemaRef.Owned(new(SemaRef.Context)
8620 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8621}
8622
8623template<typename Derived>
8624ExprResult TreeTransform<Derived>::
8625TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008626 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008627 = getDerived().TransformType(E->getTypeInfoAsWritten());
8628 if (!TSInfo)
8629 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008630
John McCallf85e1932011-06-15 23:02:42 +00008631 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008632 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008633 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008634
John McCallf85e1932011-06-15 23:02:42 +00008635 if (!getDerived().AlwaysRebuild() &&
8636 TSInfo == E->getTypeInfoAsWritten() &&
8637 Result.get() == E->getSubExpr())
8638 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008639
John McCallf85e1932011-06-15 23:02:42 +00008640 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008641 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008642 Result.get());
8643}
8644
8645template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008646ExprResult
John McCall454feb92009-12-08 09:21:05 +00008647TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008648 // Transform arguments.
8649 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008650 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008651 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008652 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008653 &ArgChanged))
8654 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008655
Douglas Gregor92e986e2010-04-22 16:44:27 +00008656 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8657 // Class message: transform the receiver type.
8658 TypeSourceInfo *ReceiverTypeInfo
8659 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8660 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008661 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008662
Douglas Gregor92e986e2010-04-22 16:44:27 +00008663 // If nothing changed, just retain the existing message send.
8664 if (!getDerived().AlwaysRebuild() &&
8665 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008666 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008667
8668 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008669 SmallVector<SourceLocation, 16> SelLocs;
8670 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008671 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8672 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008673 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008674 E->getMethodDecl(),
8675 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008676 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008677 E->getRightLoc());
8678 }
8679
8680 // Instance message: transform the receiver
8681 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8682 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008683 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008684 = getDerived().TransformExpr(E->getInstanceReceiver());
8685 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008686 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008687
8688 // If nothing changed, just retain the existing message send.
8689 if (!getDerived().AlwaysRebuild() &&
8690 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008691 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008692
Douglas Gregor92e986e2010-04-22 16:44:27 +00008693 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008694 SmallVector<SourceLocation, 16> SelLocs;
8695 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008696 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008697 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008698 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008699 E->getMethodDecl(),
8700 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008701 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008702 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008703}
8704
Mike Stump1eb44332009-09-09 15:08:12 +00008705template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008706ExprResult
John McCall454feb92009-12-08 09:21:05 +00008707TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008708 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008709}
8710
Mike Stump1eb44332009-09-09 15:08:12 +00008711template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008712ExprResult
John McCall454feb92009-12-08 09:21:05 +00008713TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008714 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008715}
8716
Mike Stump1eb44332009-09-09 15:08:12 +00008717template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008718ExprResult
John McCall454feb92009-12-08 09:21:05 +00008719TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008720 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008721 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008722 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008723 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008724
8725 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008726
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008727 // If nothing changed, just retain the existing expression.
8728 if (!getDerived().AlwaysRebuild() &&
8729 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008730 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008731
John McCall9ae2f072010-08-23 23:25:46 +00008732 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008733 E->getLocation(),
8734 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008735}
8736
Mike Stump1eb44332009-09-09 15:08:12 +00008737template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008738ExprResult
John McCall454feb92009-12-08 09:21:05 +00008739TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008740 // 'super' and types never change. Property never changes. Just
8741 // retain the existing expression.
8742 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008743 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008744
Douglas Gregore3303542010-04-26 20:47:02 +00008745 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008746 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008747 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008748 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008749
Douglas Gregore3303542010-04-26 20:47:02 +00008750 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008751
Douglas Gregore3303542010-04-26 20:47:02 +00008752 // If nothing changed, just retain the existing expression.
8753 if (!getDerived().AlwaysRebuild() &&
8754 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008755 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008756
John McCall12f78a62010-12-02 01:19:52 +00008757 if (E->isExplicitProperty())
8758 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8759 E->getExplicitProperty(),
8760 E->getLocation());
8761
8762 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008763 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008764 E->getImplicitPropertyGetter(),
8765 E->getImplicitPropertySetter(),
8766 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008767}
8768
Mike Stump1eb44332009-09-09 15:08:12 +00008769template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008770ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008771TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8772 // Transform the base expression.
8773 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8774 if (Base.isInvalid())
8775 return ExprError();
8776
8777 // Transform the key expression.
8778 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8779 if (Key.isInvalid())
8780 return ExprError();
8781
8782 // If nothing changed, just retain the existing expression.
8783 if (!getDerived().AlwaysRebuild() &&
8784 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8785 return SemaRef.Owned(E);
8786
Chad Rosier4a9d7952012-08-08 18:46:20 +00008787 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008788 Base.get(), Key.get(),
8789 E->getAtIndexMethodDecl(),
8790 E->setAtIndexMethodDecl());
8791}
8792
8793template<typename Derived>
8794ExprResult
John McCall454feb92009-12-08 09:21:05 +00008795TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008796 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008797 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008798 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008799 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008800
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008801 // If nothing changed, just retain the existing expression.
8802 if (!getDerived().AlwaysRebuild() &&
8803 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008804 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008805
John McCall9ae2f072010-08-23 23:25:46 +00008806 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00008807 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008808 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008809}
8810
Mike Stump1eb44332009-09-09 15:08:12 +00008811template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008812ExprResult
John McCall454feb92009-12-08 09:21:05 +00008813TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008814 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008815 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008816 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008817 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008818 SubExprs, &ArgumentChanged))
8819 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008820
Douglas Gregorb98b1992009-08-11 05:31:07 +00008821 if (!getDerived().AlwaysRebuild() &&
8822 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008823 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008824
Douglas Gregorb98b1992009-08-11 05:31:07 +00008825 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008826 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008827 E->getRParenLoc());
8828}
8829
Mike Stump1eb44332009-09-09 15:08:12 +00008830template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008831ExprResult
John McCall454feb92009-12-08 09:21:05 +00008832TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008833 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008834
John McCallc6ac9c32011-02-04 18:33:18 +00008835 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8836 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8837
8838 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008839 blockScope->TheDecl->setBlockMissingReturnType(
8840 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008841
Chris Lattner686775d2011-07-20 06:58:45 +00008842 SmallVector<ParmVarDecl*, 4> params;
8843 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008844
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008845 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008846 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8847 oldBlock->param_begin(),
8848 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008849 0, paramTypes, &params)) {
8850 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008851 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008852 }
John McCallc6ac9c32011-02-04 18:33:18 +00008853
Jordan Rose09189892013-03-08 22:25:36 +00008854 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008855 QualType exprResultType =
8856 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008857
8858 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008859 if (exprResultType->isObjCObjectType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008860 getSema().Diag(E->getCaretLocation(),
8861 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008862 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008863 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008864 return ExprError();
8865 }
John McCall711c52b2011-01-05 12:14:39 +00008866
Jordan Rosebea522f2013-03-08 21:51:21 +00008867 QualType functionType =
8868 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00008869 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00008870 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008871
8872 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008873 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008874 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008875
8876 if (!oldBlock->blockMissingReturnType()) {
8877 blockScope->HasImplicitReturnType = false;
8878 blockScope->ReturnType = exprResultType;
8879 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008880
John McCall711c52b2011-01-05 12:14:39 +00008881 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008882 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008883 if (body.isInvalid()) {
8884 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008885 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008886 }
John McCall711c52b2011-01-05 12:14:39 +00008887
John McCallc6ac9c32011-02-04 18:33:18 +00008888#ifndef NDEBUG
8889 // In builds with assertions, make sure that we captured everything we
8890 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008891 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8892 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8893 e = oldBlock->capture_end(); i != e; ++i) {
8894 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008895
Douglas Gregorfc921372011-05-20 15:32:55 +00008896 // Ignore parameter packs.
8897 if (isa<ParmVarDecl>(oldCapture) &&
8898 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8899 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008900
Douglas Gregorfc921372011-05-20 15:32:55 +00008901 VarDecl *newCapture =
8902 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8903 oldCapture));
8904 assert(blockScope->CaptureMap.count(newCapture));
8905 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008906 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008907 }
8908#endif
8909
8910 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8911 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008912}
8913
Mike Stump1eb44332009-09-09 15:08:12 +00008914template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008915ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008916TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008917 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008918}
Eli Friedman276b0612011-10-11 02:20:01 +00008919
8920template<typename Derived>
8921ExprResult
8922TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008923 QualType RetTy = getDerived().TransformType(E->getType());
8924 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008925 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008926 SubExprs.reserve(E->getNumSubExprs());
8927 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8928 SubExprs, &ArgumentChanged))
8929 return ExprError();
8930
8931 if (!getDerived().AlwaysRebuild() &&
8932 !ArgumentChanged)
8933 return SemaRef.Owned(E);
8934
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008935 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008936 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008937}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008938
Douglas Gregorb98b1992009-08-11 05:31:07 +00008939//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008940// Type reconstruction
8941//===----------------------------------------------------------------------===//
8942
Mike Stump1eb44332009-09-09 15:08:12 +00008943template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008944QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8945 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008946 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008947 getDerived().getBaseEntity());
8948}
8949
Mike Stump1eb44332009-09-09 15:08:12 +00008950template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008951QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8952 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008953 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008954 getDerived().getBaseEntity());
8955}
8956
Mike Stump1eb44332009-09-09 15:08:12 +00008957template<typename Derived>
8958QualType
John McCall85737a72009-10-30 00:06:24 +00008959TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8960 bool WrittenAsLValue,
8961 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008962 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008963 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008964}
8965
8966template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008967QualType
John McCall85737a72009-10-30 00:06:24 +00008968TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8969 QualType ClassType,
8970 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008971 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008972 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008973}
8974
8975template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008976QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008977TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8978 ArrayType::ArraySizeModifier SizeMod,
8979 const llvm::APInt *Size,
8980 Expr *SizeExpr,
8981 unsigned IndexTypeQuals,
8982 SourceRange BracketsRange) {
8983 if (SizeExpr || !Size)
8984 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8985 IndexTypeQuals, BracketsRange,
8986 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008987
8988 QualType Types[] = {
8989 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8990 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8991 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008992 };
8993 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8994 QualType SizeType;
8995 for (unsigned I = 0; I != NumTypes; ++I)
8996 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8997 SizeType = Types[I];
8998 break;
8999 }
Mike Stump1eb44332009-09-09 15:08:12 +00009000
Eli Friedman01f276d2012-01-25 23:20:27 +00009001 // Note that we can return a VariableArrayType here in the case where
9002 // the element type was a dependent VariableArrayType.
9003 IntegerLiteral *ArraySize
9004 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9005 /*FIXME*/BracketsRange.getBegin());
9006 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009007 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00009008 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009009}
Mike Stump1eb44332009-09-09 15:08:12 +00009010
Douglas Gregor577f75a2009-08-04 16:50:30 +00009011template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009012QualType
9013TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009014 ArrayType::ArraySizeModifier SizeMod,
9015 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009016 unsigned IndexTypeQuals,
9017 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009018 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009019 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009020}
9021
9022template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009023QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009024TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009025 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009026 unsigned IndexTypeQuals,
9027 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009028 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009029 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009030}
Mike Stump1eb44332009-09-09 15:08:12 +00009031
Douglas Gregor577f75a2009-08-04 16:50:30 +00009032template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009033QualType
9034TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009035 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009036 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009037 unsigned IndexTypeQuals,
9038 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009039 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009040 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009041 IndexTypeQuals, BracketsRange);
9042}
9043
9044template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009045QualType
9046TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009047 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009048 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009049 unsigned IndexTypeQuals,
9050 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009051 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009052 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009053 IndexTypeQuals, BracketsRange);
9054}
9055
9056template<typename Derived>
9057QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009058 unsigned NumElements,
9059 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009060 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009061 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009062}
Mike Stump1eb44332009-09-09 15:08:12 +00009063
Douglas Gregor577f75a2009-08-04 16:50:30 +00009064template<typename Derived>
9065QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9066 unsigned NumElements,
9067 SourceLocation AttributeLoc) {
9068 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9069 NumElements, true);
9070 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009071 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9072 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009073 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009074}
Mike Stump1eb44332009-09-09 15:08:12 +00009075
Douglas Gregor577f75a2009-08-04 16:50:30 +00009076template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009077QualType
9078TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009079 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009080 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009081 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009082}
Mike Stump1eb44332009-09-09 15:08:12 +00009083
Douglas Gregor577f75a2009-08-04 16:50:30 +00009084template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009085QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9086 QualType T,
9087 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009088 const FunctionProtoType::ExtProtoInfo &EPI) {
9089 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009090 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009091 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009092 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009093}
Mike Stump1eb44332009-09-09 15:08:12 +00009094
Douglas Gregor577f75a2009-08-04 16:50:30 +00009095template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009096QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9097 return SemaRef.Context.getFunctionNoProtoType(T);
9098}
9099
9100template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009101QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9102 assert(D && "no decl found");
9103 if (D->isInvalidDecl()) return QualType();
9104
Douglas Gregor92e986e2010-04-22 16:44:27 +00009105 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009106 TypeDecl *Ty;
9107 if (isa<UsingDecl>(D)) {
9108 UsingDecl *Using = cast<UsingDecl>(D);
9109 assert(Using->isTypeName() &&
9110 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9111
9112 // A valid resolved using typename decl points to exactly one type decl.
9113 assert(++Using->shadow_begin() == Using->shadow_end());
9114 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009115
John McCalled976492009-12-04 22:46:56 +00009116 } else {
9117 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9118 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9119 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9120 }
9121
9122 return SemaRef.Context.getTypeDeclType(Ty);
9123}
9124
9125template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009126QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9127 SourceLocation Loc) {
9128 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009129}
9130
9131template<typename Derived>
9132QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9133 return SemaRef.Context.getTypeOfType(Underlying);
9134}
9135
9136template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009137QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9138 SourceLocation Loc) {
9139 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009140}
9141
9142template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009143QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9144 UnaryTransformType::UTTKind UKind,
9145 SourceLocation Loc) {
9146 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9147}
9148
9149template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009150QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009151 TemplateName Template,
9152 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009153 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009154 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009155}
Mike Stump1eb44332009-09-09 15:08:12 +00009156
Douglas Gregordcee1a12009-08-06 05:28:30 +00009157template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009158QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9159 SourceLocation KWLoc) {
9160 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9161}
9162
9163template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009164TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009165TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009166 bool TemplateKW,
9167 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009168 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009169 Template);
9170}
9171
9172template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009173TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009174TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9175 const IdentifierInfo &Name,
9176 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009177 QualType ObjectType,
9178 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009179 UnqualifiedId TemplateName;
9180 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009181 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009182 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009183 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009184 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009185 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009186 /*EnteringContext=*/false,
9187 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009188 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009189}
Mike Stump1eb44332009-09-09 15:08:12 +00009190
Douglas Gregorb98b1992009-08-11 05:31:07 +00009191template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009192TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009193TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009194 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009195 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009196 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009197 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009198 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009199 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009200 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009201 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009202 Sema::TemplateTy Template;
9203 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009204 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009205 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009206 /*EnteringContext=*/false,
9207 Template);
9208 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009209}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009210
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009211template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009212ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009213TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9214 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009215 Expr *OrigCallee,
9216 Expr *First,
9217 Expr *Second) {
9218 Expr *Callee = OrigCallee->IgnoreParenCasts();
9219 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009220
Douglas Gregorb98b1992009-08-11 05:31:07 +00009221 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009222 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009223 if (!First->getType()->isOverloadableType() &&
9224 !Second->getType()->isOverloadableType())
9225 return getSema().CreateBuiltinArraySubscriptExpr(First,
9226 Callee->getLocStart(),
9227 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009228 } else if (Op == OO_Arrow) {
9229 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009230 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9231 } else if (Second == 0 || isPostIncDec) {
9232 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009233 // The argument is not of overloadable type, so try to create a
9234 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009235 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009236 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009237
John McCall9ae2f072010-08-23 23:25:46 +00009238 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009239 }
9240 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009241 if (!First->getType()->isOverloadableType() &&
9242 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009243 // Neither of the arguments is an overloadable type, so try to
9244 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009245 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009246 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009247 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009248 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009249 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009250
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009251 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009252 }
9253 }
Mike Stump1eb44332009-09-09 15:08:12 +00009254
9255 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009256 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009257 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009258
John McCall9ae2f072010-08-23 23:25:46 +00009259 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009260 assert(ULE->requiresADL());
9261
9262 // FIXME: Do we have to check
9263 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009264 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009265 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009266 // If we've resolved this to a particular non-member function, just call
9267 // that function. If we resolved it to a member function,
9268 // CreateOverloaded* will find that function for us.
9269 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9270 if (!isa<CXXMethodDecl>(ND))
9271 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009272 }
Mike Stump1eb44332009-09-09 15:08:12 +00009273
Douglas Gregorb98b1992009-08-11 05:31:07 +00009274 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009275 Expr *Args[2] = { First, Second };
9276 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009277
Douglas Gregorb98b1992009-08-11 05:31:07 +00009278 // Create the overloaded operator invocation for unary operators.
9279 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009280 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009281 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009282 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009283 }
Mike Stump1eb44332009-09-09 15:08:12 +00009284
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009285 if (Op == OO_Subscript) {
9286 SourceLocation LBrace;
9287 SourceLocation RBrace;
9288
9289 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9290 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9291 LBrace = SourceLocation::getFromRawEncoding(
9292 NameLoc.CXXOperatorName.BeginOpNameLoc);
9293 RBrace = SourceLocation::getFromRawEncoding(
9294 NameLoc.CXXOperatorName.EndOpNameLoc);
9295 } else {
9296 LBrace = Callee->getLocStart();
9297 RBrace = OpLoc;
9298 }
9299
9300 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9301 First, Second);
9302 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009303
Douglas Gregorb98b1992009-08-11 05:31:07 +00009304 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009305 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009306 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009307 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9308 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009309 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009310
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009311 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009312}
Mike Stump1eb44332009-09-09 15:08:12 +00009313
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009314template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009315ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009316TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009317 SourceLocation OperatorLoc,
9318 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009319 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009320 TypeSourceInfo *ScopeType,
9321 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009322 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009323 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009324 QualType BaseType = Base->getType();
9325 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009326 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009327 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009328 !BaseType->getAs<PointerType>()->getPointeeType()
9329 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009330 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009331 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009332 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009333 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009334 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009335 /*FIXME?*/true);
9336 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009337
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009338 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009339 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9340 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9341 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9342 NameInfo.setNamedTypeInfo(DestroyedType);
9343
Richard Smith6314db92012-05-15 06:15:11 +00009344 // The scope type is now known to be a valid nested name specifier
9345 // component. Tack it on to the end of the nested name specifier.
9346 if (ScopeType)
9347 SS.Extend(SemaRef.Context, SourceLocation(),
9348 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009349
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009350 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009351 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009352 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009353 SS, TemplateKWLoc,
9354 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009355 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009356 /*TemplateArgs*/ 0);
9357}
9358
Douglas Gregor577f75a2009-08-04 16:50:30 +00009359} // end namespace clang
9360
9361#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H