blob: f68de26cde3b07e138daea9d52d36336da3ae6a2 [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) {
6176 return SemaRef.MaybeBindToTemporary(E);
6177}
6178
6179template<typename Derived>
6180ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006181TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6182 ExprResult ControllingExpr =
6183 getDerived().TransformExpr(E->getControllingExpr());
6184 if (ControllingExpr.isInvalid())
6185 return ExprError();
6186
Chris Lattner686775d2011-07-20 06:58:45 +00006187 SmallVector<Expr *, 4> AssocExprs;
6188 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006189 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6190 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6191 if (TS) {
6192 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6193 if (!AssocType)
6194 return ExprError();
6195 AssocTypes.push_back(AssocType);
6196 } else {
6197 AssocTypes.push_back(0);
6198 }
6199
6200 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6201 if (AssocExpr.isInvalid())
6202 return ExprError();
6203 AssocExprs.push_back(AssocExpr.release());
6204 }
6205
6206 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6207 E->getDefaultLoc(),
6208 E->getRParenLoc(),
6209 ControllingExpr.release(),
6210 AssocTypes.data(),
6211 AssocExprs.data(),
6212 E->getNumAssocs());
6213}
6214
6215template<typename Derived>
6216ExprResult
John McCall454feb92009-12-08 09:21:05 +00006217TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006218 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006219 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006220 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006221
Douglas Gregorb98b1992009-08-11 05:31:07 +00006222 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006223 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006224
John McCall9ae2f072010-08-23 23:25:46 +00006225 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006226 E->getRParen());
6227}
6228
Richard Smithefeeccf2012-10-21 03:28:35 +00006229/// \brief The operand of a unary address-of operator has special rules: it's
6230/// allowed to refer to a non-static member of a class even if there's no 'this'
6231/// object available.
6232template<typename Derived>
6233ExprResult
6234TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6235 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6236 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6237 else
6238 return getDerived().TransformExpr(E);
6239}
6240
Mike Stump1eb44332009-09-09 15:08:12 +00006241template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006242ExprResult
John McCall454feb92009-12-08 09:21:05 +00006243TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00006244 ExprResult SubExpr = TransformAddressOfOperand(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006245 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006246 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006247
Douglas Gregorb98b1992009-08-11 05:31:07 +00006248 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006249 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006250
Douglas Gregorb98b1992009-08-11 05:31:07 +00006251 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6252 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006253 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006254}
Mike Stump1eb44332009-09-09 15:08:12 +00006255
Douglas Gregorb98b1992009-08-11 05:31:07 +00006256template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006257ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006258TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6259 // Transform the type.
6260 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6261 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006262 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006263
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006264 // Transform all of the components into components similar to what the
6265 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006266 // FIXME: It would be slightly more efficient in the non-dependent case to
6267 // just map FieldDecls, rather than requiring the rebuilder to look for
6268 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006269 // template code that we don't care.
6270 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006271 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006272 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006273 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006274 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6275 const Node &ON = E->getComponent(I);
6276 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006277 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006278 Comp.LocStart = ON.getSourceRange().getBegin();
6279 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006280 switch (ON.getKind()) {
6281 case Node::Array: {
6282 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006283 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006284 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006285 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006286
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006287 ExprChanged = ExprChanged || Index.get() != FromIndex;
6288 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006289 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006290 break;
6291 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006292
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006293 case Node::Field:
6294 case Node::Identifier:
6295 Comp.isBrackets = false;
6296 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006297 if (!Comp.U.IdentInfo)
6298 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006299
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006300 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006301
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006302 case Node::Base:
6303 // Will be recomputed during the rebuild.
6304 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006305 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006306
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006307 Components.push_back(Comp);
6308 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006309
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006310 // If nothing changed, retain the existing expression.
6311 if (!getDerived().AlwaysRebuild() &&
6312 Type == E->getTypeSourceInfo() &&
6313 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006314 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006315
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006316 // Build a new offsetof expression.
6317 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6318 Components.data(), Components.size(),
6319 E->getRParenLoc());
6320}
6321
6322template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006323ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006324TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6325 assert(getDerived().AlreadyTransformed(E->getType()) &&
6326 "opaque value expression requires transformation");
6327 return SemaRef.Owned(E);
6328}
6329
6330template<typename Derived>
6331ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006332TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006333 // Rebuild the syntactic form. The original syntactic form has
6334 // opaque-value expressions in it, so strip those away and rebuild
6335 // the result. This is a really awful way of doing this, but the
6336 // better solution (rebuilding the semantic expressions and
6337 // rebinding OVEs as necessary) doesn't work; we'd need
6338 // TreeTransform to not strip away implicit conversions.
6339 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6340 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006341 if (result.isInvalid()) return ExprError();
6342
6343 // If that gives us a pseudo-object result back, the pseudo-object
6344 // expression must have been an lvalue-to-rvalue conversion which we
6345 // should reapply.
6346 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6347 result = SemaRef.checkPseudoObjectRValue(result.take());
6348
6349 return result;
6350}
6351
6352template<typename Derived>
6353ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006354TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6355 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006356 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006357 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006358
John McCalla93c9342009-12-07 02:54:59 +00006359 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006360 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006361 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006362
John McCall5ab75172009-11-04 07:28:41 +00006363 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006364 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006365
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006366 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6367 E->getKind(),
6368 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006369 }
Mike Stump1eb44332009-09-09 15:08:12 +00006370
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006371 // C++0x [expr.sizeof]p1:
6372 // The operand is either an expression, which is an unevaluated operand
6373 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006374 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6375 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006376
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006377 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6378 if (SubExpr.isInvalid())
6379 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006380
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006381 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6382 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006383
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006384 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6385 E->getOperatorLoc(),
6386 E->getKind(),
6387 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006388}
Mike Stump1eb44332009-09-09 15:08:12 +00006389
Douglas Gregorb98b1992009-08-11 05:31:07 +00006390template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006391ExprResult
John McCall454feb92009-12-08 09:21:05 +00006392TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006393 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006394 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006395 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006396
John McCall60d7b3a2010-08-24 06:29:42 +00006397 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006398 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006399 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006400
6401
Douglas Gregorb98b1992009-08-11 05:31:07 +00006402 if (!getDerived().AlwaysRebuild() &&
6403 LHS.get() == E->getLHS() &&
6404 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006405 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006406
John McCall9ae2f072010-08-23 23:25:46 +00006407 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006408 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006409 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006410 E->getRBracketLoc());
6411}
Mike Stump1eb44332009-09-09 15:08:12 +00006412
6413template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006414ExprResult
John McCall454feb92009-12-08 09:21:05 +00006415TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006416 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006417 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006418 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006419 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006420
6421 // Transform arguments.
6422 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006423 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006424 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006425 &ArgChanged))
6426 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006427
Douglas Gregorb98b1992009-08-11 05:31:07 +00006428 if (!getDerived().AlwaysRebuild() &&
6429 Callee.get() == E->getCallee() &&
6430 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006431 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006432
Douglas Gregorb98b1992009-08-11 05:31:07 +00006433 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006434 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006435 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006436 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006437 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006438 E->getRParenLoc());
6439}
Mike Stump1eb44332009-09-09 15:08:12 +00006440
6441template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006442ExprResult
John McCall454feb92009-12-08 09:21:05 +00006443TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006444 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006445 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006446 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006447
Douglas Gregor40d96a62011-02-28 21:54:11 +00006448 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006449 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006450 QualifierLoc
6451 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006452
Douglas Gregor40d96a62011-02-28 21:54:11 +00006453 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006454 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006455 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006456 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006457
Eli Friedmanf595cc42009-12-04 06:40:45 +00006458 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006459 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6460 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006461 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006462 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006463
John McCall6bb80172010-03-30 21:47:33 +00006464 NamedDecl *FoundDecl = E->getFoundDecl();
6465 if (FoundDecl == E->getMemberDecl()) {
6466 FoundDecl = Member;
6467 } else {
6468 FoundDecl = cast_or_null<NamedDecl>(
6469 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6470 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006471 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006472 }
6473
Douglas Gregorb98b1992009-08-11 05:31:07 +00006474 if (!getDerived().AlwaysRebuild() &&
6475 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006476 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006477 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006478 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006479 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006480
Anders Carlsson1f240322009-12-22 05:24:09 +00006481 // Mark it referenced in the new context regardless.
6482 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006483 SemaRef.MarkMemberReferenced(E);
6484
John McCall3fa5cae2010-10-26 07:05:15 +00006485 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006486 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006487
John McCalld5532b62009-11-23 01:53:49 +00006488 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006489 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006490 TransArgs.setLAngleLoc(E->getLAngleLoc());
6491 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006492 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6493 E->getNumTemplateArgs(),
6494 TransArgs))
6495 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006496 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006497
Douglas Gregorb98b1992009-08-11 05:31:07 +00006498 // FIXME: Bogus source location for the operator
6499 SourceLocation FakeOperatorLoc
6500 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6501
John McCallc2233c52010-01-15 08:34:02 +00006502 // FIXME: to do this check properly, we will need to preserve the
6503 // first-qualifier-in-scope here, just in case we had a dependent
6504 // base (and therefore couldn't do the check) and a
6505 // nested-name-qualifier (and therefore could do the lookup).
6506 NamedDecl *FirstQualifierInScope = 0;
6507
John McCall9ae2f072010-08-23 23:25:46 +00006508 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006509 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006510 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006511 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006512 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006513 Member,
John McCall6bb80172010-03-30 21:47:33 +00006514 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006515 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006516 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006517 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006518}
Mike Stump1eb44332009-09-09 15:08:12 +00006519
Douglas Gregorb98b1992009-08-11 05:31:07 +00006520template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006521ExprResult
John McCall454feb92009-12-08 09:21:05 +00006522TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006523 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006524 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006525 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006526
John McCall60d7b3a2010-08-24 06:29:42 +00006527 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006528 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006529 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006530
Douglas Gregorb98b1992009-08-11 05:31:07 +00006531 if (!getDerived().AlwaysRebuild() &&
6532 LHS.get() == E->getLHS() &&
6533 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006534 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006535
Lang Hamesbe9af122012-10-02 04:45:10 +00006536 Sema::FPContractStateRAII FPContractState(getSema());
6537 getSema().FPFeatures.fp_contract = E->isFPContractable();
6538
Douglas Gregorb98b1992009-08-11 05:31:07 +00006539 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006540 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006541}
6542
Mike Stump1eb44332009-09-09 15:08:12 +00006543template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006544ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006545TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006546 CompoundAssignOperator *E) {
6547 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006548}
Mike Stump1eb44332009-09-09 15:08:12 +00006549
Douglas Gregorb98b1992009-08-11 05:31:07 +00006550template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006551ExprResult TreeTransform<Derived>::
6552TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6553 // Just rebuild the common and RHS expressions and see whether we
6554 // get any changes.
6555
6556 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6557 if (commonExpr.isInvalid())
6558 return ExprError();
6559
6560 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6561 if (rhs.isInvalid())
6562 return ExprError();
6563
6564 if (!getDerived().AlwaysRebuild() &&
6565 commonExpr.get() == e->getCommon() &&
6566 rhs.get() == e->getFalseExpr())
6567 return SemaRef.Owned(e);
6568
6569 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6570 e->getQuestionLoc(),
6571 0,
6572 e->getColonLoc(),
6573 rhs.get());
6574}
6575
6576template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006577ExprResult
John McCall454feb92009-12-08 09:21:05 +00006578TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006579 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006580 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006581 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006582
John McCall60d7b3a2010-08-24 06:29:42 +00006583 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006584 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006585 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006586
John McCall60d7b3a2010-08-24 06:29:42 +00006587 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006588 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006589 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006590
Douglas Gregorb98b1992009-08-11 05:31:07 +00006591 if (!getDerived().AlwaysRebuild() &&
6592 Cond.get() == E->getCond() &&
6593 LHS.get() == E->getLHS() &&
6594 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006595 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006596
John McCall9ae2f072010-08-23 23:25:46 +00006597 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006598 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006599 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006600 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006601 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006602}
Mike Stump1eb44332009-09-09 15:08:12 +00006603
6604template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006605ExprResult
John McCall454feb92009-12-08 09:21:05 +00006606TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006607 // Implicit casts are eliminated during transformation, since they
6608 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006609 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006610}
Mike Stump1eb44332009-09-09 15:08:12 +00006611
Douglas Gregorb98b1992009-08-11 05:31:07 +00006612template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006613ExprResult
John McCall454feb92009-12-08 09:21:05 +00006614TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006615 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6616 if (!Type)
6617 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006618
John McCall60d7b3a2010-08-24 06:29:42 +00006619 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006620 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006621 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006622 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006623
Douglas Gregorb98b1992009-08-11 05:31:07 +00006624 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006625 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006626 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006627 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006628
John McCall9d125032010-01-15 18:39:57 +00006629 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006630 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006631 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006632 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006633}
Mike Stump1eb44332009-09-09 15:08:12 +00006634
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006636ExprResult
John McCall454feb92009-12-08 09:21:05 +00006637TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006638 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6639 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6640 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006641 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006642
John McCall60d7b3a2010-08-24 06:29:42 +00006643 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006644 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006645 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006646
Douglas Gregorb98b1992009-08-11 05:31:07 +00006647 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006648 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006649 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006650 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006651
John McCall1d7d8d62010-01-19 22:33:45 +00006652 // Note: the expression type doesn't necessarily match the
6653 // type-as-written, but that's okay, because it should always be
6654 // derivable from the initializer.
6655
John McCall42f56b52010-01-18 19:35:47 +00006656 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006657 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006658 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006659}
Mike Stump1eb44332009-09-09 15:08:12 +00006660
Douglas Gregorb98b1992009-08-11 05:31:07 +00006661template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006662ExprResult
John McCall454feb92009-12-08 09:21:05 +00006663TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006664 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006665 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006666 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006667
Douglas Gregorb98b1992009-08-11 05:31:07 +00006668 if (!getDerived().AlwaysRebuild() &&
6669 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006670 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006671
Douglas Gregorb98b1992009-08-11 05:31:07 +00006672 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006673 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006674 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006675 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006676 E->getAccessorLoc(),
6677 E->getAccessor());
6678}
Mike Stump1eb44332009-09-09 15:08:12 +00006679
Douglas Gregorb98b1992009-08-11 05:31:07 +00006680template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006681ExprResult
John McCall454feb92009-12-08 09:21:05 +00006682TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006683 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006684
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006685 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006686 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006687 Inits, &InitChanged))
6688 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006689
Douglas Gregorb98b1992009-08-11 05:31:07 +00006690 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006691 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006692
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006693 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006694 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006695}
Mike Stump1eb44332009-09-09 15:08:12 +00006696
Douglas Gregorb98b1992009-08-11 05:31:07 +00006697template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006698ExprResult
John McCall454feb92009-12-08 09:21:05 +00006699TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006700 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006701
Douglas Gregor43959a92009-08-20 07:17:43 +00006702 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006703 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006704 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006705 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006706
Douglas Gregor43959a92009-08-20 07:17:43 +00006707 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006708 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006709 bool ExprChanged = false;
6710 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6711 DEnd = E->designators_end();
6712 D != DEnd; ++D) {
6713 if (D->isFieldDesignator()) {
6714 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6715 D->getDotLoc(),
6716 D->getFieldLoc()));
6717 continue;
6718 }
Mike Stump1eb44332009-09-09 15:08:12 +00006719
Douglas Gregorb98b1992009-08-11 05:31:07 +00006720 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006721 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006722 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006723 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006724
6725 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006726 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006727
Douglas Gregorb98b1992009-08-11 05:31:07 +00006728 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6729 ArrayExprs.push_back(Index.release());
6730 continue;
6731 }
Mike Stump1eb44332009-09-09 15:08:12 +00006732
Douglas Gregorb98b1992009-08-11 05:31:07 +00006733 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006734 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006735 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6736 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006737 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006738
John McCall60d7b3a2010-08-24 06:29:42 +00006739 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006740 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006741 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006742
6743 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006744 End.get(),
6745 D->getLBracketLoc(),
6746 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006747
Douglas Gregorb98b1992009-08-11 05:31:07 +00006748 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6749 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006750
Douglas Gregorb98b1992009-08-11 05:31:07 +00006751 ArrayExprs.push_back(Start.release());
6752 ArrayExprs.push_back(End.release());
6753 }
Mike Stump1eb44332009-09-09 15:08:12 +00006754
Douglas Gregorb98b1992009-08-11 05:31:07 +00006755 if (!getDerived().AlwaysRebuild() &&
6756 Init.get() == E->getInit() &&
6757 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006758 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006759
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006760 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006761 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006762 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006763}
Mike Stump1eb44332009-09-09 15:08:12 +00006764
Douglas Gregorb98b1992009-08-11 05:31:07 +00006765template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006766ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006767TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006768 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006769 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006770
Douglas Gregor5557b252009-10-28 00:29:27 +00006771 // FIXME: Will we ever have proper type location here? Will we actually
6772 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006773 QualType T = getDerived().TransformType(E->getType());
6774 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006775 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006776
Douglas Gregorb98b1992009-08-11 05:31:07 +00006777 if (!getDerived().AlwaysRebuild() &&
6778 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006779 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006780
Douglas Gregorb98b1992009-08-11 05:31:07 +00006781 return getDerived().RebuildImplicitValueInitExpr(T);
6782}
Mike Stump1eb44332009-09-09 15:08:12 +00006783
Douglas Gregorb98b1992009-08-11 05:31:07 +00006784template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006785ExprResult
John McCall454feb92009-12-08 09:21:05 +00006786TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006787 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6788 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006789 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006790
John McCall60d7b3a2010-08-24 06:29:42 +00006791 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006792 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006793 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006794
Douglas Gregorb98b1992009-08-11 05:31:07 +00006795 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006796 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006797 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006798 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006799
John McCall9ae2f072010-08-23 23:25:46 +00006800 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006801 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006802}
6803
6804template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006805ExprResult
John McCall454feb92009-12-08 09:21:05 +00006806TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006807 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006808 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00006809 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6810 &ArgumentChanged))
6811 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006812
Douglas Gregorb98b1992009-08-11 05:31:07 +00006813 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006814 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006815 E->getRParenLoc());
6816}
Mike Stump1eb44332009-09-09 15:08:12 +00006817
Douglas Gregorb98b1992009-08-11 05:31:07 +00006818/// \brief Transform an address-of-label expression.
6819///
6820/// By default, the transformation of an address-of-label expression always
6821/// rebuilds the expression, so that the label identifier can be resolved to
6822/// the corresponding label statement by semantic analysis.
6823template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006824ExprResult
John McCall454feb92009-12-08 09:21:05 +00006825TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006826 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6827 E->getLabel());
6828 if (!LD)
6829 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006830
Douglas Gregorb98b1992009-08-11 05:31:07 +00006831 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006832 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006833}
Mike Stump1eb44332009-09-09 15:08:12 +00006834
6835template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006836ExprResult
John McCall454feb92009-12-08 09:21:05 +00006837TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006838 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006839 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006840 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006841 if (SubStmt.isInvalid()) {
6842 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006843 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006844 }
Mike Stump1eb44332009-09-09 15:08:12 +00006845
Douglas Gregorb98b1992009-08-11 05:31:07 +00006846 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006847 SubStmt.get() == E->getSubStmt()) {
6848 // Calling this an 'error' is unintuitive, but it does the right thing.
6849 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006850 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006851 }
Mike Stump1eb44332009-09-09 15:08:12 +00006852
6853 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006854 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006855 E->getRParenLoc());
6856}
Mike Stump1eb44332009-09-09 15:08:12 +00006857
Douglas Gregorb98b1992009-08-11 05:31:07 +00006858template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006859ExprResult
John McCall454feb92009-12-08 09:21:05 +00006860TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006861 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006862 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006863 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006864
John McCall60d7b3a2010-08-24 06:29:42 +00006865 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006866 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006867 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006868
John McCall60d7b3a2010-08-24 06:29:42 +00006869 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006870 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006871 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006872
Douglas Gregorb98b1992009-08-11 05:31:07 +00006873 if (!getDerived().AlwaysRebuild() &&
6874 Cond.get() == E->getCond() &&
6875 LHS.get() == E->getLHS() &&
6876 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006877 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006878
Douglas Gregorb98b1992009-08-11 05:31:07 +00006879 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006880 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006881 E->getRParenLoc());
6882}
Mike Stump1eb44332009-09-09 15:08:12 +00006883
Douglas Gregorb98b1992009-08-11 05:31:07 +00006884template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006885ExprResult
John McCall454feb92009-12-08 09:21:05 +00006886TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006887 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006888}
6889
6890template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006891ExprResult
John McCall454feb92009-12-08 09:21:05 +00006892TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006893 switch (E->getOperator()) {
6894 case OO_New:
6895 case OO_Delete:
6896 case OO_Array_New:
6897 case OO_Array_Delete:
6898 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006899
Douglas Gregor668d6d92009-12-13 20:44:55 +00006900 case OO_Call: {
6901 // This is a call to an object's operator().
6902 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6903
6904 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006905 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006906 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006907 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006908
6909 // FIXME: Poor location information
6910 SourceLocation FakeLParenLoc
6911 = SemaRef.PP.getLocForEndOfToken(
6912 static_cast<Expr *>(Object.get())->getLocEnd());
6913
6914 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006915 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006916 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006917 Args))
6918 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006919
John McCall9ae2f072010-08-23 23:25:46 +00006920 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006921 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006922 E->getLocEnd());
6923 }
6924
6925#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6926 case OO_##Name:
6927#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6928#include "clang/Basic/OperatorKinds.def"
6929 case OO_Subscript:
6930 // Handled below.
6931 break;
6932
6933 case OO_Conditional:
6934 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006935
6936 case OO_None:
6937 case NUM_OVERLOADED_OPERATORS:
6938 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006939 }
6940
John McCall60d7b3a2010-08-24 06:29:42 +00006941 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006942 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006943 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006944
Richard Smithefeeccf2012-10-21 03:28:35 +00006945 ExprResult First;
6946 if (E->getOperator() == OO_Amp)
6947 First = getDerived().TransformAddressOfOperand(E->getArg(0));
6948 else
6949 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006950 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006951 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006952
John McCall60d7b3a2010-08-24 06:29:42 +00006953 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006954 if (E->getNumArgs() == 2) {
6955 Second = getDerived().TransformExpr(E->getArg(1));
6956 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006957 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006958 }
Mike Stump1eb44332009-09-09 15:08:12 +00006959
Douglas Gregorb98b1992009-08-11 05:31:07 +00006960 if (!getDerived().AlwaysRebuild() &&
6961 Callee.get() == E->getCallee() &&
6962 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006963 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006964 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006965
Lang Hamesbe9af122012-10-02 04:45:10 +00006966 Sema::FPContractStateRAII FPContractState(getSema());
6967 getSema().FPFeatures.fp_contract = E->isFPContractable();
6968
Douglas Gregorb98b1992009-08-11 05:31:07 +00006969 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6970 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006971 Callee.get(),
6972 First.get(),
6973 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006974}
Mike Stump1eb44332009-09-09 15:08:12 +00006975
Douglas Gregorb98b1992009-08-11 05:31:07 +00006976template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006977ExprResult
John McCall454feb92009-12-08 09:21:05 +00006978TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6979 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006980}
Mike Stump1eb44332009-09-09 15:08:12 +00006981
Douglas Gregorb98b1992009-08-11 05:31:07 +00006982template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006983ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006984TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6985 // Transform the callee.
6986 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6987 if (Callee.isInvalid())
6988 return ExprError();
6989
6990 // Transform exec config.
6991 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6992 if (EC.isInvalid())
6993 return ExprError();
6994
6995 // Transform arguments.
6996 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006997 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006998 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006999 &ArgChanged))
7000 return ExprError();
7001
7002 if (!getDerived().AlwaysRebuild() &&
7003 Callee.get() == E->getCallee() &&
7004 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007005 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00007006
7007 // FIXME: Wrong source location information for the '('.
7008 SourceLocation FakeLParenLoc
7009 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7010 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007011 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007012 E->getRParenLoc(), EC.get());
7013}
7014
7015template<typename Derived>
7016ExprResult
John McCall454feb92009-12-08 09:21:05 +00007017TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007018 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7019 if (!Type)
7020 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007021
John McCall60d7b3a2010-08-24 06:29:42 +00007022 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007023 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007024 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007025 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007026
Douglas Gregorb98b1992009-08-11 05:31:07 +00007027 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007028 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007029 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007030 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007031 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007032 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007033 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007034 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007035 E->getAngleBrackets().getEnd(),
7036 // FIXME. this should be '(' location
7037 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007038 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007039 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007040}
Mike Stump1eb44332009-09-09 15:08:12 +00007041
Douglas Gregorb98b1992009-08-11 05:31:07 +00007042template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007043ExprResult
John McCall454feb92009-12-08 09:21:05 +00007044TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7045 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007046}
Mike Stump1eb44332009-09-09 15:08:12 +00007047
7048template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007049ExprResult
John McCall454feb92009-12-08 09:21:05 +00007050TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7051 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007052}
7053
Douglas Gregorb98b1992009-08-11 05:31:07 +00007054template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007055ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007056TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007057 CXXReinterpretCastExpr *E) {
7058 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007059}
Mike Stump1eb44332009-09-09 15:08:12 +00007060
Douglas Gregorb98b1992009-08-11 05:31:07 +00007061template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007062ExprResult
John McCall454feb92009-12-08 09:21:05 +00007063TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7064 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007065}
Mike Stump1eb44332009-09-09 15:08:12 +00007066
Douglas Gregorb98b1992009-08-11 05:31:07 +00007067template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007068ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007069TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007070 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007071 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7072 if (!Type)
7073 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007074
John McCall60d7b3a2010-08-24 06:29:42 +00007075 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007076 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007077 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007078 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007079
Douglas Gregorb98b1992009-08-11 05:31:07 +00007080 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007081 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007082 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007083 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007084
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007085 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007086 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007087 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007088 E->getRParenLoc());
7089}
Mike Stump1eb44332009-09-09 15:08:12 +00007090
Douglas Gregorb98b1992009-08-11 05:31:07 +00007091template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007092ExprResult
John McCall454feb92009-12-08 09:21:05 +00007093TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007094 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007095 TypeSourceInfo *TInfo
7096 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7097 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007098 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007099
Douglas Gregorb98b1992009-08-11 05:31:07 +00007100 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007101 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007102 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007103
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007104 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7105 E->getLocStart(),
7106 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007107 E->getLocEnd());
7108 }
Mike Stump1eb44332009-09-09 15:08:12 +00007109
Eli Friedmanef331b72012-01-20 01:26:23 +00007110 // We don't know whether the subexpression is potentially evaluated until
7111 // after we perform semantic analysis. We speculatively assume it is
7112 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007113 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007114 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7115 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007116
John McCall60d7b3a2010-08-24 06:29:42 +00007117 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007118 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007119 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007120
Douglas Gregorb98b1992009-08-11 05:31:07 +00007121 if (!getDerived().AlwaysRebuild() &&
7122 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007123 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007124
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007125 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7126 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007127 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007128 E->getLocEnd());
7129}
7130
7131template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007132ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007133TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7134 if (E->isTypeOperand()) {
7135 TypeSourceInfo *TInfo
7136 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7137 if (!TInfo)
7138 return ExprError();
7139
7140 if (!getDerived().AlwaysRebuild() &&
7141 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007142 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007143
Douglas Gregor3c52a212011-03-06 17:40:41 +00007144 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007145 E->getLocStart(),
7146 TInfo,
7147 E->getLocEnd());
7148 }
7149
Francois Pichet01b7c302010-09-08 12:20:18 +00007150 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7151
7152 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7153 if (SubExpr.isInvalid())
7154 return ExprError();
7155
7156 if (!getDerived().AlwaysRebuild() &&
7157 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007158 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007159
7160 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7161 E->getLocStart(),
7162 SubExpr.get(),
7163 E->getLocEnd());
7164}
7165
7166template<typename Derived>
7167ExprResult
John McCall454feb92009-12-08 09:21:05 +00007168TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007169 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007170}
Mike Stump1eb44332009-09-09 15:08:12 +00007171
Douglas Gregorb98b1992009-08-11 05:31:07 +00007172template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007173ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007174TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007175 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007176 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007177}
Mike Stump1eb44332009-09-09 15:08:12 +00007178
Douglas Gregorb98b1992009-08-11 05:31:07 +00007179template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007180ExprResult
John McCall454feb92009-12-08 09:21:05 +00007181TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007182 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007183 QualType T;
7184 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7185 T = MD->getThisType(getSema().Context);
Douglas Gregore4743be2013-03-08 22:43:48 +00007186 else if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(DC)) {
Richard Smith7a614d82011-06-11 17:19:42 +00007187 T = getSema().Context.getPointerType(
Douglas Gregore4743be2013-03-08 22:43:48 +00007188 getSema().Context.getRecordType(Record));
7189 } else {
7190 assert(SemaRef.Context.getDiagnostics().hasErrorOccurred() &&
7191 "this in the wrong scope?");
7192 return ExprError();
7193 }
Mike Stump1eb44332009-09-09 15:08:12 +00007194
Douglas Gregorec79d872012-02-24 17:41:38 +00007195 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7196 // Make sure that we capture 'this'.
7197 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007198 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007199 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007200
Douglas Gregor828a1972010-01-07 23:12:05 +00007201 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007202}
Mike Stump1eb44332009-09-09 15:08:12 +00007203
Douglas Gregorb98b1992009-08-11 05:31:07 +00007204template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007205ExprResult
John McCall454feb92009-12-08 09:21:05 +00007206TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007207 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007208 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007209 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007210
Douglas Gregorb98b1992009-08-11 05:31:07 +00007211 if (!getDerived().AlwaysRebuild() &&
7212 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007213 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007214
Douglas Gregorbca01b42011-07-06 22:04:06 +00007215 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7216 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007217}
Mike Stump1eb44332009-09-09 15:08:12 +00007218
Douglas Gregorb98b1992009-08-11 05:31:07 +00007219template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007220ExprResult
John McCall454feb92009-12-08 09:21:05 +00007221TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007222 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007223 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7224 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007225 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007226 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007227
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007228 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007229 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007230 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007231
Douglas Gregor036aed12009-12-23 23:03:06 +00007232 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007233}
Mike Stump1eb44332009-09-09 15:08:12 +00007234
Douglas Gregorb98b1992009-08-11 05:31:07 +00007235template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007236ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007237TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7238 CXXScalarValueInitExpr *E) {
7239 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7240 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007241 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007242
Douglas Gregorb98b1992009-08-11 05:31:07 +00007243 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007244 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007245 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007246
Chad Rosier4a9d7952012-08-08 18:46:20 +00007247 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007248 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007249 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007250}
Mike Stump1eb44332009-09-09 15:08:12 +00007251
Douglas Gregorb98b1992009-08-11 05:31:07 +00007252template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007253ExprResult
John McCall454feb92009-12-08 09:21:05 +00007254TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007255 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007256 TypeSourceInfo *AllocTypeInfo
7257 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7258 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007259 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007260
Douglas Gregorb98b1992009-08-11 05:31:07 +00007261 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007262 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007263 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007264 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007265
Douglas Gregorb98b1992009-08-11 05:31:07 +00007266 // Transform the placement arguments (if any).
7267 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007268 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007269 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007270 E->getNumPlacementArgs(), true,
7271 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007272 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007273
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007274 // Transform the initializer (if any).
7275 Expr *OldInit = E->getInitializer();
7276 ExprResult NewInit;
7277 if (OldInit)
7278 NewInit = getDerived().TransformExpr(OldInit);
7279 if (NewInit.isInvalid())
7280 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007281
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007282 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007283 FunctionDecl *OperatorNew = 0;
7284 if (E->getOperatorNew()) {
7285 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007286 getDerived().TransformDecl(E->getLocStart(),
7287 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007288 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007289 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007290 }
7291
7292 FunctionDecl *OperatorDelete = 0;
7293 if (E->getOperatorDelete()) {
7294 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007295 getDerived().TransformDecl(E->getLocStart(),
7296 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007297 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007298 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007299 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007300
Douglas Gregorb98b1992009-08-11 05:31:07 +00007301 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007302 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007303 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007304 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007305 OperatorNew == E->getOperatorNew() &&
7306 OperatorDelete == E->getOperatorDelete() &&
7307 !ArgumentChanged) {
7308 // Mark any declarations we need as referenced.
7309 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007310 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007311 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007312 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007313 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007314
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007315 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007316 QualType ElementType
7317 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7318 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7319 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7320 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007321 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007322 }
7323 }
7324 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007325
John McCall3fa5cae2010-10-26 07:05:15 +00007326 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007327 }
Mike Stump1eb44332009-09-09 15:08:12 +00007328
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007329 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007330 if (!ArraySize.get()) {
7331 // If no array size was specified, but the new expression was
7332 // instantiated with an array type (e.g., "new T" where T is
7333 // instantiated with "int[4]"), extract the outer bound from the
7334 // array type as our array size. We do this with constant and
7335 // dependently-sized array types.
7336 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7337 if (!ArrayT) {
7338 // Do nothing
7339 } else if (const ConstantArrayType *ConsArrayT
7340 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007341 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007342 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007343 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007344 SemaRef.Context.getSizeType(),
7345 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007346 AllocType = ConsArrayT->getElementType();
7347 } else if (const DependentSizedArrayType *DepArrayT
7348 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7349 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007350 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007351 AllocType = DepArrayT->getElementType();
7352 }
7353 }
7354 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007355
Douglas Gregorb98b1992009-08-11 05:31:07 +00007356 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7357 E->isGlobalNew(),
7358 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007359 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007360 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007361 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007362 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007363 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007364 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007365 E->getDirectInitRange(),
7366 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007367}
Mike Stump1eb44332009-09-09 15:08:12 +00007368
Douglas Gregorb98b1992009-08-11 05:31:07 +00007369template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007370ExprResult
John McCall454feb92009-12-08 09:21:05 +00007371TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007372 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007373 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007374 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007375
Douglas Gregor1af74512010-02-26 00:38:10 +00007376 // Transform the delete operator, if known.
7377 FunctionDecl *OperatorDelete = 0;
7378 if (E->getOperatorDelete()) {
7379 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007380 getDerived().TransformDecl(E->getLocStart(),
7381 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007382 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007383 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007384 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007385
Douglas Gregorb98b1992009-08-11 05:31:07 +00007386 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007387 Operand.get() == E->getArgument() &&
7388 OperatorDelete == E->getOperatorDelete()) {
7389 // Mark any declarations we need as referenced.
7390 // FIXME: instantiation-specific.
7391 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007392 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007393
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007394 if (!E->getArgument()->isTypeDependent()) {
7395 QualType Destroyed = SemaRef.Context.getBaseElementType(
7396 E->getDestroyedType());
7397 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7398 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007399 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007400 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007401 }
7402 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007403
John McCall3fa5cae2010-10-26 07:05:15 +00007404 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007405 }
Mike Stump1eb44332009-09-09 15:08:12 +00007406
Douglas Gregorb98b1992009-08-11 05:31:07 +00007407 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7408 E->isGlobalDelete(),
7409 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007410 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007411}
Mike Stump1eb44332009-09-09 15:08:12 +00007412
Douglas Gregorb98b1992009-08-11 05:31:07 +00007413template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007414ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007415TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007416 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007417 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007418 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007419 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007420
John McCallb3d87482010-08-24 05:47:05 +00007421 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007422 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007423 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007424 E->getOperatorLoc(),
7425 E->isArrow()? tok::arrow : tok::period,
7426 ObjectTypePtr,
7427 MayBePseudoDestructor);
7428 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007429 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007430
John McCallb3d87482010-08-24 05:47:05 +00007431 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007432 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7433 if (QualifierLoc) {
7434 QualifierLoc
7435 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7436 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007437 return ExprError();
7438 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007439 CXXScopeSpec SS;
7440 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007441
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007442 PseudoDestructorTypeStorage Destroyed;
7443 if (E->getDestroyedTypeInfo()) {
7444 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007445 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007446 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007447 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007448 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007449 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007450 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007451 // We aren't likely to be able to resolve the identifier down to a type
7452 // now anyway, so just retain the identifier.
7453 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7454 E->getDestroyedTypeLoc());
7455 } else {
7456 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007457 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007458 *E->getDestroyedTypeIdentifier(),
7459 E->getDestroyedTypeLoc(),
7460 /*Scope=*/0,
7461 SS, ObjectTypePtr,
7462 false);
7463 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007464 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007465
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007466 Destroyed
7467 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7468 E->getDestroyedTypeLoc());
7469 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007470
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007471 TypeSourceInfo *ScopeTypeInfo = 0;
7472 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007473 CXXScopeSpec EmptySS;
7474 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7475 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007476 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007477 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007478 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007479
John McCall9ae2f072010-08-23 23:25:46 +00007480 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007481 E->getOperatorLoc(),
7482 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007483 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007484 ScopeTypeInfo,
7485 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007486 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007487 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007488}
Mike Stump1eb44332009-09-09 15:08:12 +00007489
Douglas Gregora71d8192009-09-04 17:36:40 +00007490template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007491ExprResult
John McCallba135432009-11-21 08:51:07 +00007492TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007493 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007494 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7495 Sema::LookupOrdinaryName);
7496
7497 // Transform all the decls.
7498 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7499 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007500 NamedDecl *InstD = static_cast<NamedDecl*>(
7501 getDerived().TransformDecl(Old->getNameLoc(),
7502 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007503 if (!InstD) {
7504 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7505 // This can happen because of dependent hiding.
7506 if (isa<UsingShadowDecl>(*I))
7507 continue;
7508 else
John McCallf312b1e2010-08-26 23:41:50 +00007509 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007510 }
John McCallf7a1a742009-11-24 19:00:30 +00007511
7512 // Expand using declarations.
7513 if (isa<UsingDecl>(InstD)) {
7514 UsingDecl *UD = cast<UsingDecl>(InstD);
7515 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7516 E = UD->shadow_end(); I != E; ++I)
7517 R.addDecl(*I);
7518 continue;
7519 }
7520
7521 R.addDecl(InstD);
7522 }
7523
7524 // Resolve a kind, but don't do any further analysis. If it's
7525 // ambiguous, the callee needs to deal with it.
7526 R.resolveKind();
7527
7528 // Rebuild the nested-name qualifier, if present.
7529 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007530 if (Old->getQualifierLoc()) {
7531 NestedNameSpecifierLoc QualifierLoc
7532 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7533 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007534 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007535
Douglas Gregor4c9be892011-02-28 20:01:57 +00007536 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007537 }
7538
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007539 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007540 CXXRecordDecl *NamingClass
7541 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7542 Old->getNameLoc(),
7543 Old->getNamingClass()));
7544 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007545 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007546
Douglas Gregor66c45152010-04-27 16:10:10 +00007547 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007548 }
7549
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007550 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7551
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007552 // If we have neither explicit template arguments, nor the template keyword,
7553 // it's a normal declaration name.
7554 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007555 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7556
7557 // If we have template arguments, rebuild them, then rebuild the
7558 // templateid expression.
7559 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007560 if (Old->hasExplicitTemplateArgs() &&
7561 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007562 Old->getNumTemplateArgs(),
7563 TransArgs))
7564 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007565
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007566 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007567 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007568}
Mike Stump1eb44332009-09-09 15:08:12 +00007569
Douglas Gregorb98b1992009-08-11 05:31:07 +00007570template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007571ExprResult
John McCall454feb92009-12-08 09:21:05 +00007572TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007573 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7574 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007575 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007576
Douglas Gregorb98b1992009-08-11 05:31:07 +00007577 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007578 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007579 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007580
Mike Stump1eb44332009-09-09 15:08:12 +00007581 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007582 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007583 T,
7584 E->getLocEnd());
7585}
Mike Stump1eb44332009-09-09 15:08:12 +00007586
Douglas Gregorb98b1992009-08-11 05:31:07 +00007587template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007588ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007589TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7590 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7591 if (!LhsT)
7592 return ExprError();
7593
7594 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7595 if (!RhsT)
7596 return ExprError();
7597
7598 if (!getDerived().AlwaysRebuild() &&
7599 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7600 return SemaRef.Owned(E);
7601
7602 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7603 E->getLocStart(),
7604 LhsT, RhsT,
7605 E->getLocEnd());
7606}
7607
7608template<typename Derived>
7609ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007610TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7611 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007612 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007613 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7614 TypeSourceInfo *From = E->getArg(I);
7615 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007616 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007617 TypeLocBuilder TLB;
7618 TLB.reserve(FromTL.getFullDataSize());
7619 QualType To = getDerived().TransformType(TLB, FromTL);
7620 if (To.isNull())
7621 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007622
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007623 if (To == From->getType())
7624 Args.push_back(From);
7625 else {
7626 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7627 ArgChanged = true;
7628 }
7629 continue;
7630 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007631
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007632 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007633
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007634 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007635 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007636 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7637 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7638 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007639
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007640 // Determine whether the set of unexpanded parameter packs can and should
7641 // be expanded.
7642 bool Expand = true;
7643 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007644 Optional<unsigned> OrigNumExpansions =
7645 ExpansionTL.getTypePtr()->getNumExpansions();
7646 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007647 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7648 PatternTL.getSourceRange(),
7649 Unexpanded,
7650 Expand, RetainExpansion,
7651 NumExpansions))
7652 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007653
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007654 if (!Expand) {
7655 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007656 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007657 // expansion.
7658 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007659
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007660 TypeLocBuilder TLB;
7661 TLB.reserve(From->getTypeLoc().getFullDataSize());
7662
7663 QualType To = getDerived().TransformType(TLB, PatternTL);
7664 if (To.isNull())
7665 return ExprError();
7666
Chad Rosier4a9d7952012-08-08 18:46:20 +00007667 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007668 PatternTL.getSourceRange(),
7669 ExpansionTL.getEllipsisLoc(),
7670 NumExpansions);
7671 if (To.isNull())
7672 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007673
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007674 PackExpansionTypeLoc ToExpansionTL
7675 = TLB.push<PackExpansionTypeLoc>(To);
7676 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7677 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7678 continue;
7679 }
7680
7681 // Expand the pack expansion by substituting for each argument in the
7682 // pack(s).
7683 for (unsigned I = 0; I != *NumExpansions; ++I) {
7684 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7685 TypeLocBuilder TLB;
7686 TLB.reserve(PatternTL.getFullDataSize());
7687 QualType To = getDerived().TransformType(TLB, PatternTL);
7688 if (To.isNull())
7689 return ExprError();
7690
7691 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7692 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007693
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007694 if (!RetainExpansion)
7695 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007696
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007697 // If we're supposed to retain a pack expansion, do so by temporarily
7698 // forgetting the partially-substituted parameter pack.
7699 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7700
7701 TypeLocBuilder TLB;
7702 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007703
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007704 QualType To = getDerived().TransformType(TLB, PatternTL);
7705 if (To.isNull())
7706 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007707
7708 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007709 PatternTL.getSourceRange(),
7710 ExpansionTL.getEllipsisLoc(),
7711 NumExpansions);
7712 if (To.isNull())
7713 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007714
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007715 PackExpansionTypeLoc ToExpansionTL
7716 = TLB.push<PackExpansionTypeLoc>(To);
7717 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7718 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7719 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007720
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007721 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7722 return SemaRef.Owned(E);
7723
7724 return getDerived().RebuildTypeTrait(E->getTrait(),
7725 E->getLocStart(),
7726 Args,
7727 E->getLocEnd());
7728}
7729
7730template<typename Derived>
7731ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007732TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7733 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7734 if (!T)
7735 return ExprError();
7736
7737 if (!getDerived().AlwaysRebuild() &&
7738 T == E->getQueriedTypeSourceInfo())
7739 return SemaRef.Owned(E);
7740
7741 ExprResult SubExpr;
7742 {
7743 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7744 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7745 if (SubExpr.isInvalid())
7746 return ExprError();
7747
7748 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7749 return SemaRef.Owned(E);
7750 }
7751
7752 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7753 E->getLocStart(),
7754 T,
7755 SubExpr.get(),
7756 E->getLocEnd());
7757}
7758
7759template<typename Derived>
7760ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007761TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7762 ExprResult SubExpr;
7763 {
7764 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7765 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7766 if (SubExpr.isInvalid())
7767 return ExprError();
7768
7769 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7770 return SemaRef.Owned(E);
7771 }
7772
7773 return getDerived().RebuildExpressionTrait(
7774 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7775}
7776
7777template<typename Derived>
7778ExprResult
John McCall865d4472009-11-19 22:55:06 +00007779TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007780 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00007781 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
7782}
7783
7784template<typename Derived>
7785ExprResult
7786TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
7787 DependentScopeDeclRefExpr *E,
7788 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007789 NestedNameSpecifierLoc QualifierLoc
7790 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7791 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007792 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007793 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007794
John McCall43fed0d2010-11-12 08:19:04 +00007795 // TODO: If this is a conversion-function-id, verify that the
7796 // destination type name (if present) resolves the same way after
7797 // instantiation as it did in the local scope.
7798
Abramo Bagnara25777432010-08-11 22:01:17 +00007799 DeclarationNameInfo NameInfo
7800 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7801 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007802 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007803
John McCallf7a1a742009-11-24 19:00:30 +00007804 if (!E->hasExplicitTemplateArgs()) {
7805 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007806 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007807 // Note: it is sufficient to compare the Name component of NameInfo:
7808 // if name has not changed, DNLoc has not changed either.
7809 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007810 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007811
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007812 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007813 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007814 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007815 /*TemplateArgs*/ 0,
7816 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007817 }
John McCalld5532b62009-11-23 01:53:49 +00007818
7819 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007820 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7821 E->getNumTemplateArgs(),
7822 TransArgs))
7823 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007824
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007825 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007826 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007827 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007828 &TransArgs,
7829 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007830}
7831
7832template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007833ExprResult
John McCall454feb92009-12-08 09:21:05 +00007834TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00007835 // CXXConstructExprs other than for list-initialization and
7836 // CXXTemporaryObjectExpr are always implicit, so when we have
7837 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00007838 if ((E->getNumArgs() == 1 ||
7839 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00007840 (!getDerived().DropCallArgument(E->getArg(0))) &&
7841 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00007842 return getDerived().TransformExpr(E->getArg(0));
7843
Douglas Gregorb98b1992009-08-11 05:31:07 +00007844 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7845
7846 QualType T = getDerived().TransformType(E->getType());
7847 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007848 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007849
7850 CXXConstructorDecl *Constructor
7851 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007852 getDerived().TransformDecl(E->getLocStart(),
7853 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007854 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007855 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007856
Douglas Gregorb98b1992009-08-11 05:31:07 +00007857 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007858 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007859 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007860 &ArgumentChanged))
7861 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007862
Douglas Gregorb98b1992009-08-11 05:31:07 +00007863 if (!getDerived().AlwaysRebuild() &&
7864 T == E->getType() &&
7865 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007866 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007867 // Mark the constructor as referenced.
7868 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007869 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007870 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007871 }
Mike Stump1eb44332009-09-09 15:08:12 +00007872
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007873 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7874 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007875 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007876 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00007877 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007878 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007879 E->getConstructionKind(),
7880 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007881}
Mike Stump1eb44332009-09-09 15:08:12 +00007882
Douglas Gregorb98b1992009-08-11 05:31:07 +00007883/// \brief Transform a C++ temporary-binding expression.
7884///
Douglas Gregor51326552009-12-24 18:51:59 +00007885/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7886/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007887template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007888ExprResult
John McCall454feb92009-12-08 09:21:05 +00007889TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007890 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007891}
Mike Stump1eb44332009-09-09 15:08:12 +00007892
John McCall4765fa02010-12-06 08:20:24 +00007893/// \brief Transform a C++ expression that contains cleanups that should
7894/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007895///
John McCall4765fa02010-12-06 08:20:24 +00007896/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007897/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007898template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007899ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007900TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007901 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007902}
Mike Stump1eb44332009-09-09 15:08:12 +00007903
Douglas Gregorb98b1992009-08-11 05:31:07 +00007904template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007905ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007906TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007907 CXXTemporaryObjectExpr *E) {
7908 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7909 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007910 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007911
Douglas Gregorb98b1992009-08-11 05:31:07 +00007912 CXXConstructorDecl *Constructor
7913 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00007914 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007915 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007916 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007917 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007918
Douglas Gregorb98b1992009-08-11 05:31:07 +00007919 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007920 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007921 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007922 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007923 &ArgumentChanged))
7924 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007925
Douglas Gregorb98b1992009-08-11 05:31:07 +00007926 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007927 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007928 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007929 !ArgumentChanged) {
7930 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007931 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007932 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007933 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007934
Richard Smithc83c2302012-12-19 01:39:02 +00007935 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00007936 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7937 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007938 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007939 E->getLocEnd());
7940}
Mike Stump1eb44332009-09-09 15:08:12 +00007941
Douglas Gregorb98b1992009-08-11 05:31:07 +00007942template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007943ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007944TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007945 // Transform the type of the lambda parameters and start the definition of
7946 // the lambda itself.
7947 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00007948 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00007949 if (!MethodTy)
7950 return ExprError();
7951
Eli Friedman8da8a662012-09-19 01:18:11 +00007952 // Create the local class that will describe the lambda.
7953 CXXRecordDecl *Class
7954 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7955 MethodTy,
7956 /*KnownDependent=*/false);
7957 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7958
Douglas Gregorc6889e72012-02-14 22:28:59 +00007959 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007960 SmallVector<QualType, 4> ParamTypes;
7961 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00007962 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7963 E->getCallOperator()->param_begin(),
7964 E->getCallOperator()->param_size(),
7965 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00007966 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00007967
Douglas Gregordfca6f52012-02-13 22:00:16 +00007968 // Build the call operator.
7969 CXXMethodDecl *CallOperator
7970 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007971 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007972 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007973 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007974 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00007975
Richard Smith612409e2012-07-25 03:56:55 +00007976 return getDerived().TransformLambdaScope(E, CallOperator);
7977}
7978
7979template<typename Derived>
7980ExprResult
7981TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
7982 CXXMethodDecl *CallOperator) {
Douglas Gregord5387e82012-02-14 00:00:48 +00007983 // Introduce the context of the call operator.
7984 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7985
Douglas Gregordfca6f52012-02-13 22:00:16 +00007986 // Enter the scope of the lambda.
7987 sema::LambdaScopeInfo *LSI
7988 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7989 E->getCaptureDefault(),
7990 E->hasExplicitParameters(),
7991 E->hasExplicitResultType(),
7992 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007993
Douglas Gregordfca6f52012-02-13 22:00:16 +00007994 // Transform captures.
Richard Smith612409e2012-07-25 03:56:55 +00007995 bool Invalid = false;
Douglas Gregordfca6f52012-02-13 22:00:16 +00007996 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007997 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007998 CEnd = E->capture_end();
7999 C != CEnd; ++C) {
8000 // When we hit the first implicit capture, tell Sema that we've finished
8001 // the list of explicit captures.
8002 if (!FinishedExplicitCaptures && C->isImplicit()) {
8003 getSema().finishLambdaExplicitCaptures(LSI);
8004 FinishedExplicitCaptures = true;
8005 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008006
Douglas Gregordfca6f52012-02-13 22:00:16 +00008007 // Capturing 'this' is trivial.
8008 if (C->capturesThis()) {
8009 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8010 continue;
8011 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008012
Douglas Gregora7365242012-02-14 19:27:52 +00008013 // Determine the capture kind for Sema.
8014 Sema::TryCaptureKind Kind
8015 = C->isImplicit()? Sema::TryCapture_Implicit
8016 : C->getCaptureKind() == LCK_ByCopy
8017 ? Sema::TryCapture_ExplicitByVal
8018 : Sema::TryCapture_ExplicitByRef;
8019 SourceLocation EllipsisLoc;
8020 if (C->isPackExpansion()) {
8021 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8022 bool ShouldExpand = false;
8023 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008024 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008025 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8026 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008027 Unexpanded,
8028 ShouldExpand, RetainExpansion,
8029 NumExpansions))
8030 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008031
Douglas Gregora7365242012-02-14 19:27:52 +00008032 if (ShouldExpand) {
8033 // The transform has determined that we should perform an expansion;
8034 // transform and capture each of the arguments.
8035 // expansion of the pattern. Do so.
8036 VarDecl *Pack = C->getCapturedVar();
8037 for (unsigned I = 0; I != *NumExpansions; ++I) {
8038 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8039 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008040 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008041 Pack));
8042 if (!CapturedVar) {
8043 Invalid = true;
8044 continue;
8045 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008046
Douglas Gregora7365242012-02-14 19:27:52 +00008047 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008048 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8049 }
Douglas Gregora7365242012-02-14 19:27:52 +00008050 continue;
8051 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008052
Douglas Gregora7365242012-02-14 19:27:52 +00008053 EllipsisLoc = C->getEllipsisLoc();
8054 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008055
Douglas Gregordfca6f52012-02-13 22:00:16 +00008056 // Transform the captured variable.
8057 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008058 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008059 C->getCapturedVar()));
8060 if (!CapturedVar) {
8061 Invalid = true;
8062 continue;
8063 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008064
Douglas Gregordfca6f52012-02-13 22:00:16 +00008065 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008066 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008067 }
8068 if (!FinishedExplicitCaptures)
8069 getSema().finishLambdaExplicitCaptures(LSI);
8070
Douglas Gregordfca6f52012-02-13 22:00:16 +00008071
8072 // Enter a new evaluation context to insulate the lambda from any
8073 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008074 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008075
8076 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008077 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008078 /*IsInstantiation=*/true);
8079 return ExprError();
8080 }
8081
8082 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008083 StmtResult Body = getDerived().TransformStmt(E->getBody());
8084 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008085 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008086 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008087 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008088 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008089
Chad Rosier4a9d7952012-08-08 18:46:20 +00008090 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008091 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008092}
8093
8094template<typename Derived>
8095ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008096TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008097 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008098 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8099 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008100 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008101
Douglas Gregorb98b1992009-08-11 05:31:07 +00008102 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008103 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008104 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008105 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008106 &ArgumentChanged))
8107 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008108
Douglas Gregorb98b1992009-08-11 05:31:07 +00008109 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008110 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008111 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008112 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008113
Douglas Gregorb98b1992009-08-11 05:31:07 +00008114 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008115 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008116 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008117 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008118 E->getRParenLoc());
8119}
Mike Stump1eb44332009-09-09 15:08:12 +00008120
Douglas Gregorb98b1992009-08-11 05:31:07 +00008121template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008122ExprResult
John McCall865d4472009-11-19 22:55:06 +00008123TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008124 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008125 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008126 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008127 Expr *OldBase;
8128 QualType BaseType;
8129 QualType ObjectType;
8130 if (!E->isImplicitAccess()) {
8131 OldBase = E->getBase();
8132 Base = getDerived().TransformExpr(OldBase);
8133 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008134 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008135
John McCallaa81e162009-12-01 22:10:20 +00008136 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008137 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008138 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008139 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008140 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008141 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008142 ObjectTy,
8143 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008144 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008145 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008146
John McCallb3d87482010-08-24 05:47:05 +00008147 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008148 BaseType = ((Expr*) Base.get())->getType();
8149 } else {
8150 OldBase = 0;
8151 BaseType = getDerived().TransformType(E->getBaseType());
8152 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8153 }
Mike Stump1eb44332009-09-09 15:08:12 +00008154
Douglas Gregor6cd21982009-10-20 05:58:46 +00008155 // Transform the first part of the nested-name-specifier that qualifies
8156 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008157 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008158 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008159 E->getFirstQualifierFoundInScope(),
8160 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008161
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008162 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008163 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008164 QualifierLoc
8165 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8166 ObjectType,
8167 FirstQualifierInScope);
8168 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008169 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008170 }
Mike Stump1eb44332009-09-09 15:08:12 +00008171
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008172 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8173
John McCall43fed0d2010-11-12 08:19:04 +00008174 // TODO: If this is a conversion-function-id, verify that the
8175 // destination type name (if present) resolves the same way after
8176 // instantiation as it did in the local scope.
8177
Abramo Bagnara25777432010-08-11 22:01:17 +00008178 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008179 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008180 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008181 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008182
John McCallaa81e162009-12-01 22:10:20 +00008183 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008184 // This is a reference to a member without an explicitly-specified
8185 // template argument list. Optimize for this common case.
8186 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008187 Base.get() == OldBase &&
8188 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008189 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008190 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008191 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008192 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008193
John McCall9ae2f072010-08-23 23:25:46 +00008194 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008195 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008196 E->isArrow(),
8197 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008198 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008199 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008200 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008201 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008202 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008203 }
8204
John McCalld5532b62009-11-23 01:53:49 +00008205 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008206 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8207 E->getNumTemplateArgs(),
8208 TransArgs))
8209 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008210
John McCall9ae2f072010-08-23 23:25:46 +00008211 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008212 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008213 E->isArrow(),
8214 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008215 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008216 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008217 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008218 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008219 &TransArgs);
8220}
8221
8222template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008223ExprResult
John McCall454feb92009-12-08 09:21:05 +00008224TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008225 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008226 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008227 QualType BaseType;
8228 if (!Old->isImplicitAccess()) {
8229 Base = getDerived().TransformExpr(Old->getBase());
8230 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008231 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008232 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8233 Old->isArrow());
8234 if (Base.isInvalid())
8235 return ExprError();
8236 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008237 } else {
8238 BaseType = getDerived().TransformType(Old->getBaseType());
8239 }
John McCall129e2df2009-11-30 22:42:35 +00008240
Douglas Gregor4c9be892011-02-28 20:01:57 +00008241 NestedNameSpecifierLoc QualifierLoc;
8242 if (Old->getQualifierLoc()) {
8243 QualifierLoc
8244 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8245 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008246 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008247 }
8248
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008249 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8250
Abramo Bagnara25777432010-08-11 22:01:17 +00008251 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008252 Sema::LookupOrdinaryName);
8253
8254 // Transform all the decls.
8255 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8256 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008257 NamedDecl *InstD = static_cast<NamedDecl*>(
8258 getDerived().TransformDecl(Old->getMemberLoc(),
8259 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008260 if (!InstD) {
8261 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8262 // This can happen because of dependent hiding.
8263 if (isa<UsingShadowDecl>(*I))
8264 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008265 else {
8266 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008267 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008268 }
John McCall9f54ad42009-12-10 09:41:52 +00008269 }
John McCall129e2df2009-11-30 22:42:35 +00008270
8271 // Expand using declarations.
8272 if (isa<UsingDecl>(InstD)) {
8273 UsingDecl *UD = cast<UsingDecl>(InstD);
8274 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8275 E = UD->shadow_end(); I != E; ++I)
8276 R.addDecl(*I);
8277 continue;
8278 }
8279
8280 R.addDecl(InstD);
8281 }
8282
8283 R.resolveKind();
8284
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008285 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008286 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008287 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008288 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008289 Old->getMemberLoc(),
8290 Old->getNamingClass()));
8291 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008292 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008293
Douglas Gregor66c45152010-04-27 16:10:10 +00008294 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008295 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008296
John McCall129e2df2009-11-30 22:42:35 +00008297 TemplateArgumentListInfo TransArgs;
8298 if (Old->hasExplicitTemplateArgs()) {
8299 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8300 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008301 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8302 Old->getNumTemplateArgs(),
8303 TransArgs))
8304 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008305 }
John McCallc2233c52010-01-15 08:34:02 +00008306
8307 // FIXME: to do this check properly, we will need to preserve the
8308 // first-qualifier-in-scope here, just in case we had a dependent
8309 // base (and therefore couldn't do the check) and a
8310 // nested-name-qualifier (and therefore could do the lookup).
8311 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008312
John McCall9ae2f072010-08-23 23:25:46 +00008313 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008314 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008315 Old->getOperatorLoc(),
8316 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008317 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008318 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008319 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008320 R,
8321 (Old->hasExplicitTemplateArgs()
8322 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008323}
8324
8325template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008326ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008327TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008328 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008329 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8330 if (SubExpr.isInvalid())
8331 return ExprError();
8332
8333 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008334 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008335
8336 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8337}
8338
8339template<typename Derived>
8340ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008341TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008342 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8343 if (Pattern.isInvalid())
8344 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008345
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008346 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8347 return SemaRef.Owned(E);
8348
Douglas Gregor67fd1252011-01-14 21:20:45 +00008349 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8350 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008351}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008352
8353template<typename Derived>
8354ExprResult
8355TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8356 // If E is not value-dependent, then nothing will change when we transform it.
8357 // Note: This is an instantiation-centric view.
8358 if (!E->isValueDependent())
8359 return SemaRef.Owned(E);
8360
8361 // Note: None of the implementations of TryExpandParameterPacks can ever
8362 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008363 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008364 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8365 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008366 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008367 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008368 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008369 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008370 ShouldExpand, RetainExpansion,
8371 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008372 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008373
Douglas Gregor089e8932011-10-10 18:59:29 +00008374 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008375 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008376
Douglas Gregor089e8932011-10-10 18:59:29 +00008377 NamedDecl *Pack = E->getPack();
8378 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008379 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008380 Pack));
8381 if (!Pack)
8382 return ExprError();
8383 }
8384
Chad Rosier4a9d7952012-08-08 18:46:20 +00008385
Douglas Gregoree8aff02011-01-04 17:33:58 +00008386 // We now know the length of the parameter pack, so build a new expression
8387 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008388 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8389 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008390 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008391}
8392
Douglas Gregorbe230c32011-01-03 17:17:50 +00008393template<typename Derived>
8394ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008395TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8396 SubstNonTypeTemplateParmPackExpr *E) {
8397 // Default behavior is to do nothing with this transformation.
8398 return SemaRef.Owned(E);
8399}
8400
8401template<typename Derived>
8402ExprResult
John McCall91a57552011-07-15 05:09:51 +00008403TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8404 SubstNonTypeTemplateParmExpr *E) {
8405 // Default behavior is to do nothing with this transformation.
8406 return SemaRef.Owned(E);
8407}
8408
8409template<typename Derived>
8410ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008411TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8412 // Default behavior is to do nothing with this transformation.
8413 return SemaRef.Owned(E);
8414}
8415
8416template<typename Derived>
8417ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008418TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8419 MaterializeTemporaryExpr *E) {
8420 return getDerived().TransformExpr(E->GetTemporaryExpr());
8421}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008422
Douglas Gregor03e80032011-06-21 17:03:29 +00008423template<typename Derived>
8424ExprResult
John McCall454feb92009-12-08 09:21:05 +00008425TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008426 return SemaRef.MaybeBindToTemporary(E);
8427}
8428
8429template<typename Derived>
8430ExprResult
8431TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008432 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008433}
8434
8435template<typename Derived>
8436ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008437TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8438 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8439 if (SubExpr.isInvalid())
8440 return ExprError();
8441
8442 if (!getDerived().AlwaysRebuild() &&
8443 SubExpr.get() == E->getSubExpr())
8444 return SemaRef.Owned(E);
8445
8446 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008447}
8448
8449template<typename Derived>
8450ExprResult
8451TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8452 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008453 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008454 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008455 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008456 /*IsCall=*/false, Elements, &ArgChanged))
8457 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008458
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008459 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8460 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008461
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008462 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8463 Elements.data(),
8464 Elements.size());
8465}
8466
8467template<typename Derived>
8468ExprResult
8469TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008470 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008471 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008472 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008473 bool ArgChanged = false;
8474 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8475 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008476
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008477 if (OrigElement.isPackExpansion()) {
8478 // This key/value element is a pack expansion.
8479 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8480 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8481 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8482 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8483
8484 // Determine whether the set of unexpanded parameter packs can
8485 // and should be expanded.
8486 bool Expand = true;
8487 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008488 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8489 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008490 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8491 OrigElement.Value->getLocEnd());
8492 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8493 PatternRange,
8494 Unexpanded,
8495 Expand, RetainExpansion,
8496 NumExpansions))
8497 return ExprError();
8498
8499 if (!Expand) {
8500 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008501 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008502 // expansion.
8503 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8504 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8505 if (Key.isInvalid())
8506 return ExprError();
8507
8508 if (Key.get() != OrigElement.Key)
8509 ArgChanged = true;
8510
8511 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8512 if (Value.isInvalid())
8513 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008514
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008515 if (Value.get() != OrigElement.Value)
8516 ArgChanged = true;
8517
Chad Rosier4a9d7952012-08-08 18:46:20 +00008518 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008519 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8520 };
8521 Elements.push_back(Expansion);
8522 continue;
8523 }
8524
8525 // Record right away that the argument was changed. This needs
8526 // to happen even if the array expands to nothing.
8527 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008528
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008529 // The transform has determined that we should perform an elementwise
8530 // expansion of the pattern. Do so.
8531 for (unsigned I = 0; I != *NumExpansions; ++I) {
8532 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8533 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8534 if (Key.isInvalid())
8535 return ExprError();
8536
8537 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8538 if (Value.isInvalid())
8539 return ExprError();
8540
Chad Rosier4a9d7952012-08-08 18:46:20 +00008541 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008542 Key.get(), Value.get(), SourceLocation(), NumExpansions
8543 };
8544
8545 // If any unexpanded parameter packs remain, we still have a
8546 // pack expansion.
8547 if (Key.get()->containsUnexpandedParameterPack() ||
8548 Value.get()->containsUnexpandedParameterPack())
8549 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008550
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008551 Elements.push_back(Element);
8552 }
8553
8554 // We've finished with this pack expansion.
8555 continue;
8556 }
8557
8558 // Transform and check key.
8559 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8560 if (Key.isInvalid())
8561 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008562
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008563 if (Key.get() != OrigElement.Key)
8564 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008565
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008566 // Transform and check value.
8567 ExprResult Value
8568 = getDerived().TransformExpr(OrigElement.Value);
8569 if (Value.isInvalid())
8570 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008571
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008572 if (Value.get() != OrigElement.Value)
8573 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008574
8575 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00008576 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008577 };
8578 Elements.push_back(Element);
8579 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008580
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008581 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8582 return SemaRef.MaybeBindToTemporary(E);
8583
8584 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8585 Elements.data(),
8586 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008587}
8588
Mike Stump1eb44332009-09-09 15:08:12 +00008589template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008590ExprResult
John McCall454feb92009-12-08 09:21:05 +00008591TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008592 TypeSourceInfo *EncodedTypeInfo
8593 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8594 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008595 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008596
Douglas Gregorb98b1992009-08-11 05:31:07 +00008597 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008598 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008599 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008600
8601 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008602 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008603 E->getRParenLoc());
8604}
Mike Stump1eb44332009-09-09 15:08:12 +00008605
Douglas Gregorb98b1992009-08-11 05:31:07 +00008606template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008607ExprResult TreeTransform<Derived>::
8608TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8609 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8610 if (result.isInvalid()) return ExprError();
8611 Expr *subExpr = result.take();
8612
8613 if (!getDerived().AlwaysRebuild() &&
8614 subExpr == E->getSubExpr())
8615 return SemaRef.Owned(E);
8616
8617 return SemaRef.Owned(new(SemaRef.Context)
8618 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8619}
8620
8621template<typename Derived>
8622ExprResult TreeTransform<Derived>::
8623TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008624 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008625 = getDerived().TransformType(E->getTypeInfoAsWritten());
8626 if (!TSInfo)
8627 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008628
John McCallf85e1932011-06-15 23:02:42 +00008629 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008630 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008631 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008632
John McCallf85e1932011-06-15 23:02:42 +00008633 if (!getDerived().AlwaysRebuild() &&
8634 TSInfo == E->getTypeInfoAsWritten() &&
8635 Result.get() == E->getSubExpr())
8636 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008637
John McCallf85e1932011-06-15 23:02:42 +00008638 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008639 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008640 Result.get());
8641}
8642
8643template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008644ExprResult
John McCall454feb92009-12-08 09:21:05 +00008645TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008646 // Transform arguments.
8647 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008648 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008649 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008650 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008651 &ArgChanged))
8652 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008653
Douglas Gregor92e986e2010-04-22 16:44:27 +00008654 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8655 // Class message: transform the receiver type.
8656 TypeSourceInfo *ReceiverTypeInfo
8657 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8658 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008659 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008660
Douglas Gregor92e986e2010-04-22 16:44:27 +00008661 // If nothing changed, just retain the existing message send.
8662 if (!getDerived().AlwaysRebuild() &&
8663 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008664 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008665
8666 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008667 SmallVector<SourceLocation, 16> SelLocs;
8668 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008669 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8670 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008671 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008672 E->getMethodDecl(),
8673 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008674 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008675 E->getRightLoc());
8676 }
8677
8678 // Instance message: transform the receiver
8679 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8680 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008681 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008682 = getDerived().TransformExpr(E->getInstanceReceiver());
8683 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008684 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008685
8686 // If nothing changed, just retain the existing message send.
8687 if (!getDerived().AlwaysRebuild() &&
8688 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008689 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008690
Douglas Gregor92e986e2010-04-22 16:44:27 +00008691 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008692 SmallVector<SourceLocation, 16> SelLocs;
8693 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008694 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008695 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008696 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008697 E->getMethodDecl(),
8698 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008699 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008700 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008701}
8702
Mike Stump1eb44332009-09-09 15:08:12 +00008703template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008704ExprResult
John McCall454feb92009-12-08 09:21:05 +00008705TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008706 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008707}
8708
Mike Stump1eb44332009-09-09 15:08:12 +00008709template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008710ExprResult
John McCall454feb92009-12-08 09:21:05 +00008711TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008712 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008713}
8714
Mike Stump1eb44332009-09-09 15:08:12 +00008715template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008716ExprResult
John McCall454feb92009-12-08 09:21:05 +00008717TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008718 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008719 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008720 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008721 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008722
8723 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008724
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008725 // If nothing changed, just retain the existing expression.
8726 if (!getDerived().AlwaysRebuild() &&
8727 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008728 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008729
John McCall9ae2f072010-08-23 23:25:46 +00008730 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008731 E->getLocation(),
8732 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008733}
8734
Mike Stump1eb44332009-09-09 15:08:12 +00008735template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008736ExprResult
John McCall454feb92009-12-08 09:21:05 +00008737TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008738 // 'super' and types never change. Property never changes. Just
8739 // retain the existing expression.
8740 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008741 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008742
Douglas Gregore3303542010-04-26 20:47:02 +00008743 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008744 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008745 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008746 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008747
Douglas Gregore3303542010-04-26 20:47:02 +00008748 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008749
Douglas Gregore3303542010-04-26 20:47:02 +00008750 // If nothing changed, just retain the existing expression.
8751 if (!getDerived().AlwaysRebuild() &&
8752 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008753 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008754
John McCall12f78a62010-12-02 01:19:52 +00008755 if (E->isExplicitProperty())
8756 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8757 E->getExplicitProperty(),
8758 E->getLocation());
8759
8760 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008761 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008762 E->getImplicitPropertyGetter(),
8763 E->getImplicitPropertySetter(),
8764 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008765}
8766
Mike Stump1eb44332009-09-09 15:08:12 +00008767template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008768ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008769TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8770 // Transform the base expression.
8771 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8772 if (Base.isInvalid())
8773 return ExprError();
8774
8775 // Transform the key expression.
8776 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8777 if (Key.isInvalid())
8778 return ExprError();
8779
8780 // If nothing changed, just retain the existing expression.
8781 if (!getDerived().AlwaysRebuild() &&
8782 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8783 return SemaRef.Owned(E);
8784
Chad Rosier4a9d7952012-08-08 18:46:20 +00008785 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008786 Base.get(), Key.get(),
8787 E->getAtIndexMethodDecl(),
8788 E->setAtIndexMethodDecl());
8789}
8790
8791template<typename Derived>
8792ExprResult
John McCall454feb92009-12-08 09:21:05 +00008793TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008794 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008795 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008796 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008797 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008798
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008799 // If nothing changed, just retain the existing expression.
8800 if (!getDerived().AlwaysRebuild() &&
8801 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008802 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008803
John McCall9ae2f072010-08-23 23:25:46 +00008804 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00008805 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008806 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008807}
8808
Mike Stump1eb44332009-09-09 15:08:12 +00008809template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008810ExprResult
John McCall454feb92009-12-08 09:21:05 +00008811TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008812 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008813 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008814 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008815 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008816 SubExprs, &ArgumentChanged))
8817 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008818
Douglas Gregorb98b1992009-08-11 05:31:07 +00008819 if (!getDerived().AlwaysRebuild() &&
8820 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008821 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008822
Douglas Gregorb98b1992009-08-11 05:31:07 +00008823 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008824 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008825 E->getRParenLoc());
8826}
8827
Mike Stump1eb44332009-09-09 15:08:12 +00008828template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008829ExprResult
John McCall454feb92009-12-08 09:21:05 +00008830TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008831 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008832
John McCallc6ac9c32011-02-04 18:33:18 +00008833 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8834 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8835
8836 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008837 blockScope->TheDecl->setBlockMissingReturnType(
8838 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008839
Chris Lattner686775d2011-07-20 06:58:45 +00008840 SmallVector<ParmVarDecl*, 4> params;
8841 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008842
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008843 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008844 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8845 oldBlock->param_begin(),
8846 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008847 0, paramTypes, &params)) {
8848 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008849 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008850 }
John McCallc6ac9c32011-02-04 18:33:18 +00008851
Jordan Rose09189892013-03-08 22:25:36 +00008852 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008853 QualType exprResultType =
8854 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008855
8856 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008857 if (exprResultType->isObjCObjectType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008858 getSema().Diag(E->getCaretLocation(),
8859 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008860 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008861 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008862 return ExprError();
8863 }
John McCall711c52b2011-01-05 12:14:39 +00008864
Jordan Rosebea522f2013-03-08 21:51:21 +00008865 QualType functionType =
8866 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00008867 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00008868 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008869
8870 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008871 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008872 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008873
8874 if (!oldBlock->blockMissingReturnType()) {
8875 blockScope->HasImplicitReturnType = false;
8876 blockScope->ReturnType = exprResultType;
8877 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008878
John McCall711c52b2011-01-05 12:14:39 +00008879 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008880 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008881 if (body.isInvalid()) {
8882 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008883 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008884 }
John McCall711c52b2011-01-05 12:14:39 +00008885
John McCallc6ac9c32011-02-04 18:33:18 +00008886#ifndef NDEBUG
8887 // In builds with assertions, make sure that we captured everything we
8888 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008889 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8890 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8891 e = oldBlock->capture_end(); i != e; ++i) {
8892 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008893
Douglas Gregorfc921372011-05-20 15:32:55 +00008894 // Ignore parameter packs.
8895 if (isa<ParmVarDecl>(oldCapture) &&
8896 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8897 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008898
Douglas Gregorfc921372011-05-20 15:32:55 +00008899 VarDecl *newCapture =
8900 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8901 oldCapture));
8902 assert(blockScope->CaptureMap.count(newCapture));
8903 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008904 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008905 }
8906#endif
8907
8908 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8909 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008910}
8911
Mike Stump1eb44332009-09-09 15:08:12 +00008912template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008913ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008914TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008915 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008916}
Eli Friedman276b0612011-10-11 02:20:01 +00008917
8918template<typename Derived>
8919ExprResult
8920TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008921 QualType RetTy = getDerived().TransformType(E->getType());
8922 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008923 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008924 SubExprs.reserve(E->getNumSubExprs());
8925 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8926 SubExprs, &ArgumentChanged))
8927 return ExprError();
8928
8929 if (!getDerived().AlwaysRebuild() &&
8930 !ArgumentChanged)
8931 return SemaRef.Owned(E);
8932
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008933 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008934 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008935}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008936
Douglas Gregorb98b1992009-08-11 05:31:07 +00008937//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008938// Type reconstruction
8939//===----------------------------------------------------------------------===//
8940
Mike Stump1eb44332009-09-09 15:08:12 +00008941template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008942QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8943 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008944 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008945 getDerived().getBaseEntity());
8946}
8947
Mike Stump1eb44332009-09-09 15:08:12 +00008948template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008949QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8950 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008951 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008952 getDerived().getBaseEntity());
8953}
8954
Mike Stump1eb44332009-09-09 15:08:12 +00008955template<typename Derived>
8956QualType
John McCall85737a72009-10-30 00:06:24 +00008957TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8958 bool WrittenAsLValue,
8959 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008960 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008961 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008962}
8963
8964template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008965QualType
John McCall85737a72009-10-30 00:06:24 +00008966TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8967 QualType ClassType,
8968 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008969 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008970 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008971}
8972
8973template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008974QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008975TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8976 ArrayType::ArraySizeModifier SizeMod,
8977 const llvm::APInt *Size,
8978 Expr *SizeExpr,
8979 unsigned IndexTypeQuals,
8980 SourceRange BracketsRange) {
8981 if (SizeExpr || !Size)
8982 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8983 IndexTypeQuals, BracketsRange,
8984 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008985
8986 QualType Types[] = {
8987 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8988 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8989 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008990 };
8991 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8992 QualType SizeType;
8993 for (unsigned I = 0; I != NumTypes; ++I)
8994 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8995 SizeType = Types[I];
8996 break;
8997 }
Mike Stump1eb44332009-09-09 15:08:12 +00008998
Eli Friedman01f276d2012-01-25 23:20:27 +00008999 // Note that we can return a VariableArrayType here in the case where
9000 // the element type was a dependent VariableArrayType.
9001 IntegerLiteral *ArraySize
9002 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9003 /*FIXME*/BracketsRange.getBegin());
9004 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009005 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00009006 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009007}
Mike Stump1eb44332009-09-09 15:08:12 +00009008
Douglas Gregor577f75a2009-08-04 16:50:30 +00009009template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009010QualType
9011TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009012 ArrayType::ArraySizeModifier SizeMod,
9013 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009014 unsigned IndexTypeQuals,
9015 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009016 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009017 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009018}
9019
9020template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009021QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009022TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009023 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009024 unsigned IndexTypeQuals,
9025 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009026 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009027 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009028}
Mike Stump1eb44332009-09-09 15:08:12 +00009029
Douglas Gregor577f75a2009-08-04 16:50:30 +00009030template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009031QualType
9032TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009033 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009034 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009035 unsigned IndexTypeQuals,
9036 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009037 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009038 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009039 IndexTypeQuals, BracketsRange);
9040}
9041
9042template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009043QualType
9044TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009045 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009046 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009047 unsigned IndexTypeQuals,
9048 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009049 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009050 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009051 IndexTypeQuals, BracketsRange);
9052}
9053
9054template<typename Derived>
9055QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009056 unsigned NumElements,
9057 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009058 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009059 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009060}
Mike Stump1eb44332009-09-09 15:08:12 +00009061
Douglas Gregor577f75a2009-08-04 16:50:30 +00009062template<typename Derived>
9063QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9064 unsigned NumElements,
9065 SourceLocation AttributeLoc) {
9066 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9067 NumElements, true);
9068 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009069 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9070 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009071 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009072}
Mike Stump1eb44332009-09-09 15:08:12 +00009073
Douglas Gregor577f75a2009-08-04 16:50:30 +00009074template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009075QualType
9076TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009077 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009078 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009079 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009080}
Mike Stump1eb44332009-09-09 15:08:12 +00009081
Douglas Gregor577f75a2009-08-04 16:50:30 +00009082template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009083QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9084 QualType T,
9085 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009086 const FunctionProtoType::ExtProtoInfo &EPI) {
9087 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009088 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009089 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009090 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009091}
Mike Stump1eb44332009-09-09 15:08:12 +00009092
Douglas Gregor577f75a2009-08-04 16:50:30 +00009093template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009094QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9095 return SemaRef.Context.getFunctionNoProtoType(T);
9096}
9097
9098template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009099QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9100 assert(D && "no decl found");
9101 if (D->isInvalidDecl()) return QualType();
9102
Douglas Gregor92e986e2010-04-22 16:44:27 +00009103 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009104 TypeDecl *Ty;
9105 if (isa<UsingDecl>(D)) {
9106 UsingDecl *Using = cast<UsingDecl>(D);
9107 assert(Using->isTypeName() &&
9108 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9109
9110 // A valid resolved using typename decl points to exactly one type decl.
9111 assert(++Using->shadow_begin() == Using->shadow_end());
9112 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009113
John McCalled976492009-12-04 22:46:56 +00009114 } else {
9115 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9116 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9117 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9118 }
9119
9120 return SemaRef.Context.getTypeDeclType(Ty);
9121}
9122
9123template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009124QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9125 SourceLocation Loc) {
9126 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009127}
9128
9129template<typename Derived>
9130QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9131 return SemaRef.Context.getTypeOfType(Underlying);
9132}
9133
9134template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009135QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9136 SourceLocation Loc) {
9137 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009138}
9139
9140template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009141QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9142 UnaryTransformType::UTTKind UKind,
9143 SourceLocation Loc) {
9144 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9145}
9146
9147template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009148QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009149 TemplateName Template,
9150 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009151 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009152 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009153}
Mike Stump1eb44332009-09-09 15:08:12 +00009154
Douglas Gregordcee1a12009-08-06 05:28:30 +00009155template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009156QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9157 SourceLocation KWLoc) {
9158 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9159}
9160
9161template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009162TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009163TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009164 bool TemplateKW,
9165 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009166 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009167 Template);
9168}
9169
9170template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009171TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009172TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9173 const IdentifierInfo &Name,
9174 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009175 QualType ObjectType,
9176 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009177 UnqualifiedId TemplateName;
9178 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009179 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009180 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009181 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009182 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009183 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009184 /*EnteringContext=*/false,
9185 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009186 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009187}
Mike Stump1eb44332009-09-09 15:08:12 +00009188
Douglas Gregorb98b1992009-08-11 05:31:07 +00009189template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009190TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009191TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009192 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009193 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009194 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009195 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009196 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009197 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009198 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009199 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009200 Sema::TemplateTy Template;
9201 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009202 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009203 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009204 /*EnteringContext=*/false,
9205 Template);
9206 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009207}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009208
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009209template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009210ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009211TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9212 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009213 Expr *OrigCallee,
9214 Expr *First,
9215 Expr *Second) {
9216 Expr *Callee = OrigCallee->IgnoreParenCasts();
9217 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009218
Douglas Gregorb98b1992009-08-11 05:31:07 +00009219 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009220 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009221 if (!First->getType()->isOverloadableType() &&
9222 !Second->getType()->isOverloadableType())
9223 return getSema().CreateBuiltinArraySubscriptExpr(First,
9224 Callee->getLocStart(),
9225 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009226 } else if (Op == OO_Arrow) {
9227 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009228 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9229 } else if (Second == 0 || isPostIncDec) {
9230 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009231 // The argument is not of overloadable type, so try to create a
9232 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009233 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009234 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009235
John McCall9ae2f072010-08-23 23:25:46 +00009236 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009237 }
9238 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009239 if (!First->getType()->isOverloadableType() &&
9240 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009241 // Neither of the arguments is an overloadable type, so try to
9242 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009243 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009244 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009245 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009246 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009247 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009248
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009249 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009250 }
9251 }
Mike Stump1eb44332009-09-09 15:08:12 +00009252
9253 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009254 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009255 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009256
John McCall9ae2f072010-08-23 23:25:46 +00009257 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009258 assert(ULE->requiresADL());
9259
9260 // FIXME: Do we have to check
9261 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009262 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009263 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009264 // If we've resolved this to a particular non-member function, just call
9265 // that function. If we resolved it to a member function,
9266 // CreateOverloaded* will find that function for us.
9267 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9268 if (!isa<CXXMethodDecl>(ND))
9269 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009270 }
Mike Stump1eb44332009-09-09 15:08:12 +00009271
Douglas Gregorb98b1992009-08-11 05:31:07 +00009272 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009273 Expr *Args[2] = { First, Second };
9274 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009275
Douglas Gregorb98b1992009-08-11 05:31:07 +00009276 // Create the overloaded operator invocation for unary operators.
9277 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009278 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009279 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009280 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009281 }
Mike Stump1eb44332009-09-09 15:08:12 +00009282
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009283 if (Op == OO_Subscript) {
9284 SourceLocation LBrace;
9285 SourceLocation RBrace;
9286
9287 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9288 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9289 LBrace = SourceLocation::getFromRawEncoding(
9290 NameLoc.CXXOperatorName.BeginOpNameLoc);
9291 RBrace = SourceLocation::getFromRawEncoding(
9292 NameLoc.CXXOperatorName.EndOpNameLoc);
9293 } else {
9294 LBrace = Callee->getLocStart();
9295 RBrace = OpLoc;
9296 }
9297
9298 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9299 First, Second);
9300 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009301
Douglas Gregorb98b1992009-08-11 05:31:07 +00009302 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009303 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009304 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009305 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9306 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009307 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009308
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009309 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009310}
Mike Stump1eb44332009-09-09 15:08:12 +00009311
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009312template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009313ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009314TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009315 SourceLocation OperatorLoc,
9316 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009317 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009318 TypeSourceInfo *ScopeType,
9319 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009320 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009321 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009322 QualType BaseType = Base->getType();
9323 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009324 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009325 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009326 !BaseType->getAs<PointerType>()->getPointeeType()
9327 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009328 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009329 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009330 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009331 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009332 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009333 /*FIXME?*/true);
9334 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009335
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009336 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009337 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9338 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9339 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9340 NameInfo.setNamedTypeInfo(DestroyedType);
9341
Richard Smith6314db92012-05-15 06:15:11 +00009342 // The scope type is now known to be a valid nested name specifier
9343 // component. Tack it on to the end of the nested name specifier.
9344 if (ScopeType)
9345 SS.Extend(SemaRef.Context, SourceLocation(),
9346 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009347
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009348 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009349 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009350 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009351 SS, TemplateKWLoc,
9352 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009353 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009354 /*TemplateArgs*/ 0);
9355}
9356
Douglas Gregor577f75a2009-08-04 16:50:30 +00009357} // end namespace clang
9358
9359#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H