blob: 97316f89b329f0f3d5c87fd42270899fea06dc68 [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
Richard Smithc3bf52c2013-04-20 22:23:05 +00001983 /// \brief Build a new C++11 default-initialization expression.
1984 ///
1985 /// By default, builds a new default field initialization expression, which
1986 /// does not require any semantic analysis. Subclasses may override this
1987 /// routine to provide different behavior.
1988 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
1989 FieldDecl *Field) {
1990 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
1991 Field));
1992 }
1993
Douglas Gregorb98b1992009-08-11 05:31:07 +00001994 /// \brief Build a new C++ zero-initialization expression.
1995 ///
1996 /// By default, performs semantic analysis to build the new expression.
1997 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001998 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1999 SourceLocation LParenLoc,
2000 SourceLocation RParenLoc) {
2001 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Benjamin Kramer5354e772012-08-23 23:38:35 +00002002 MultiExprArg(), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002003 }
Mike Stump1eb44332009-09-09 15:08:12 +00002004
Douglas Gregorb98b1992009-08-11 05:31:07 +00002005 /// \brief Build a new C++ "new" expression.
2006 ///
2007 /// By default, performs semantic analysis to build the new expression.
2008 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002009 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002010 bool UseGlobal,
2011 SourceLocation PlacementLParen,
2012 MultiExprArg PlacementArgs,
2013 SourceLocation PlacementRParen,
2014 SourceRange TypeIdParens,
2015 QualType AllocatedType,
2016 TypeSourceInfo *AllocatedTypeInfo,
2017 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002018 SourceRange DirectInitRange,
2019 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00002020 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002021 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002022 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002023 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002024 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002025 AllocatedType,
2026 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002027 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002028 DirectInitRange,
2029 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002030 }
Mike Stump1eb44332009-09-09 15:08:12 +00002031
Douglas Gregorb98b1992009-08-11 05:31:07 +00002032 /// \brief Build a new C++ "delete" expression.
2033 ///
2034 /// By default, performs semantic analysis to build the new expression.
2035 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002036 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002037 bool IsGlobalDelete,
2038 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002039 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002040 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002041 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002042 }
Mike Stump1eb44332009-09-09 15:08:12 +00002043
Douglas Gregorb98b1992009-08-11 05:31:07 +00002044 /// \brief Build a new unary 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.
John McCall60d7b3a2010-08-24 06:29:42 +00002048 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002049 SourceLocation StartLoc,
2050 TypeSourceInfo *T,
2051 SourceLocation RParenLoc) {
2052 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002053 }
2054
Francois Pichet6ad6f282010-12-07 00:08:36 +00002055 /// \brief Build a new binary type trait expression.
2056 ///
2057 /// By default, performs semantic analysis to build the new expression.
2058 /// Subclasses may override this routine to provide different behavior.
2059 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2060 SourceLocation StartLoc,
2061 TypeSourceInfo *LhsT,
2062 TypeSourceInfo *RhsT,
2063 SourceLocation RParenLoc) {
2064 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2065 }
2066
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002067 /// \brief Build a new 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 RebuildTypeTrait(TypeTrait Trait,
2072 SourceLocation StartLoc,
2073 ArrayRef<TypeSourceInfo *> Args,
2074 SourceLocation RParenLoc) {
2075 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2076 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002077
John Wiegley21ff2e52011-04-28 00:16:57 +00002078 /// \brief Build a new array type trait expression.
2079 ///
2080 /// By default, performs semantic analysis to build the new expression.
2081 /// Subclasses may override this routine to provide different behavior.
2082 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2083 SourceLocation StartLoc,
2084 TypeSourceInfo *TSInfo,
2085 Expr *DimExpr,
2086 SourceLocation RParenLoc) {
2087 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2088 }
2089
John Wiegley55262202011-04-25 06:54:41 +00002090 /// \brief Build a new expression trait expression.
2091 ///
2092 /// By default, performs semantic analysis to build the new expression.
2093 /// Subclasses may override this routine to provide different behavior.
2094 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2095 SourceLocation StartLoc,
2096 Expr *Queried,
2097 SourceLocation RParenLoc) {
2098 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2099 }
2100
Mike Stump1eb44332009-09-09 15:08:12 +00002101 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002102 /// expression.
2103 ///
2104 /// By default, performs semantic analysis to build the new expression.
2105 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002106 ExprResult RebuildDependentScopeDeclRefExpr(
2107 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002108 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002109 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002110 const TemplateArgumentListInfo *TemplateArgs,
2111 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002112 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002113 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002114
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002115 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002116 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002117 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002118
Richard Smithefeeccf2012-10-21 03:28:35 +00002119 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2120 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002121 }
2122
2123 /// \brief Build a new template-id expression.
2124 ///
2125 /// By default, performs semantic analysis to build the new expression.
2126 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002127 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002128 SourceLocation TemplateKWLoc,
2129 LookupResult &R,
2130 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002131 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002132 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2133 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002134 }
2135
2136 /// \brief Build a new object-construction expression.
2137 ///
2138 /// By default, performs semantic analysis to build the new expression.
2139 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002140 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002141 SourceLocation Loc,
2142 CXXConstructorDecl *Constructor,
2143 bool IsElidable,
2144 MultiExprArg Args,
2145 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002146 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002147 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002148 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002149 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002150 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002151 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002152 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002153 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002154
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002155 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002156 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002157 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002158 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002159 RequiresZeroInit, ConstructKind,
2160 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002161 }
2162
2163 /// \brief Build a new object-construction expression.
2164 ///
2165 /// By default, performs semantic analysis to build the new expression.
2166 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002167 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2168 SourceLocation LParenLoc,
2169 MultiExprArg Args,
2170 SourceLocation RParenLoc) {
2171 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002172 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002173 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002174 RParenLoc);
2175 }
2176
2177 /// \brief Build a new object-construction expression.
2178 ///
2179 /// By default, performs semantic analysis to build the new expression.
2180 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002181 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2182 SourceLocation LParenLoc,
2183 MultiExprArg Args,
2184 SourceLocation RParenLoc) {
2185 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002186 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002187 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002188 RParenLoc);
2189 }
Mike Stump1eb44332009-09-09 15:08:12 +00002190
Douglas Gregorb98b1992009-08-11 05:31:07 +00002191 /// \brief Build a new member reference expression.
2192 ///
2193 /// By default, performs semantic analysis to build the new expression.
2194 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002195 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002196 QualType BaseType,
2197 bool IsArrow,
2198 SourceLocation OperatorLoc,
2199 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002200 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002201 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002202 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002203 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002204 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002205 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002206
John McCall9ae2f072010-08-23 23:25:46 +00002207 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002208 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002209 SS, TemplateKWLoc,
2210 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002211 MemberNameInfo,
2212 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002213 }
2214
John McCall129e2df2009-11-30 22:42:35 +00002215 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002216 ///
2217 /// By default, performs semantic analysis to build the new expression.
2218 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002219 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2220 SourceLocation OperatorLoc,
2221 bool IsArrow,
2222 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002223 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002224 NamedDecl *FirstQualifierInScope,
2225 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002226 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002227 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002228 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002229
John McCall9ae2f072010-08-23 23:25:46 +00002230 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002231 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002232 SS, TemplateKWLoc,
2233 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002234 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002235 }
Mike Stump1eb44332009-09-09 15:08:12 +00002236
Sebastian Redl2e156222010-09-10 20:55:43 +00002237 /// \brief Build a new noexcept expression.
2238 ///
2239 /// By default, performs semantic analysis to build the new expression.
2240 /// Subclasses may override this routine to provide different behavior.
2241 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2242 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2243 }
2244
Douglas Gregoree8aff02011-01-04 17:33:58 +00002245 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002246 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2247 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002248 SourceLocation RParenLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002249 Optional<unsigned> Length) {
Douglas Gregor089e8932011-10-10 18:59:29 +00002250 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002251 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2252 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002253 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002254
2255 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2256 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002257 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002258 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002259
Patrick Beardeb382ec2012-04-19 00:25:12 +00002260 /// \brief Build a new Objective-C boxed expression.
2261 ///
2262 /// By default, performs semantic analysis to build the new expression.
2263 /// Subclasses may override this routine to provide different behavior.
2264 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2265 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2266 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002267
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002268 /// \brief Build a new Objective-C array literal.
2269 ///
2270 /// By default, performs semantic analysis to build the new expression.
2271 /// Subclasses may override this routine to provide different behavior.
2272 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2273 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002274 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002275 MultiExprArg(Elements, NumElements));
2276 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002277
2278 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002279 Expr *Base, Expr *Key,
2280 ObjCMethodDecl *getterMethod,
2281 ObjCMethodDecl *setterMethod) {
2282 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2283 getterMethod, setterMethod);
2284 }
2285
2286 /// \brief Build a new Objective-C dictionary literal.
2287 ///
2288 /// By default, performs semantic analysis to build the new expression.
2289 /// Subclasses may override this routine to provide different behavior.
2290 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2291 ObjCDictionaryElement *Elements,
2292 unsigned NumElements) {
2293 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2294 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002295
James Dennett699c9042012-06-15 07:13:21 +00002296 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002297 ///
2298 /// By default, performs semantic analysis to build the new expression.
2299 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002300 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002301 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002302 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002303 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002304 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002305 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002306
Douglas Gregor92e986e2010-04-22 16:44:27 +00002307 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002308 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002309 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002310 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002311 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002312 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002313 MultiExprArg Args,
2314 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002315 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2316 ReceiverTypeInfo->getType(),
2317 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002318 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002319 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002320 }
2321
2322 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002323 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002324 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002325 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002326 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002327 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002328 MultiExprArg Args,
2329 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002330 return SemaRef.BuildInstanceMessage(Receiver,
2331 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002332 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002333 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002334 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002335 }
2336
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002337 /// \brief Build a new Objective-C ivar reference expression.
2338 ///
2339 /// By default, performs semantic analysis to build the new expression.
2340 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002341 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002342 SourceLocation IvarLoc,
2343 bool IsArrow, bool IsFreeIvar) {
2344 // FIXME: We lose track of the IsFreeIvar bit.
2345 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002346 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002347 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2348 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002349 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002350 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002351 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002352 false);
John Wiegley429bb272011-04-08 18:41:53 +00002353 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002354 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002355
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002356 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002357 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002358
John Wiegley429bb272011-04-08 18:41:53 +00002359 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002360 /*FIXME:*/IvarLoc, IsArrow,
2361 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002362 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002363 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002364 /*TemplateArgs=*/0);
2365 }
Douglas Gregore3303542010-04-26 20:47:02 +00002366
2367 /// \brief Build a new Objective-C property reference expression.
2368 ///
2369 /// By default, performs semantic analysis to build the new expression.
2370 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002371 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002372 ObjCPropertyDecl *Property,
2373 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002374 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002375 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002376 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2377 Sema::LookupMemberName);
2378 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002379 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002380 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002381 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002382 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002383 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002384
Douglas Gregore3303542010-04-26 20:47:02 +00002385 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002386 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002387
John Wiegley429bb272011-04-08 18:41:53 +00002388 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002389 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002390 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002391 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002392 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002393 /*TemplateArgs=*/0);
2394 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002395
John McCall12f78a62010-12-02 01:19:52 +00002396 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002397 ///
2398 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002399 /// Subclasses may override this routine to provide different behavior.
2400 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2401 ObjCMethodDecl *Getter,
2402 ObjCMethodDecl *Setter,
2403 SourceLocation PropertyLoc) {
2404 // Since these expressions can only be value-dependent, we do not
2405 // need to perform semantic analysis again.
2406 return Owned(
2407 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2408 VK_LValue, OK_ObjCProperty,
2409 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002410 }
2411
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002412 /// \brief Build a new Objective-C "isa" expression.
2413 ///
2414 /// By default, performs semantic analysis to build the new expression.
2415 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002416 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002417 SourceLocation OpLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002418 bool IsArrow) {
2419 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002420 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002421 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2422 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002423 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002424 OpLoc,
John McCalld226f652010-08-21 09:40:31 +00002425 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002426 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002427 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002428
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002429 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002430 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002431
John Wiegley429bb272011-04-08 18:41:53 +00002432 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002433 OpLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002434 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002435 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002436 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002437 /*TemplateArgs=*/0);
2438 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002439
Douglas Gregorb98b1992009-08-11 05:31:07 +00002440 /// \brief Build a new shuffle vector expression.
2441 ///
2442 /// By default, performs semantic analysis to build the new expression.
2443 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002444 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002445 MultiExprArg SubExprs,
2446 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002447 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002448 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002449 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2450 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2451 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002452 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002453
Douglas Gregorb98b1992009-08-11 05:31:07 +00002454 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002455 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002456 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2457 SemaRef.Context.BuiltinFnTy,
2458 VK_RValue, BuiltinLoc);
2459 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2460 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2461 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002462
2463 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002464 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002465 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002466 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002467 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002468 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002469
Douglas Gregorb98b1992009-08-11 05:31:07 +00002470 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002471 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002472 }
John McCall43fed0d2010-11-12 08:19:04 +00002473
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002474 /// \brief Build a new template argument pack expansion.
2475 ///
2476 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002477 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002478 /// different behavior.
2479 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002480 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002481 Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002482 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002483 case TemplateArgument::Expression: {
2484 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002485 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2486 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002487 if (Result.isInvalid())
2488 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002489
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002490 return TemplateArgumentLoc(Result.get(), Result.get());
2491 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002492
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002493 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002494 return TemplateArgumentLoc(TemplateArgument(
2495 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002496 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002497 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002498 Pattern.getTemplateNameLoc(),
2499 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002500
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002501 case TemplateArgument::Null:
2502 case TemplateArgument::Integral:
2503 case TemplateArgument::Declaration:
2504 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002505 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002506 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002507 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002508
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002509 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002510 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002511 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002512 EllipsisLoc,
2513 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002514 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2515 Expansion);
2516 break;
2517 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002518
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002519 return TemplateArgumentLoc();
2520 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002521
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002522 /// \brief Build a new expression pack expansion.
2523 ///
2524 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002525 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002526 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002527 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002528 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002529 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002530 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002531
2532 /// \brief Build a new atomic operation expression.
2533 ///
2534 /// By default, performs semantic analysis to build the new expression.
2535 /// Subclasses may override this routine to provide different behavior.
2536 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2537 MultiExprArg SubExprs,
2538 QualType RetTy,
2539 AtomicExpr::AtomicOp Op,
2540 SourceLocation RParenLoc) {
2541 // Just create the expression; there is not any interesting semantic
2542 // analysis here because we can't actually build an AtomicExpr until
2543 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002544 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002545 RParenLoc);
2546 }
2547
John McCall43fed0d2010-11-12 08:19:04 +00002548private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002549 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2550 QualType ObjectType,
2551 NamedDecl *FirstQualifierInScope,
2552 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002553
2554 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2555 QualType ObjectType,
2556 NamedDecl *FirstQualifierInScope,
2557 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002558};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002559
Douglas Gregor43959a92009-08-20 07:17:43 +00002560template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002561StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002562 if (!S)
2563 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002564
Douglas Gregor43959a92009-08-20 07:17:43 +00002565 switch (S->getStmtClass()) {
2566 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002567
Douglas Gregor43959a92009-08-20 07:17:43 +00002568 // Transform individual statement nodes
2569#define STMT(Node, Parent) \
2570 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002571#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002572#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002573#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002574
Douglas Gregor43959a92009-08-20 07:17:43 +00002575 // Transform expressions by calling TransformExpr.
2576#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002577#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002578#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002579#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002580 {
John McCall60d7b3a2010-08-24 06:29:42 +00002581 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002582 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002583 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002584
Richard Smith41956372013-01-14 22:39:08 +00002585 return getSema().ActOnExprStmt(E);
Douglas Gregor43959a92009-08-20 07:17:43 +00002586 }
Mike Stump1eb44332009-09-09 15:08:12 +00002587 }
2588
John McCall3fa5cae2010-10-26 07:05:15 +00002589 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002590}
Mike Stump1eb44332009-09-09 15:08:12 +00002591
2592
Douglas Gregor670444e2009-08-04 22:27:00 +00002593template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002594ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002595 if (!E)
2596 return SemaRef.Owned(E);
2597
2598 switch (E->getStmtClass()) {
2599 case Stmt::NoStmtClass: break;
2600#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002601#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002602#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002603 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002604#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002605 }
2606
John McCall3fa5cae2010-10-26 07:05:15 +00002607 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002608}
2609
2610template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002611ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2612 bool CXXDirectInit) {
2613 // Initializers are instantiated like expressions, except that various outer
2614 // layers are stripped.
2615 if (!Init)
2616 return SemaRef.Owned(Init);
2617
2618 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2619 Init = ExprTemp->getSubExpr();
2620
2621 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2622 Init = Binder->getSubExpr();
2623
2624 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2625 Init = ICE->getSubExprAsWritten();
2626
Richard Smith5cf15892012-12-21 08:13:35 +00002627 // If this is not a direct-initializer, we only need to reconstruct
2628 // InitListExprs. Other forms of copy-initialization will be a no-op if
2629 // the initializer is already the right type.
2630 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2631 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2632 return getDerived().TransformExpr(Init);
2633
2634 // Revert value-initialization back to empty parens.
2635 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2636 SourceRange Parens = VIE->getSourceRange();
2637 return getDerived().RebuildParenListExpr(Parens.getBegin(), MultiExprArg(),
2638 Parens.getEnd());
2639 }
2640
2641 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2642 if (isa<ImplicitValueInitExpr>(Init))
2643 return getDerived().RebuildParenListExpr(SourceLocation(), MultiExprArg(),
2644 SourceLocation());
2645
2646 // Revert initialization by constructor back to a parenthesized or braced list
2647 // of expressions. Any other form of initializer can just be reused directly.
2648 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002649 return getDerived().TransformExpr(Init);
2650
2651 SmallVector<Expr*, 8> NewArgs;
2652 bool ArgChanged = false;
2653 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2654 /*IsCall*/true, NewArgs, &ArgChanged))
2655 return ExprError();
2656
2657 // If this was list initialization, revert to list form.
2658 if (Construct->isListInitialization())
2659 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2660 Construct->getLocEnd(),
2661 Construct->getType());
2662
Richard Smithc83c2302012-12-19 01:39:02 +00002663 // Build a ParenListExpr to represent anything else.
2664 SourceRange Parens = Construct->getParenRange();
2665 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2666 Parens.getEnd());
2667}
2668
2669template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002670bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2671 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002672 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002673 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002674 bool *ArgChanged) {
2675 for (unsigned I = 0; I != NumInputs; ++I) {
2676 // If requested, drop call arguments that need to be dropped.
2677 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2678 if (ArgChanged)
2679 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002680
Douglas Gregoraa165f82011-01-03 19:04:46 +00002681 break;
2682 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002683
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002684 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2685 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002686
Chris Lattner686775d2011-07-20 06:58:45 +00002687 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002688 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2689 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002690
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002691 // Determine whether the set of unexpanded parameter packs can and should
2692 // be expanded.
2693 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002694 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00002695 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2696 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002697 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2698 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002699 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002700 Expand, RetainExpansion,
2701 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002702 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002703
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002704 if (!Expand) {
2705 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002706 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002707 // expansion.
2708 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2709 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2710 if (OutPattern.isInvalid())
2711 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002712
2713 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002714 Expansion->getEllipsisLoc(),
2715 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002716 if (Out.isInvalid())
2717 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002718
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002719 if (ArgChanged)
2720 *ArgChanged = true;
2721 Outputs.push_back(Out.get());
2722 continue;
2723 }
John McCallc8fc90a2011-07-06 07:30:07 +00002724
2725 // Record right away that the argument was changed. This needs
2726 // to happen even if the array expands to nothing.
2727 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002728
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002729 // The transform has determined that we should perform an elementwise
2730 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002731 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002732 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2733 ExprResult Out = getDerived().TransformExpr(Pattern);
2734 if (Out.isInvalid())
2735 return true;
2736
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002737 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002738 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2739 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002740 if (Out.isInvalid())
2741 return true;
2742 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002743
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002744 Outputs.push_back(Out.get());
2745 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002746
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002747 continue;
2748 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002749
Richard Smithc83c2302012-12-19 01:39:02 +00002750 ExprResult Result =
2751 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2752 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002753 if (Result.isInvalid())
2754 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002755
Douglas Gregoraa165f82011-01-03 19:04:46 +00002756 if (Result.get() != Inputs[I] && ArgChanged)
2757 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002758
2759 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002760 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002761
Douglas Gregoraa165f82011-01-03 19:04:46 +00002762 return false;
2763}
2764
2765template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002766NestedNameSpecifierLoc
2767TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2768 NestedNameSpecifierLoc NNS,
2769 QualType ObjectType,
2770 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002771 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002772 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002773 Qualifier = Qualifier.getPrefix())
2774 Qualifiers.push_back(Qualifier);
2775
2776 CXXScopeSpec SS;
2777 while (!Qualifiers.empty()) {
2778 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2779 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002780
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002781 switch (QNNS->getKind()) {
2782 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002783 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002784 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002785 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002786 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002787 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002788 FirstQualifierInScope, false))
2789 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002790
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002791 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002792
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002793 case NestedNameSpecifier::Namespace: {
2794 NamespaceDecl *NS
2795 = cast_or_null<NamespaceDecl>(
2796 getDerived().TransformDecl(
2797 Q.getLocalBeginLoc(),
2798 QNNS->getAsNamespace()));
2799 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2800 break;
2801 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002802
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002803 case NestedNameSpecifier::NamespaceAlias: {
2804 NamespaceAliasDecl *Alias
2805 = cast_or_null<NamespaceAliasDecl>(
2806 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2807 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002808 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002809 Q.getLocalEndLoc());
2810 break;
2811 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002812
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002813 case NestedNameSpecifier::Global:
2814 // There is no meaningful transformation that one could perform on the
2815 // global scope.
2816 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2817 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002818
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002819 case NestedNameSpecifier::TypeSpecWithTemplate:
2820 case NestedNameSpecifier::TypeSpec: {
2821 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2822 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002823
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002824 if (!TL)
2825 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002826
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002827 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002828 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002829 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002830 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002831 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002832 if (TL.getType()->isEnumeralType())
2833 SemaRef.Diag(TL.getBeginLoc(),
2834 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002835 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2836 Q.getLocalEndLoc());
2837 break;
2838 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002839 // If the nested-name-specifier is an invalid type def, don't emit an
2840 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002841 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2842 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002843 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002844 << TL.getType() << SS.getRange();
2845 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002846 return NestedNameSpecifierLoc();
2847 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002848 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002849
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002850 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002851 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002852 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002853 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002854
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002855 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002856 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002857 !getDerived().AlwaysRebuild())
2858 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002859
2860 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002861 // nested-name-specifier, do so.
2862 if (SS.location_size() == NNS.getDataLength() &&
2863 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2864 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2865
2866 // Allocate new nested-name-specifier location information.
2867 return SS.getWithLocInContext(SemaRef.Context);
2868}
2869
2870template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002871DeclarationNameInfo
2872TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002873::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002874 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002875 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002876 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002877
2878 switch (Name.getNameKind()) {
2879 case DeclarationName::Identifier:
2880 case DeclarationName::ObjCZeroArgSelector:
2881 case DeclarationName::ObjCOneArgSelector:
2882 case DeclarationName::ObjCMultiArgSelector:
2883 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002884 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002885 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002886 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002887
Douglas Gregor81499bb2009-09-03 22:13:48 +00002888 case DeclarationName::CXXConstructorName:
2889 case DeclarationName::CXXDestructorName:
2890 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002891 TypeSourceInfo *NewTInfo;
2892 CanQualType NewCanTy;
2893 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002894 NewTInfo = getDerived().TransformType(OldTInfo);
2895 if (!NewTInfo)
2896 return DeclarationNameInfo();
2897 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002898 }
2899 else {
2900 NewTInfo = 0;
2901 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002902 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002903 if (NewT.isNull())
2904 return DeclarationNameInfo();
2905 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2906 }
Mike Stump1eb44332009-09-09 15:08:12 +00002907
Abramo Bagnara25777432010-08-11 22:01:17 +00002908 DeclarationName NewName
2909 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2910 NewCanTy);
2911 DeclarationNameInfo NewNameInfo(NameInfo);
2912 NewNameInfo.setName(NewName);
2913 NewNameInfo.setNamedTypeInfo(NewTInfo);
2914 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002915 }
Mike Stump1eb44332009-09-09 15:08:12 +00002916 }
2917
David Blaikieb219cfc2011-09-23 05:06:16 +00002918 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002919}
2920
2921template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002922TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002923TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2924 TemplateName Name,
2925 SourceLocation NameLoc,
2926 QualType ObjectType,
2927 NamedDecl *FirstQualifierInScope) {
2928 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2929 TemplateDecl *Template = QTN->getTemplateDecl();
2930 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002931
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002932 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002933 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002934 Template));
2935 if (!TransTemplate)
2936 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002937
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002938 if (!getDerived().AlwaysRebuild() &&
2939 SS.getScopeRep() == QTN->getQualifier() &&
2940 TransTemplate == Template)
2941 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002942
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002943 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2944 TransTemplate);
2945 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002946
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002947 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2948 if (SS.getScopeRep()) {
2949 // These apply to the scope specifier, not the template.
2950 ObjectType = QualType();
2951 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002952 }
2953
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002954 if (!getDerived().AlwaysRebuild() &&
2955 SS.getScopeRep() == DTN->getQualifier() &&
2956 ObjectType.isNull())
2957 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002958
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002959 if (DTN->isIdentifier()) {
2960 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002961 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002962 NameLoc,
2963 ObjectType,
2964 FirstQualifierInScope);
2965 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002966
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002967 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2968 ObjectType);
2969 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002970
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002971 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2972 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002973 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002974 Template));
2975 if (!TransTemplate)
2976 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002977
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002978 if (!getDerived().AlwaysRebuild() &&
2979 TransTemplate == Template)
2980 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002981
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002982 return TemplateName(TransTemplate);
2983 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002984
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002985 if (SubstTemplateTemplateParmPackStorage *SubstPack
2986 = Name.getAsSubstTemplateTemplateParmPack()) {
2987 TemplateTemplateParmDecl *TransParam
2988 = cast_or_null<TemplateTemplateParmDecl>(
2989 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2990 if (!TransParam)
2991 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002992
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002993 if (!getDerived().AlwaysRebuild() &&
2994 TransParam == SubstPack->getParameterPack())
2995 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002996
2997 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002998 SubstPack->getArgumentPack());
2999 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003000
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003001 // These should be getting filtered out before they reach the AST.
3002 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003003}
3004
3005template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003006void TreeTransform<Derived>::InventTemplateArgumentLoc(
3007 const TemplateArgument &Arg,
3008 TemplateArgumentLoc &Output) {
3009 SourceLocation Loc = getDerived().getBaseLocation();
3010 switch (Arg.getKind()) {
3011 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003012 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00003013 break;
3014
3015 case TemplateArgument::Type:
3016 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00003017 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00003018
John McCall833ca992009-10-29 08:12:44 +00003019 break;
3020
Douglas Gregor788cd062009-11-11 01:00:40 +00003021 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003022 case TemplateArgument::TemplateExpansion: {
3023 NestedNameSpecifierLocBuilder Builder;
3024 TemplateName Template = Arg.getAsTemplate();
3025 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3026 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3027 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3028 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003029
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003030 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003031 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003032 Builder.getWithLocInContext(SemaRef.Context),
3033 Loc);
3034 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003035 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003036 Builder.getWithLocInContext(SemaRef.Context),
3037 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003038
Douglas Gregor788cd062009-11-11 01:00:40 +00003039 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003040 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003041
John McCall833ca992009-10-29 08:12:44 +00003042 case TemplateArgument::Expression:
3043 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3044 break;
3045
3046 case TemplateArgument::Declaration:
3047 case TemplateArgument::Integral:
3048 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003049 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003050 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003051 break;
3052 }
3053}
3054
3055template<typename Derived>
3056bool TreeTransform<Derived>::TransformTemplateArgument(
3057 const TemplateArgumentLoc &Input,
3058 TemplateArgumentLoc &Output) {
3059 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003060 switch (Arg.getKind()) {
3061 case TemplateArgument::Null:
3062 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003063 case TemplateArgument::Pack:
3064 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003065 case TemplateArgument::NullPtr:
3066 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003067
Douglas Gregor670444e2009-08-04 22:27:00 +00003068 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003069 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003070 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003071 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003072
3073 DI = getDerived().TransformType(DI);
3074 if (!DI) return true;
3075
3076 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3077 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003078 }
Mike Stump1eb44332009-09-09 15:08:12 +00003079
Douglas Gregor788cd062009-11-11 01:00:40 +00003080 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003081 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3082 if (QualifierLoc) {
3083 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3084 if (!QualifierLoc)
3085 return true;
3086 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003087
Douglas Gregor1d752d72011-03-02 18:46:51 +00003088 CXXScopeSpec SS;
3089 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003090 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003091 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3092 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003093 if (Template.isNull())
3094 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003095
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003096 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003097 Input.getTemplateNameLoc());
3098 return false;
3099 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003100
3101 case TemplateArgument::TemplateExpansion:
3102 llvm_unreachable("Caller should expand pack expansions");
3103
Douglas Gregor670444e2009-08-04 22:27:00 +00003104 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003105 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003106 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003107 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003108
John McCall833ca992009-10-29 08:12:44 +00003109 Expr *InputExpr = Input.getSourceExpression();
3110 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3111
Chris Lattner223de242011-04-25 20:37:58 +00003112 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003113 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003114 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003115 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003116 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003117 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003118 }
Mike Stump1eb44332009-09-09 15:08:12 +00003119
Douglas Gregor670444e2009-08-04 22:27:00 +00003120 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003121 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003122}
3123
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003124/// \brief Iterator adaptor that invents template argument location information
3125/// for each of the template arguments in its underlying iterator.
3126template<typename Derived, typename InputIterator>
3127class TemplateArgumentLocInventIterator {
3128 TreeTransform<Derived> &Self;
3129 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003130
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003131public:
3132 typedef TemplateArgumentLoc value_type;
3133 typedef TemplateArgumentLoc reference;
3134 typedef typename std::iterator_traits<InputIterator>::difference_type
3135 difference_type;
3136 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003137
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003138 class pointer {
3139 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003140
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003141 public:
3142 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003143
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003144 const TemplateArgumentLoc *operator->() const { return &Arg; }
3145 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003146
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003147 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003148
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003149 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3150 InputIterator Iter)
3151 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003152
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003153 TemplateArgumentLocInventIterator &operator++() {
3154 ++Iter;
3155 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003156 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003157
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003158 TemplateArgumentLocInventIterator operator++(int) {
3159 TemplateArgumentLocInventIterator Old(*this);
3160 ++(*this);
3161 return Old;
3162 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003163
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003164 reference operator*() const {
3165 TemplateArgumentLoc Result;
3166 Self.InventTemplateArgumentLoc(*Iter, Result);
3167 return Result;
3168 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003169
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003170 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003171
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003172 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3173 const TemplateArgumentLocInventIterator &Y) {
3174 return X.Iter == Y.Iter;
3175 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003176
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003177 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3178 const TemplateArgumentLocInventIterator &Y) {
3179 return X.Iter != Y.Iter;
3180 }
3181};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003182
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003183template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003184template<typename InputIterator>
3185bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3186 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003187 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003188 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003189 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003190 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003191
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003192 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3193 // Unpack argument packs, which we translate them into separate
3194 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003195 // FIXME: We could do much better if we could guarantee that the
3196 // TemplateArgumentLocInfo for the pack expansion would be usable for
3197 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003198 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003199 TemplateArgument::pack_iterator>
3200 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003201 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003202 In.getArgument().pack_begin()),
3203 PackLocIterator(*this,
3204 In.getArgument().pack_end()),
3205 Outputs))
3206 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003207
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003208 continue;
3209 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003210
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003211 if (In.getArgument().isPackExpansion()) {
3212 // We have a pack expansion, for which we will be substituting into
3213 // the pattern.
3214 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003215 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003216 TemplateArgumentLoc Pattern
Chad Rosier4a9d7952012-08-08 18:46:20 +00003217 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
Douglas Gregorcded4f62011-01-14 17:04:44 +00003218 getSema().Context);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003219
Chris Lattner686775d2011-07-20 06:58:45 +00003220 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003221 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3222 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003223
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003224 // Determine whether the set of unexpanded parameter packs can and should
3225 // be expanded.
3226 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003227 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003228 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003229 if (getDerived().TryExpandParameterPacks(Ellipsis,
3230 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003231 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003232 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003233 RetainExpansion,
3234 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003235 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003236
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003237 if (!Expand) {
3238 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003239 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003240 // expansion.
3241 TemplateArgumentLoc OutPattern;
3242 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3243 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3244 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003245
Douglas Gregorcded4f62011-01-14 17:04:44 +00003246 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3247 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003248 if (Out.getArgument().isNull())
3249 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003250
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003251 Outputs.addArgument(Out);
3252 continue;
3253 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003254
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003255 // The transform has determined that we should perform an elementwise
3256 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003257 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003258 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3259
3260 if (getDerived().TransformTemplateArgument(Pattern, Out))
3261 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003262
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003263 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003264 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3265 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003266 if (Out.getArgument().isNull())
3267 return true;
3268 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003269
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003270 Outputs.addArgument(Out);
3271 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003272
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003273 // If we're supposed to retain a pack expansion, do so by temporarily
3274 // forgetting the partially-substituted parameter pack.
3275 if (RetainExpansion) {
3276 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003277
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003278 if (getDerived().TransformTemplateArgument(Pattern, Out))
3279 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003280
Douglas Gregorcded4f62011-01-14 17:04:44 +00003281 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3282 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003283 if (Out.getArgument().isNull())
3284 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003285
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003286 Outputs.addArgument(Out);
3287 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003288
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003289 continue;
3290 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003291
3292 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003293 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003294 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003295
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003296 Outputs.addArgument(Out);
3297 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003298
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003299 return false;
3300
3301}
3302
Douglas Gregor577f75a2009-08-04 16:50:30 +00003303//===----------------------------------------------------------------------===//
3304// Type transformation
3305//===----------------------------------------------------------------------===//
3306
3307template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003308QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003309 if (getDerived().AlreadyTransformed(T))
3310 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003311
John McCalla2becad2009-10-21 00:40:46 +00003312 // Temporary workaround. All of these transformations should
3313 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003314 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3315 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003316
John McCall43fed0d2010-11-12 08:19:04 +00003317 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003318
John McCalla2becad2009-10-21 00:40:46 +00003319 if (!NewDI)
3320 return QualType();
3321
3322 return NewDI->getType();
3323}
3324
3325template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003326TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003327 // Refine the base location to the type's location.
3328 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3329 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003330 if (getDerived().AlreadyTransformed(DI->getType()))
3331 return DI;
3332
3333 TypeLocBuilder TLB;
3334
3335 TypeLoc TL = DI->getTypeLoc();
3336 TLB.reserve(TL.getFullDataSize());
3337
John McCall43fed0d2010-11-12 08:19:04 +00003338 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003339 if (Result.isNull())
3340 return 0;
3341
John McCalla93c9342009-12-07 02:54:59 +00003342 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003343}
3344
3345template<typename Derived>
3346QualType
John McCall43fed0d2010-11-12 08:19:04 +00003347TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003348 switch (T.getTypeLocClass()) {
3349#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003350#define TYPELOC(CLASS, PARENT) \
3351 case TypeLoc::CLASS: \
3352 return getDerived().Transform##CLASS##Type(TLB, \
3353 T.castAs<CLASS##TypeLoc>());
John McCalla2becad2009-10-21 00:40:46 +00003354#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003355 }
Mike Stump1eb44332009-09-09 15:08:12 +00003356
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003357 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003358}
3359
3360/// FIXME: By default, this routine adds type qualifiers only to types
3361/// that can have qualifiers, and silently suppresses those qualifiers
3362/// that are not permitted (e.g., qualifiers on reference or function
3363/// types). This is the right thing for template instantiation, but
3364/// probably not for other clients.
3365template<typename Derived>
3366QualType
3367TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003368 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003369 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003370
John McCall43fed0d2010-11-12 08:19:04 +00003371 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003372 if (Result.isNull())
3373 return QualType();
3374
3375 // Silently suppress qualifiers if the result type can't be qualified.
3376 // FIXME: this is the right thing for template instantiation, but
3377 // probably not for other clients.
3378 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003379 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003380
John McCallf85e1932011-06-15 23:02:42 +00003381 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003382 // resulting type.
3383 if (Quals.hasObjCLifetime()) {
3384 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3385 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003386 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003387 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003388 // A lifetime qualifier applied to a substituted template parameter
3389 // overrides the lifetime qualifier from the template argument.
Douglas Gregor92d13872013-01-17 23:59:28 +00003390 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003391 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003392 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3393 QualType Replacement = SubstTypeParam->getReplacementType();
3394 Qualifiers Qs = Replacement.getQualifiers();
3395 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003396 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003397 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3398 Qs);
3399 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003400 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003401 Replacement);
3402 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003403 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3404 // 'auto' types behave the same way as template parameters.
3405 QualType Deduced = AutoTy->getDeducedType();
3406 Qualifiers Qs = Deduced.getQualifiers();
3407 Qs.removeObjCLifetime();
3408 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3409 Qs);
3410 Result = SemaRef.Context.getAutoType(Deduced);
3411 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003412 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003413 // Otherwise, complain about the addition of a qualifier to an
3414 // already-qualified type.
3415 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003416 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003417 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003418
Douglas Gregore559ca12011-06-17 22:11:49 +00003419 Quals.removeObjCLifetime();
3420 }
3421 }
3422 }
John McCall28654742010-06-05 06:41:15 +00003423 if (!Quals.empty()) {
3424 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smith9807a2e2013-03-27 23:36:39 +00003425 // BuildQualifiedType might not add qualifiers if they are invalid.
3426 if (Result.hasLocalQualifiers())
3427 TLB.push<QualifiedTypeLoc>(Result);
John McCall28654742010-06-05 06:41:15 +00003428 // No location information to preserve.
3429 }
John McCalla2becad2009-10-21 00:40:46 +00003430
3431 return Result;
3432}
3433
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003434template<typename Derived>
3435TypeLoc
3436TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3437 QualType ObjectType,
3438 NamedDecl *UnqualLookup,
3439 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003440 QualType T = TL.getType();
3441 if (getDerived().AlreadyTransformed(T))
3442 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003443
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003444 TypeLocBuilder TLB;
3445 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003446
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003447 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003448 TemplateSpecializationTypeLoc SpecTL =
3449 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003450
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003451 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003452 getDerived().TransformTemplateName(SS,
3453 SpecTL.getTypePtr()->getTemplateName(),
3454 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003455 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003456 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003457 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003458
3459 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003460 Template);
3461 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003462 DependentTemplateSpecializationTypeLoc SpecTL =
3463 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003464
Douglas Gregora88f09f2011-02-28 17:23:35 +00003465 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003466 = getDerived().RebuildTemplateName(SS,
3467 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003468 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003469 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003470 if (Template.isNull())
3471 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003472
3473 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003474 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003475 Template,
3476 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003477 } else {
3478 // Nothing special needs to be done for these.
3479 Result = getDerived().TransformType(TLB, TL);
3480 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003481
3482 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003483 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003484
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003485 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3486}
3487
Douglas Gregorb71d8212011-03-02 18:32:08 +00003488template<typename Derived>
3489TypeSourceInfo *
3490TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3491 QualType ObjectType,
3492 NamedDecl *UnqualLookup,
3493 CXXScopeSpec &SS) {
3494 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003495
Douglas Gregorb71d8212011-03-02 18:32:08 +00003496 QualType T = TSInfo->getType();
3497 if (getDerived().AlreadyTransformed(T))
3498 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003499
Douglas Gregorb71d8212011-03-02 18:32:08 +00003500 TypeLocBuilder TLB;
3501 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003502
Douglas Gregorb71d8212011-03-02 18:32:08 +00003503 TypeLoc TL = TSInfo->getTypeLoc();
3504 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003505 TemplateSpecializationTypeLoc SpecTL =
3506 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003507
Douglas Gregorb71d8212011-03-02 18:32:08 +00003508 TemplateName Template
3509 = getDerived().TransformTemplateName(SS,
3510 SpecTL.getTypePtr()->getTemplateName(),
3511 SpecTL.getTemplateNameLoc(),
3512 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003513 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003514 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003515
3516 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003517 Template);
3518 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003519 DependentTemplateSpecializationTypeLoc SpecTL =
3520 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003521
Douglas Gregorb71d8212011-03-02 18:32:08 +00003522 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003523 = getDerived().RebuildTemplateName(SS,
3524 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003525 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003526 ObjectType, UnqualLookup);
3527 if (Template.isNull())
3528 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003529
3530 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003531 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003532 Template,
3533 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003534 } else {
3535 // Nothing special needs to be done for these.
3536 Result = getDerived().TransformType(TLB, TL);
3537 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003538
3539 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003540 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003541
Douglas Gregorb71d8212011-03-02 18:32:08 +00003542 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3543}
3544
John McCalla2becad2009-10-21 00:40:46 +00003545template <class TyLoc> static inline
3546QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3547 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3548 NewT.setNameLoc(T.getNameLoc());
3549 return T.getType();
3550}
3551
John McCalla2becad2009-10-21 00:40:46 +00003552template<typename Derived>
3553QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003554 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003555 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3556 NewT.setBuiltinLoc(T.getBuiltinLoc());
3557 if (T.needsExtraLocalData())
3558 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3559 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003560}
Mike Stump1eb44332009-09-09 15:08:12 +00003561
Douglas Gregor577f75a2009-08-04 16:50:30 +00003562template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003563QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003564 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003565 // FIXME: recurse?
3566 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003567}
Mike Stump1eb44332009-09-09 15:08:12 +00003568
Douglas Gregor577f75a2009-08-04 16:50:30 +00003569template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003570QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003571 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003572 QualType PointeeType
3573 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003574 if (PointeeType.isNull())
3575 return QualType();
3576
3577 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003578 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003579 // A dependent pointer type 'T *' has is being transformed such
3580 // that an Objective-C class type is being replaced for 'T'. The
3581 // resulting pointer type is an ObjCObjectPointerType, not a
3582 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003583 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003584
John McCallc12c5bb2010-05-15 11:32:37 +00003585 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3586 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003587 return Result;
3588 }
John McCall43fed0d2010-11-12 08:19:04 +00003589
Douglas Gregor92e986e2010-04-22 16:44:27 +00003590 if (getDerived().AlwaysRebuild() ||
3591 PointeeType != TL.getPointeeLoc().getType()) {
3592 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3593 if (Result.isNull())
3594 return QualType();
3595 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003596
John McCallf85e1932011-06-15 23:02:42 +00003597 // Objective-C ARC can add lifetime qualifiers to the type that we're
3598 // pointing to.
3599 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003600
Douglas Gregor92e986e2010-04-22 16:44:27 +00003601 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3602 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003603 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003604}
Mike Stump1eb44332009-09-09 15:08:12 +00003605
3606template<typename Derived>
3607QualType
John McCalla2becad2009-10-21 00:40:46 +00003608TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003609 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003610 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003611 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3612 if (PointeeType.isNull())
3613 return QualType();
3614
3615 QualType Result = TL.getType();
3616 if (getDerived().AlwaysRebuild() ||
3617 PointeeType != TL.getPointeeLoc().getType()) {
3618 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003619 TL.getSigilLoc());
3620 if (Result.isNull())
3621 return QualType();
3622 }
3623
Douglas Gregor39968ad2010-04-22 16:50:51 +00003624 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003625 NewT.setSigilLoc(TL.getSigilLoc());
3626 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003627}
3628
John McCall85737a72009-10-30 00:06:24 +00003629/// Transforms a reference type. Note that somewhat paradoxically we
3630/// don't care whether the type itself is an l-value type or an r-value
3631/// type; we only care if the type was *written* as an l-value type
3632/// or an r-value type.
3633template<typename Derived>
3634QualType
3635TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003636 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003637 const ReferenceType *T = TL.getTypePtr();
3638
3639 // Note that this works with the pointee-as-written.
3640 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3641 if (PointeeType.isNull())
3642 return QualType();
3643
3644 QualType Result = TL.getType();
3645 if (getDerived().AlwaysRebuild() ||
3646 PointeeType != T->getPointeeTypeAsWritten()) {
3647 Result = getDerived().RebuildReferenceType(PointeeType,
3648 T->isSpelledAsLValue(),
3649 TL.getSigilLoc());
3650 if (Result.isNull())
3651 return QualType();
3652 }
3653
John McCallf85e1932011-06-15 23:02:42 +00003654 // Objective-C ARC can add lifetime qualifiers to the type that we're
3655 // referring to.
3656 TLB.TypeWasModifiedSafely(
3657 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3658
John McCall85737a72009-10-30 00:06:24 +00003659 // r-value references can be rebuilt as l-value references.
3660 ReferenceTypeLoc NewTL;
3661 if (isa<LValueReferenceType>(Result))
3662 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3663 else
3664 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3665 NewTL.setSigilLoc(TL.getSigilLoc());
3666
3667 return Result;
3668}
3669
Mike Stump1eb44332009-09-09 15:08:12 +00003670template<typename Derived>
3671QualType
John McCalla2becad2009-10-21 00:40:46 +00003672TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003673 LValueReferenceTypeLoc TL) {
3674 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003675}
3676
Mike Stump1eb44332009-09-09 15:08:12 +00003677template<typename Derived>
3678QualType
John McCalla2becad2009-10-21 00:40:46 +00003679TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003680 RValueReferenceTypeLoc TL) {
3681 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003682}
Mike Stump1eb44332009-09-09 15:08:12 +00003683
Douglas Gregor577f75a2009-08-04 16:50:30 +00003684template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003685QualType
John McCalla2becad2009-10-21 00:40:46 +00003686TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003687 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003688 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003689 if (PointeeType.isNull())
3690 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003691
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003692 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3693 TypeSourceInfo* NewClsTInfo = 0;
3694 if (OldClsTInfo) {
3695 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3696 if (!NewClsTInfo)
3697 return QualType();
3698 }
3699
3700 const MemberPointerType *T = TL.getTypePtr();
3701 QualType OldClsType = QualType(T->getClass(), 0);
3702 QualType NewClsType;
3703 if (NewClsTInfo)
3704 NewClsType = NewClsTInfo->getType();
3705 else {
3706 NewClsType = getDerived().TransformType(OldClsType);
3707 if (NewClsType.isNull())
3708 return QualType();
3709 }
Mike Stump1eb44332009-09-09 15:08:12 +00003710
John McCalla2becad2009-10-21 00:40:46 +00003711 QualType Result = TL.getType();
3712 if (getDerived().AlwaysRebuild() ||
3713 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003714 NewClsType != OldClsType) {
3715 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003716 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003717 if (Result.isNull())
3718 return QualType();
3719 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003720
John McCalla2becad2009-10-21 00:40:46 +00003721 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3722 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003723 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003724
3725 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003726}
3727
Mike Stump1eb44332009-09-09 15:08:12 +00003728template<typename Derived>
3729QualType
John McCalla2becad2009-10-21 00:40:46 +00003730TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003731 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003732 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003733 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003734 if (ElementType.isNull())
3735 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003736
John McCalla2becad2009-10-21 00:40:46 +00003737 QualType Result = TL.getType();
3738 if (getDerived().AlwaysRebuild() ||
3739 ElementType != T->getElementType()) {
3740 Result = getDerived().RebuildConstantArrayType(ElementType,
3741 T->getSizeModifier(),
3742 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003743 T->getIndexTypeCVRQualifiers(),
3744 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003745 if (Result.isNull())
3746 return QualType();
3747 }
Eli Friedman457a3772012-01-25 22:19:07 +00003748
3749 // We might have either a ConstantArrayType or a VariableArrayType now:
3750 // a ConstantArrayType is allowed to have an element type which is a
3751 // VariableArrayType if the type is dependent. Fortunately, all array
3752 // types have the same location layout.
3753 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003754 NewTL.setLBracketLoc(TL.getLBracketLoc());
3755 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003756
John McCalla2becad2009-10-21 00:40:46 +00003757 Expr *Size = TL.getSizeExpr();
3758 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003759 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3760 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003761 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003762 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003763 }
3764 NewTL.setSizeExpr(Size);
3765
3766 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003767}
Mike Stump1eb44332009-09-09 15:08:12 +00003768
Douglas Gregor577f75a2009-08-04 16:50:30 +00003769template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003770QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003771 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003772 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003773 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003774 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003775 if (ElementType.isNull())
3776 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003777
John McCalla2becad2009-10-21 00:40:46 +00003778 QualType Result = TL.getType();
3779 if (getDerived().AlwaysRebuild() ||
3780 ElementType != T->getElementType()) {
3781 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003782 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003783 T->getIndexTypeCVRQualifiers(),
3784 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003785 if (Result.isNull())
3786 return QualType();
3787 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003788
John McCalla2becad2009-10-21 00:40:46 +00003789 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3790 NewTL.setLBracketLoc(TL.getLBracketLoc());
3791 NewTL.setRBracketLoc(TL.getRBracketLoc());
3792 NewTL.setSizeExpr(0);
3793
3794 return Result;
3795}
3796
3797template<typename Derived>
3798QualType
3799TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003800 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003801 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003802 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3803 if (ElementType.isNull())
3804 return QualType();
3805
John McCall60d7b3a2010-08-24 06:29:42 +00003806 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003807 = getDerived().TransformExpr(T->getSizeExpr());
3808 if (SizeResult.isInvalid())
3809 return QualType();
3810
John McCall9ae2f072010-08-23 23:25:46 +00003811 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003812
3813 QualType Result = TL.getType();
3814 if (getDerived().AlwaysRebuild() ||
3815 ElementType != T->getElementType() ||
3816 Size != T->getSizeExpr()) {
3817 Result = getDerived().RebuildVariableArrayType(ElementType,
3818 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003819 Size,
John McCalla2becad2009-10-21 00:40:46 +00003820 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003821 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003822 if (Result.isNull())
3823 return QualType();
3824 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003825
John McCalla2becad2009-10-21 00:40:46 +00003826 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3827 NewTL.setLBracketLoc(TL.getLBracketLoc());
3828 NewTL.setRBracketLoc(TL.getRBracketLoc());
3829 NewTL.setSizeExpr(Size);
3830
3831 return Result;
3832}
3833
3834template<typename Derived>
3835QualType
3836TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003837 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003838 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003839 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3840 if (ElementType.isNull())
3841 return QualType();
3842
Richard Smithf6702a32011-12-20 02:08:33 +00003843 // Array bounds are constant expressions.
3844 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3845 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003846
John McCall3b657512011-01-19 10:06:00 +00003847 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3848 Expr *origSize = TL.getSizeExpr();
3849 if (!origSize) origSize = T->getSizeExpr();
3850
3851 ExprResult sizeResult
3852 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003853 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003854 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003855 return QualType();
3856
John McCall3b657512011-01-19 10:06:00 +00003857 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003858
3859 QualType Result = TL.getType();
3860 if (getDerived().AlwaysRebuild() ||
3861 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003862 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003863 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3864 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003865 size,
John McCalla2becad2009-10-21 00:40:46 +00003866 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003867 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003868 if (Result.isNull())
3869 return QualType();
3870 }
John McCalla2becad2009-10-21 00:40:46 +00003871
3872 // We might have any sort of array type now, but fortunately they
3873 // all have the same location layout.
3874 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3875 NewTL.setLBracketLoc(TL.getLBracketLoc());
3876 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003877 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003878
3879 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003880}
Mike Stump1eb44332009-09-09 15:08:12 +00003881
3882template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003883QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003884 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003885 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003886 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003887
3888 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003889 QualType ElementType = getDerived().TransformType(T->getElementType());
3890 if (ElementType.isNull())
3891 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003892
Richard Smithf6702a32011-12-20 02:08:33 +00003893 // Vector sizes are constant expressions.
3894 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3895 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003896
John McCall60d7b3a2010-08-24 06:29:42 +00003897 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003898 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003899 if (Size.isInvalid())
3900 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003901
John McCalla2becad2009-10-21 00:40:46 +00003902 QualType Result = TL.getType();
3903 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003904 ElementType != T->getElementType() ||
3905 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003906 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003907 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003908 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003909 if (Result.isNull())
3910 return QualType();
3911 }
John McCalla2becad2009-10-21 00:40:46 +00003912
3913 // Result might be dependent or not.
3914 if (isa<DependentSizedExtVectorType>(Result)) {
3915 DependentSizedExtVectorTypeLoc NewTL
3916 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3917 NewTL.setNameLoc(TL.getNameLoc());
3918 } else {
3919 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3920 NewTL.setNameLoc(TL.getNameLoc());
3921 }
3922
3923 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003924}
Mike Stump1eb44332009-09-09 15:08:12 +00003925
3926template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003927QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003928 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003929 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003930 QualType ElementType = getDerived().TransformType(T->getElementType());
3931 if (ElementType.isNull())
3932 return QualType();
3933
John McCalla2becad2009-10-21 00:40:46 +00003934 QualType Result = TL.getType();
3935 if (getDerived().AlwaysRebuild() ||
3936 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003937 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003938 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003939 if (Result.isNull())
3940 return QualType();
3941 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003942
John McCalla2becad2009-10-21 00:40:46 +00003943 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3944 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003945
John McCalla2becad2009-10-21 00:40:46 +00003946 return Result;
3947}
3948
3949template<typename Derived>
3950QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003951 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003952 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003953 QualType ElementType = getDerived().TransformType(T->getElementType());
3954 if (ElementType.isNull())
3955 return QualType();
3956
3957 QualType Result = TL.getType();
3958 if (getDerived().AlwaysRebuild() ||
3959 ElementType != T->getElementType()) {
3960 Result = getDerived().RebuildExtVectorType(ElementType,
3961 T->getNumElements(),
3962 /*FIXME*/ SourceLocation());
3963 if (Result.isNull())
3964 return QualType();
3965 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003966
John McCalla2becad2009-10-21 00:40:46 +00003967 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3968 NewTL.setNameLoc(TL.getNameLoc());
3969
3970 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003971}
Mike Stump1eb44332009-09-09 15:08:12 +00003972
David Blaikiedc84cd52013-02-20 22:23:23 +00003973template <typename Derived>
3974ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
3975 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
3976 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003977 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003978 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003979
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003980 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003981 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003982 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003983 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00003984 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003985
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003986 TypeLocBuilder TLB;
3987 TypeLoc NewTL = OldDI->getTypeLoc();
3988 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003989
3990 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003991 OldExpansionTL.getPatternLoc());
3992 if (Result.isNull())
3993 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003994
3995 Result = RebuildPackExpansionType(Result,
3996 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003997 OldExpansionTL.getEllipsisLoc(),
3998 NumExpansions);
3999 if (Result.isNull())
4000 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004001
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004002 PackExpansionTypeLoc NewExpansionTL
4003 = TLB.push<PackExpansionTypeLoc>(Result);
4004 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4005 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4006 } else
4007 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00004008 if (!NewDI)
4009 return 0;
4010
John McCallfb44de92011-05-01 22:35:37 +00004011 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00004012 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00004013
4014 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4015 OldParm->getDeclContext(),
4016 OldParm->getInnerLocStart(),
4017 OldParm->getLocation(),
4018 OldParm->getIdentifier(),
4019 NewDI->getType(),
4020 NewDI,
4021 OldParm->getStorageClass(),
John McCallfb44de92011-05-01 22:35:37 +00004022 /* DefArg */ NULL);
4023 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4024 OldParm->getFunctionScopeIndex() + indexAdjustment);
4025 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004026}
4027
4028template<typename Derived>
4029bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004030 TransformFunctionTypeParams(SourceLocation Loc,
4031 ParmVarDecl **Params, unsigned NumParams,
4032 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004033 SmallVectorImpl<QualType> &OutParamTypes,
4034 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004035 int indexAdjustment = 0;
4036
Douglas Gregora009b592011-01-07 00:20:55 +00004037 for (unsigned i = 0; i != NumParams; ++i) {
4038 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004039 assert(OldParm->getFunctionScopeIndex() == i);
4040
David Blaikiedc84cd52013-02-20 22:23:23 +00004041 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004042 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004043 if (OldParm->isParameterPack()) {
4044 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004045 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004046
Douglas Gregor603cfb42011-01-05 23:12:31 +00004047 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004048 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004049 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004050 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4051 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004052 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4053
Douglas Gregor603cfb42011-01-05 23:12:31 +00004054 // Determine whether we should expand the parameter packs.
4055 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004056 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004057 Optional<unsigned> OrigNumExpansions =
4058 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004059 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004060 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4061 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004062 Unexpanded,
4063 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004064 RetainExpansion,
4065 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004066 return true;
4067 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004068
Douglas Gregor603cfb42011-01-05 23:12:31 +00004069 if (ShouldExpand) {
4070 // Expand the function parameter pack into multiple, separate
4071 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004072 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004073 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004074 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004075 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004076 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004077 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004078 OrigNumExpansions,
4079 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004080 if (!NewParm)
4081 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004082
Douglas Gregora009b592011-01-07 00:20:55 +00004083 OutParamTypes.push_back(NewParm->getType());
4084 if (PVars)
4085 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004086 }
Douglas Gregord3731192011-01-10 07:32:04 +00004087
4088 // If we're supposed to retain a pack expansion, do so by temporarily
4089 // forgetting the partially-substituted parameter pack.
4090 if (RetainExpansion) {
4091 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004092 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004093 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004094 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004095 OrigNumExpansions,
4096 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004097 if (!NewParm)
4098 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004099
Douglas Gregord3731192011-01-10 07:32:04 +00004100 OutParamTypes.push_back(NewParm->getType());
4101 if (PVars)
4102 PVars->push_back(NewParm);
4103 }
4104
John McCallfb44de92011-05-01 22:35:37 +00004105 // The next parameter should have the same adjustment as the
4106 // last thing we pushed, but we post-incremented indexAdjustment
4107 // on every push. Also, if we push nothing, the adjustment should
4108 // go down by one.
4109 indexAdjustment--;
4110
Douglas Gregor603cfb42011-01-05 23:12:31 +00004111 // We're done with the pack expansion.
4112 continue;
4113 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004114
4115 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004116 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004117 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4118 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004119 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004120 NumExpansions,
4121 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004122 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004123 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004124 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004125 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004126
John McCall21ef0fa2010-03-11 09:03:00 +00004127 if (!NewParm)
4128 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004129
Douglas Gregora009b592011-01-07 00:20:55 +00004130 OutParamTypes.push_back(NewParm->getType());
4131 if (PVars)
4132 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004133 continue;
4134 }
John McCall21ef0fa2010-03-11 09:03:00 +00004135
4136 // Deal with the possibility that we don't have a parameter
4137 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004138 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004139 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004140 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004141 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004142 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004143 = dyn_cast<PackExpansionType>(OldType)) {
4144 // We have a function parameter pack that may need to be expanded.
4145 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004146 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004147 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004148
Douglas Gregor603cfb42011-01-05 23:12:31 +00004149 // Determine whether we should expand the parameter packs.
4150 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004151 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004152 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004153 Unexpanded,
4154 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004155 RetainExpansion,
4156 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004157 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004158 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004159
Douglas Gregor603cfb42011-01-05 23:12:31 +00004160 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004161 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004162 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004163 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004164 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4165 QualType NewType = getDerived().TransformType(Pattern);
4166 if (NewType.isNull())
4167 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004168
Douglas Gregora009b592011-01-07 00:20:55 +00004169 OutParamTypes.push_back(NewType);
4170 if (PVars)
4171 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004172 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004173
Douglas Gregor603cfb42011-01-05 23:12:31 +00004174 // We're done with the pack expansion.
4175 continue;
4176 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004177
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004178 // If we're supposed to retain a pack expansion, do so by temporarily
4179 // forgetting the partially-substituted parameter pack.
4180 if (RetainExpansion) {
4181 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4182 QualType NewType = getDerived().TransformType(Pattern);
4183 if (NewType.isNull())
4184 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004185
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004186 OutParamTypes.push_back(NewType);
4187 if (PVars)
4188 PVars->push_back(0);
4189 }
Douglas Gregord3731192011-01-10 07:32:04 +00004190
Chad Rosier4a9d7952012-08-08 18:46:20 +00004191 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004192 // expansion.
4193 OldType = Expansion->getPattern();
4194 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004195 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4196 NewType = getDerived().TransformType(OldType);
4197 } else {
4198 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004199 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004200
Douglas Gregor603cfb42011-01-05 23:12:31 +00004201 if (NewType.isNull())
4202 return true;
4203
4204 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004205 NewType = getSema().Context.getPackExpansionType(NewType,
4206 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004207
Douglas Gregora009b592011-01-07 00:20:55 +00004208 OutParamTypes.push_back(NewType);
4209 if (PVars)
4210 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004211 }
4212
John McCallfb44de92011-05-01 22:35:37 +00004213#ifndef NDEBUG
4214 if (PVars) {
4215 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4216 if (ParmVarDecl *parm = (*PVars)[i])
4217 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004218 }
John McCallfb44de92011-05-01 22:35:37 +00004219#endif
4220
4221 return false;
4222}
John McCall21ef0fa2010-03-11 09:03:00 +00004223
4224template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004225QualType
John McCalla2becad2009-10-21 00:40:46 +00004226TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004227 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004228 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4229}
4230
4231template<typename Derived>
4232QualType
4233TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4234 FunctionProtoTypeLoc TL,
4235 CXXRecordDecl *ThisContext,
4236 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004237 // Transform the parameters and return type.
4238 //
Richard Smithe6975e92012-04-17 00:58:00 +00004239 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004240 // When the function has a trailing return type, we instantiate the
4241 // parameters before the return type, since the return type can then refer
4242 // to the parameters themselves (via decltype, sizeof, etc.).
4243 //
Chris Lattner686775d2011-07-20 06:58:45 +00004244 SmallVector<QualType, 4> ParamTypes;
4245 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004246 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004247
Douglas Gregordab60ad2010-10-01 18:44:50 +00004248 QualType ResultType;
4249
Richard Smith9fbf3272012-08-14 22:51:13 +00004250 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004251 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004252 TL.getParmArray(),
4253 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004254 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004255 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004256 return QualType();
4257
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004258 {
4259 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004260 // If a declaration declares a member function or member function
4261 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004262 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004263 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004264 // declarator.
4265 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004266
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004267 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4268 if (ResultType.isNull())
4269 return QualType();
4270 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004271 }
4272 else {
4273 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4274 if (ResultType.isNull())
4275 return QualType();
4276
Chad Rosier4a9d7952012-08-08 18:46:20 +00004277 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004278 TL.getParmArray(),
4279 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004280 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004281 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004282 return QualType();
4283 }
4284
Richard Smithe6975e92012-04-17 00:58:00 +00004285 // FIXME: Need to transform the exception-specification too.
4286
John McCalla2becad2009-10-21 00:40:46 +00004287 QualType Result = TL.getType();
4288 if (getDerived().AlwaysRebuild() ||
4289 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004290 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004291 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004292 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004293 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004294 if (Result.isNull())
4295 return QualType();
4296 }
Mike Stump1eb44332009-09-09 15:08:12 +00004297
John McCalla2becad2009-10-21 00:40:46 +00004298 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004299 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004300 NewTL.setLParenLoc(TL.getLParenLoc());
4301 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004302 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004303 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4304 NewTL.setArg(i, ParamDecls[i]);
4305
4306 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004307}
Mike Stump1eb44332009-09-09 15:08:12 +00004308
Douglas Gregor577f75a2009-08-04 16:50:30 +00004309template<typename Derived>
4310QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004311 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004312 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004313 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004314 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4315 if (ResultType.isNull())
4316 return QualType();
4317
4318 QualType Result = TL.getType();
4319 if (getDerived().AlwaysRebuild() ||
4320 ResultType != T->getResultType())
4321 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4322
4323 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004324 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004325 NewTL.setLParenLoc(TL.getLParenLoc());
4326 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004327 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004328
4329 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004330}
Mike Stump1eb44332009-09-09 15:08:12 +00004331
John McCalled976492009-12-04 22:46:56 +00004332template<typename Derived> QualType
4333TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004334 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004335 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004336 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004337 if (!D)
4338 return QualType();
4339
4340 QualType Result = TL.getType();
4341 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4342 Result = getDerived().RebuildUnresolvedUsingType(D);
4343 if (Result.isNull())
4344 return QualType();
4345 }
4346
4347 // We might get an arbitrary type spec type back. We should at
4348 // least always get a type spec type, though.
4349 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4350 NewTL.setNameLoc(TL.getNameLoc());
4351
4352 return Result;
4353}
4354
Douglas Gregor577f75a2009-08-04 16:50:30 +00004355template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004356QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004357 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004358 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004359 TypedefNameDecl *Typedef
4360 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4361 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004362 if (!Typedef)
4363 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004364
John McCalla2becad2009-10-21 00:40:46 +00004365 QualType Result = TL.getType();
4366 if (getDerived().AlwaysRebuild() ||
4367 Typedef != T->getDecl()) {
4368 Result = getDerived().RebuildTypedefType(Typedef);
4369 if (Result.isNull())
4370 return QualType();
4371 }
Mike Stump1eb44332009-09-09 15:08:12 +00004372
John McCalla2becad2009-10-21 00:40:46 +00004373 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4374 NewTL.setNameLoc(TL.getNameLoc());
4375
4376 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004377}
Mike Stump1eb44332009-09-09 15:08:12 +00004378
Douglas Gregor577f75a2009-08-04 16:50:30 +00004379template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004380QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004381 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004382 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004383 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4384 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004385
John McCall60d7b3a2010-08-24 06:29:42 +00004386 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004387 if (E.isInvalid())
4388 return QualType();
4389
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004390 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4391 if (E.isInvalid())
4392 return QualType();
4393
John McCalla2becad2009-10-21 00:40:46 +00004394 QualType Result = TL.getType();
4395 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004396 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004397 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004398 if (Result.isNull())
4399 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004400 }
John McCalla2becad2009-10-21 00:40:46 +00004401 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004402
John McCalla2becad2009-10-21 00:40:46 +00004403 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004404 NewTL.setTypeofLoc(TL.getTypeofLoc());
4405 NewTL.setLParenLoc(TL.getLParenLoc());
4406 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004407
4408 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004409}
Mike Stump1eb44332009-09-09 15:08:12 +00004410
4411template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004412QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004413 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004414 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4415 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4416 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004417 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004418
John McCalla2becad2009-10-21 00:40:46 +00004419 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004420 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4421 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004422 if (Result.isNull())
4423 return QualType();
4424 }
Mike Stump1eb44332009-09-09 15:08:12 +00004425
John McCalla2becad2009-10-21 00:40:46 +00004426 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004427 NewTL.setTypeofLoc(TL.getTypeofLoc());
4428 NewTL.setLParenLoc(TL.getLParenLoc());
4429 NewTL.setRParenLoc(TL.getRParenLoc());
4430 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004431
4432 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004433}
Mike Stump1eb44332009-09-09 15:08:12 +00004434
4435template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004436QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004437 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004438 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004439
Douglas Gregor670444e2009-08-04 22:27:00 +00004440 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004441 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4442 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004443
John McCall60d7b3a2010-08-24 06:29:42 +00004444 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004445 if (E.isInvalid())
4446 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004447
Richard Smith76f3f692012-02-22 02:04:18 +00004448 E = getSema().ActOnDecltypeExpression(E.take());
4449 if (E.isInvalid())
4450 return QualType();
4451
John McCalla2becad2009-10-21 00:40:46 +00004452 QualType Result = TL.getType();
4453 if (getDerived().AlwaysRebuild() ||
4454 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004455 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004456 if (Result.isNull())
4457 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004458 }
John McCalla2becad2009-10-21 00:40:46 +00004459 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004460
John McCalla2becad2009-10-21 00:40:46 +00004461 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4462 NewTL.setNameLoc(TL.getNameLoc());
4463
4464 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004465}
4466
4467template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004468QualType TreeTransform<Derived>::TransformUnaryTransformType(
4469 TypeLocBuilder &TLB,
4470 UnaryTransformTypeLoc TL) {
4471 QualType Result = TL.getType();
4472 if (Result->isDependentType()) {
4473 const UnaryTransformType *T = TL.getTypePtr();
4474 QualType NewBase =
4475 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4476 Result = getDerived().RebuildUnaryTransformType(NewBase,
4477 T->getUTTKind(),
4478 TL.getKWLoc());
4479 if (Result.isNull())
4480 return QualType();
4481 }
4482
4483 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4484 NewTL.setKWLoc(TL.getKWLoc());
4485 NewTL.setParensRange(TL.getParensRange());
4486 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4487 return Result;
4488}
4489
4490template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004491QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4492 AutoTypeLoc TL) {
4493 const AutoType *T = TL.getTypePtr();
4494 QualType OldDeduced = T->getDeducedType();
4495 QualType NewDeduced;
4496 if (!OldDeduced.isNull()) {
4497 NewDeduced = getDerived().TransformType(OldDeduced);
4498 if (NewDeduced.isNull())
4499 return QualType();
4500 }
4501
4502 QualType Result = TL.getType();
4503 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4504 Result = getDerived().RebuildAutoType(NewDeduced);
4505 if (Result.isNull())
4506 return QualType();
4507 }
4508
4509 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4510 NewTL.setNameLoc(TL.getNameLoc());
4511
4512 return Result;
4513}
4514
4515template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004516QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004517 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004518 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004519 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004520 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4521 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004522 if (!Record)
4523 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004524
John McCalla2becad2009-10-21 00:40:46 +00004525 QualType Result = TL.getType();
4526 if (getDerived().AlwaysRebuild() ||
4527 Record != T->getDecl()) {
4528 Result = getDerived().RebuildRecordType(Record);
4529 if (Result.isNull())
4530 return QualType();
4531 }
Mike Stump1eb44332009-09-09 15:08:12 +00004532
John McCalla2becad2009-10-21 00:40:46 +00004533 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4534 NewTL.setNameLoc(TL.getNameLoc());
4535
4536 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004537}
Mike Stump1eb44332009-09-09 15:08:12 +00004538
4539template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004540QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004541 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004542 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004543 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004544 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4545 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004546 if (!Enum)
4547 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004548
John McCalla2becad2009-10-21 00:40:46 +00004549 QualType Result = TL.getType();
4550 if (getDerived().AlwaysRebuild() ||
4551 Enum != T->getDecl()) {
4552 Result = getDerived().RebuildEnumType(Enum);
4553 if (Result.isNull())
4554 return QualType();
4555 }
Mike Stump1eb44332009-09-09 15:08:12 +00004556
John McCalla2becad2009-10-21 00:40:46 +00004557 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4558 NewTL.setNameLoc(TL.getNameLoc());
4559
4560 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004561}
John McCall7da24312009-09-05 00:15:47 +00004562
John McCall3cb0ebd2010-03-10 03:28:59 +00004563template<typename Derived>
4564QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4565 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004566 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004567 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4568 TL.getTypePtr()->getDecl());
4569 if (!D) return QualType();
4570
4571 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4572 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4573 return T;
4574}
4575
Douglas Gregor577f75a2009-08-04 16:50:30 +00004576template<typename Derived>
4577QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004578 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004579 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004580 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004581}
4582
Mike Stump1eb44332009-09-09 15:08:12 +00004583template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004584QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004585 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004586 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004587 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004588
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004589 // Substitute into the replacement type, which itself might involve something
4590 // that needs to be transformed. This only tends to occur with default
4591 // template arguments of template template parameters.
4592 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4593 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4594 if (Replacement.isNull())
4595 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004596
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004597 // Always canonicalize the replacement type.
4598 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4599 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004600 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004601 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004602
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004603 // Propagate type-source information.
4604 SubstTemplateTypeParmTypeLoc NewTL
4605 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4606 NewTL.setNameLoc(TL.getNameLoc());
4607 return Result;
4608
John McCall49a832b2009-10-18 09:09:24 +00004609}
4610
4611template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004612QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4613 TypeLocBuilder &TLB,
4614 SubstTemplateTypeParmPackTypeLoc TL) {
4615 return TransformTypeSpecType(TLB, TL);
4616}
4617
4618template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004619QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004620 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004621 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004622 const TemplateSpecializationType *T = TL.getTypePtr();
4623
Douglas Gregor1d752d72011-03-02 18:46:51 +00004624 // The nested-name-specifier never matters in a TemplateSpecializationType,
4625 // because we can't have a dependent nested-name-specifier anyway.
4626 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004627 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004628 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4629 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004630 if (Template.isNull())
4631 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004632
John McCall43fed0d2010-11-12 08:19:04 +00004633 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4634}
4635
Eli Friedmanb001de72011-10-06 23:00:33 +00004636template<typename Derived>
4637QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4638 AtomicTypeLoc TL) {
4639 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4640 if (ValueType.isNull())
4641 return QualType();
4642
4643 QualType Result = TL.getType();
4644 if (getDerived().AlwaysRebuild() ||
4645 ValueType != TL.getValueLoc().getType()) {
4646 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4647 if (Result.isNull())
4648 return QualType();
4649 }
4650
4651 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4652 NewTL.setKWLoc(TL.getKWLoc());
4653 NewTL.setLParenLoc(TL.getLParenLoc());
4654 NewTL.setRParenLoc(TL.getRParenLoc());
4655
4656 return Result;
4657}
4658
Chad Rosier4a9d7952012-08-08 18:46:20 +00004659 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004660 /// container that provides a \c getArgLoc() member function.
4661 ///
4662 /// This iterator is intended to be used with the iterator form of
4663 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4664 template<typename ArgLocContainer>
4665 class TemplateArgumentLocContainerIterator {
4666 ArgLocContainer *Container;
4667 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004668
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004669 public:
4670 typedef TemplateArgumentLoc value_type;
4671 typedef TemplateArgumentLoc reference;
4672 typedef int difference_type;
4673 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004674
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004675 class pointer {
4676 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004677
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004678 public:
4679 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004680
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004681 const TemplateArgumentLoc *operator->() const {
4682 return &Arg;
4683 }
4684 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004685
4686
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004687 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004688
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004689 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4690 unsigned Index)
4691 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004692
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004693 TemplateArgumentLocContainerIterator &operator++() {
4694 ++Index;
4695 return *this;
4696 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004697
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004698 TemplateArgumentLocContainerIterator operator++(int) {
4699 TemplateArgumentLocContainerIterator Old(*this);
4700 ++(*this);
4701 return Old;
4702 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004703
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004704 TemplateArgumentLoc operator*() const {
4705 return Container->getArgLoc(Index);
4706 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004707
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004708 pointer operator->() const {
4709 return pointer(Container->getArgLoc(Index));
4710 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004711
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004712 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004713 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004714 return X.Container == Y.Container && X.Index == Y.Index;
4715 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004716
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004717 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004718 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004719 return !(X == Y);
4720 }
4721 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004722
4723
John McCall43fed0d2010-11-12 08:19:04 +00004724template <typename Derived>
4725QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4726 TypeLocBuilder &TLB,
4727 TemplateSpecializationTypeLoc TL,
4728 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004729 TemplateArgumentListInfo NewTemplateArgs;
4730 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4731 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004732 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4733 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004734 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004735 ArgIterator(TL, TL.getNumArgs()),
4736 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004737 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004738
John McCall833ca992009-10-29 08:12:44 +00004739 // FIXME: maybe don't rebuild if all the template arguments are the same.
4740
4741 QualType Result =
4742 getDerived().RebuildTemplateSpecializationType(Template,
4743 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004744 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004745
4746 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004747 // Specializations of template template parameters are represented as
4748 // TemplateSpecializationTypes, and substitution of type alias templates
4749 // within a dependent context can transform them into
4750 // DependentTemplateSpecializationTypes.
4751 if (isa<DependentTemplateSpecializationType>(Result)) {
4752 DependentTemplateSpecializationTypeLoc NewTL
4753 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004754 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004755 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004756 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004757 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004758 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());
4762 return Result;
4763 }
4764
John McCall833ca992009-10-29 08:12:44 +00004765 TemplateSpecializationTypeLoc NewTL
4766 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004767 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004768 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4769 NewTL.setLAngleLoc(TL.getLAngleLoc());
4770 NewTL.setRAngleLoc(TL.getRAngleLoc());
4771 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4772 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004773 }
Mike Stump1eb44332009-09-09 15:08:12 +00004774
John McCall833ca992009-10-29 08:12:44 +00004775 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004776}
Mike Stump1eb44332009-09-09 15:08:12 +00004777
Douglas Gregora88f09f2011-02-28 17:23:35 +00004778template <typename Derived>
4779QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4780 TypeLocBuilder &TLB,
4781 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004782 TemplateName Template,
4783 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004784 TemplateArgumentListInfo NewTemplateArgs;
4785 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4786 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4787 typedef TemplateArgumentLocContainerIterator<
4788 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004789 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004790 ArgIterator(TL, TL.getNumArgs()),
4791 NewTemplateArgs))
4792 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004793
Douglas Gregora88f09f2011-02-28 17:23:35 +00004794 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004795
Douglas Gregora88f09f2011-02-28 17:23:35 +00004796 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4797 QualType Result
4798 = getSema().Context.getDependentTemplateSpecializationType(
4799 TL.getTypePtr()->getKeyword(),
4800 DTN->getQualifier(),
4801 DTN->getIdentifier(),
4802 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004803
Douglas Gregora88f09f2011-02-28 17:23:35 +00004804 DependentTemplateSpecializationTypeLoc NewTL
4805 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004806 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004807 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004808 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004809 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004810 NewTL.setLAngleLoc(TL.getLAngleLoc());
4811 NewTL.setRAngleLoc(TL.getRAngleLoc());
4812 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4813 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4814 return Result;
4815 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004816
4817 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004818 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004819 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004820 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004821
Douglas Gregora88f09f2011-02-28 17:23:35 +00004822 if (!Result.isNull()) {
4823 /// FIXME: Wrap this in an elaborated-type-specifier?
4824 TemplateSpecializationTypeLoc NewTL
4825 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004826 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004827 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004828 NewTL.setLAngleLoc(TL.getLAngleLoc());
4829 NewTL.setRAngleLoc(TL.getRAngleLoc());
4830 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4831 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4832 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004833
Douglas Gregora88f09f2011-02-28 17:23:35 +00004834 return Result;
4835}
4836
Mike Stump1eb44332009-09-09 15:08:12 +00004837template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004838QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004839TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004840 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004841 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004842
Douglas Gregor9e876872011-03-01 18:12:44 +00004843 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004844 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004845 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004846 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004847 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4848 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004849 return QualType();
4850 }
Mike Stump1eb44332009-09-09 15:08:12 +00004851
John McCall43fed0d2010-11-12 08:19:04 +00004852 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4853 if (NamedT.isNull())
4854 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004855
Richard Smith3e4c6c42011-05-05 21:57:07 +00004856 // C++0x [dcl.type.elab]p2:
4857 // If the identifier resolves to a typedef-name or the simple-template-id
4858 // resolves to an alias template specialization, the
4859 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004860 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4861 if (const TemplateSpecializationType *TST =
4862 NamedT->getAs<TemplateSpecializationType>()) {
4863 TemplateName Template = TST->getTemplateName();
4864 if (TypeAliasTemplateDecl *TAT =
4865 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4866 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4867 diag::err_tag_reference_non_tag) << 4;
4868 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4869 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004870 }
4871 }
4872
John McCalla2becad2009-10-21 00:40:46 +00004873 QualType Result = TL.getType();
4874 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004875 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004876 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004877 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004878 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004879 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004880 if (Result.isNull())
4881 return QualType();
4882 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004883
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004884 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004885 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004886 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004887 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004888}
Mike Stump1eb44332009-09-09 15:08:12 +00004889
4890template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004891QualType TreeTransform<Derived>::TransformAttributedType(
4892 TypeLocBuilder &TLB,
4893 AttributedTypeLoc TL) {
4894 const AttributedType *oldType = TL.getTypePtr();
4895 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4896 if (modifiedType.isNull())
4897 return QualType();
4898
4899 QualType result = TL.getType();
4900
4901 // FIXME: dependent operand expressions?
4902 if (getDerived().AlwaysRebuild() ||
4903 modifiedType != oldType->getModifiedType()) {
4904 // TODO: this is really lame; we should really be rebuilding the
4905 // equivalent type from first principles.
4906 QualType equivalentType
4907 = getDerived().TransformType(oldType->getEquivalentType());
4908 if (equivalentType.isNull())
4909 return QualType();
4910 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4911 modifiedType,
4912 equivalentType);
4913 }
4914
4915 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4916 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4917 if (TL.hasAttrOperand())
4918 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4919 if (TL.hasAttrExprOperand())
4920 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4921 else if (TL.hasAttrEnumOperand())
4922 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4923
4924 return result;
4925}
4926
4927template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004928QualType
4929TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4930 ParenTypeLoc TL) {
4931 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4932 if (Inner.isNull())
4933 return QualType();
4934
4935 QualType Result = TL.getType();
4936 if (getDerived().AlwaysRebuild() ||
4937 Inner != TL.getInnerLoc().getType()) {
4938 Result = getDerived().RebuildParenType(Inner);
4939 if (Result.isNull())
4940 return QualType();
4941 }
4942
4943 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4944 NewTL.setLParenLoc(TL.getLParenLoc());
4945 NewTL.setRParenLoc(TL.getRParenLoc());
4946 return Result;
4947}
4948
4949template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004950QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004951 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004952 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004953
Douglas Gregor2494dd02011-03-01 01:34:45 +00004954 NestedNameSpecifierLoc QualifierLoc
4955 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4956 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004957 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004958
John McCall33500952010-06-11 00:33:02 +00004959 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004960 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004961 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004962 QualifierLoc,
4963 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004964 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004965 if (Result.isNull())
4966 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004967
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004968 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4969 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004970 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4971
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004972 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004973 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004974 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004975 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004976 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004977 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004978 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004979 NewTL.setNameLoc(TL.getNameLoc());
4980 }
John McCalla2becad2009-10-21 00:40:46 +00004981 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004982}
Mike Stump1eb44332009-09-09 15:08:12 +00004983
Douglas Gregor577f75a2009-08-04 16:50:30 +00004984template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004985QualType TreeTransform<Derived>::
4986 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004987 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004988 NestedNameSpecifierLoc QualifierLoc;
4989 if (TL.getQualifierLoc()) {
4990 QualifierLoc
4991 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4992 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004993 return QualType();
4994 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004995
John McCall43fed0d2010-11-12 08:19:04 +00004996 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004997 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004998}
4999
5000template<typename Derived>
5001QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005002TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5003 DependentTemplateSpecializationTypeLoc TL,
5004 NestedNameSpecifierLoc QualifierLoc) {
5005 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005006
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005007 TemplateArgumentListInfo NewTemplateArgs;
5008 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5009 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005010
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005011 typedef TemplateArgumentLocContainerIterator<
5012 DependentTemplateSpecializationTypeLoc> ArgIterator;
5013 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5014 ArgIterator(TL, TL.getNumArgs()),
5015 NewTemplateArgs))
5016 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005017
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005018 QualType Result
5019 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5020 QualifierLoc,
5021 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005022 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005023 NewTemplateArgs);
5024 if (Result.isNull())
5025 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005026
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005027 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5028 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005029
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005030 // Copy information relevant to the template specialization.
5031 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005032 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005033 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005034 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005035 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5036 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005037 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005038 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005039
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005040 // Copy information relevant to the elaborated type.
5041 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005042 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005043 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005044 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5045 DependentTemplateSpecializationTypeLoc SpecTL
5046 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005047 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005048 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005049 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005050 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005051 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5052 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005053 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005054 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005055 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005056 TemplateSpecializationTypeLoc SpecTL
5057 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005058 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005059 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005060 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5061 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005062 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005063 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005064 }
5065 return Result;
5066}
5067
5068template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005069QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5070 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005071 QualType Pattern
5072 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005073 if (Pattern.isNull())
5074 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005075
5076 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005077 if (getDerived().AlwaysRebuild() ||
5078 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005079 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005080 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005081 TL.getEllipsisLoc(),
5082 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005083 if (Result.isNull())
5084 return QualType();
5085 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005086
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005087 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5088 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5089 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005090}
5091
5092template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005093QualType
5094TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005095 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005096 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005097 TLB.pushFullCopy(TL);
5098 return TL.getType();
5099}
5100
5101template<typename Derived>
5102QualType
5103TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005104 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005105 // ObjCObjectType is never dependent.
5106 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005107 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005108}
Mike Stump1eb44332009-09-09 15:08:12 +00005109
5110template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005111QualType
5112TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005113 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005114 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005115 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005116 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005117}
5118
Douglas Gregor577f75a2009-08-04 16:50:30 +00005119//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005120// Statement transformation
5121//===----------------------------------------------------------------------===//
5122template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005123StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005124TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005125 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005126}
5127
5128template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005129StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005130TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5131 return getDerived().TransformCompoundStmt(S, false);
5132}
5133
5134template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005135StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005136TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005137 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005138 Sema::CompoundScopeRAII CompoundScope(getSema());
5139
John McCall7114cba2010-08-27 19:56:05 +00005140 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005141 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005142 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005143 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5144 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005145 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005146 if (Result.isInvalid()) {
5147 // Immediately fail if this was a DeclStmt, since it's very
5148 // likely that this will cause problems for future statements.
5149 if (isa<DeclStmt>(*B))
5150 return StmtError();
5151
5152 // Otherwise, just keep processing substatements and fail later.
5153 SubStmtInvalid = true;
5154 continue;
5155 }
Mike Stump1eb44332009-09-09 15:08:12 +00005156
Douglas Gregor43959a92009-08-20 07:17:43 +00005157 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5158 Statements.push_back(Result.takeAs<Stmt>());
5159 }
Mike Stump1eb44332009-09-09 15:08:12 +00005160
John McCall7114cba2010-08-27 19:56:05 +00005161 if (SubStmtInvalid)
5162 return StmtError();
5163
Douglas Gregor43959a92009-08-20 07:17:43 +00005164 if (!getDerived().AlwaysRebuild() &&
5165 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005166 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005167
5168 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005169 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005170 S->getRBracLoc(),
5171 IsStmtExpr);
5172}
Mike Stump1eb44332009-09-09 15:08:12 +00005173
Douglas Gregor43959a92009-08-20 07:17:43 +00005174template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005175StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005176TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005177 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005178 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005179 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5180 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005181
Eli Friedman264c1f82009-11-19 03:14:00 +00005182 // Transform the left-hand case value.
5183 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005184 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005185 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005186 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005187
Eli Friedman264c1f82009-11-19 03:14:00 +00005188 // Transform the right-hand case value (for the GNU case-range extension).
5189 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005190 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005191 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005192 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005193 }
Mike Stump1eb44332009-09-09 15:08:12 +00005194
Douglas Gregor43959a92009-08-20 07:17:43 +00005195 // Build the case statement.
5196 // Case statements are always rebuilt so that they will attached to their
5197 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005198 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005199 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005200 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005201 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005202 S->getColonLoc());
5203 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005204 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005205
Douglas Gregor43959a92009-08-20 07:17:43 +00005206 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005207 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005208 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005209 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005210
Douglas Gregor43959a92009-08-20 07:17:43 +00005211 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005212 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005213}
5214
5215template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005216StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005217TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005218 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005219 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005220 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005221 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005222
Douglas Gregor43959a92009-08-20 07:17:43 +00005223 // Default statements are always rebuilt
5224 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005225 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005226}
Mike Stump1eb44332009-09-09 15:08:12 +00005227
Douglas Gregor43959a92009-08-20 07:17:43 +00005228template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005229StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005230TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005231 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005232 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005233 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005234
Chris Lattner57ad3782011-02-17 20:34:02 +00005235 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5236 S->getDecl());
5237 if (!LD)
5238 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005239
5240
Douglas Gregor43959a92009-08-20 07:17:43 +00005241 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005242 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005243 cast<LabelDecl>(LD), SourceLocation(),
5244 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005245}
Mike Stump1eb44332009-09-09 15:08:12 +00005246
Douglas Gregor43959a92009-08-20 07:17:43 +00005247template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005248StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005249TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5250 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5251 if (SubStmt.isInvalid())
5252 return StmtError();
5253
5254 // TODO: transform attributes
5255 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5256 return S;
5257
5258 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5259 S->getAttrs(),
5260 SubStmt.get());
5261}
5262
5263template<typename Derived>
5264StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005265TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005266 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005267 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005268 VarDecl *ConditionVar = 0;
5269 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005270 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005271 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005272 getDerived().TransformDefinition(
5273 S->getConditionVariable()->getLocation(),
5274 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005275 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005276 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005277 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005278 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005279
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005280 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005281 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005282
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005283 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005284 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005285 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005286 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005287 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005288 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005289
John McCall9ae2f072010-08-23 23:25:46 +00005290 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005291 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005292 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005293
John McCall9ae2f072010-08-23 23:25:46 +00005294 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5295 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005296 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005297
Douglas Gregor43959a92009-08-20 07:17:43 +00005298 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005299 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005300 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005301 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005302
Douglas Gregor43959a92009-08-20 07:17:43 +00005303 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005304 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005305 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005306 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005307
Douglas Gregor43959a92009-08-20 07:17:43 +00005308 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005309 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005310 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005311 Then.get() == S->getThen() &&
5312 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005313 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005314
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005315 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005316 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005317 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005318}
5319
5320template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005321StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005322TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005323 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005324 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005325 VarDecl *ConditionVar = 0;
5326 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005327 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005328 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005329 getDerived().TransformDefinition(
5330 S->getConditionVariable()->getLocation(),
5331 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005332 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005333 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005334 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005335 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005336
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005337 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005338 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005339 }
Mike Stump1eb44332009-09-09 15:08:12 +00005340
Douglas Gregor43959a92009-08-20 07:17:43 +00005341 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005342 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005343 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005344 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005345 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005346 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005347
Douglas Gregor43959a92009-08-20 07:17:43 +00005348 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005349 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005350 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005351 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005352
Douglas Gregor43959a92009-08-20 07:17:43 +00005353 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005354 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5355 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005356}
Mike Stump1eb44332009-09-09 15:08:12 +00005357
Douglas Gregor43959a92009-08-20 07:17:43 +00005358template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005359StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005360TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005361 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005362 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005363 VarDecl *ConditionVar = 0;
5364 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005365 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005366 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005367 getDerived().TransformDefinition(
5368 S->getConditionVariable()->getLocation(),
5369 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005370 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005371 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005372 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005373 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005374
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005375 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005376 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005377
5378 if (S->getCond()) {
5379 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005380 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005381 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005382 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005383 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005384 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005385 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005386 }
Mike Stump1eb44332009-09-09 15:08:12 +00005387
John McCall9ae2f072010-08-23 23:25:46 +00005388 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5389 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005390 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005391
Douglas Gregor43959a92009-08-20 07:17:43 +00005392 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005393 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005394 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005395 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005396
Douglas Gregor43959a92009-08-20 07:17:43 +00005397 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005398 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005399 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005400 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005401 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005402
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005403 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005404 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005405}
Mike Stump1eb44332009-09-09 15:08:12 +00005406
Douglas Gregor43959a92009-08-20 07:17:43 +00005407template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005408StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005409TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005410 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005411 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005412 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005413 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005414
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005415 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005416 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005417 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005418 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005419
Douglas Gregor43959a92009-08-20 07:17:43 +00005420 if (!getDerived().AlwaysRebuild() &&
5421 Cond.get() == S->getCond() &&
5422 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005423 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005424
John McCall9ae2f072010-08-23 23:25:46 +00005425 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5426 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005427 S->getRParenLoc());
5428}
Mike Stump1eb44332009-09-09 15:08:12 +00005429
Douglas Gregor43959a92009-08-20 07:17:43 +00005430template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005431StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005432TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005433 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005434 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005435 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005436 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005437
Douglas Gregor43959a92009-08-20 07:17:43 +00005438 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005439 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005440 VarDecl *ConditionVar = 0;
5441 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005442 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005443 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005444 getDerived().TransformDefinition(
5445 S->getConditionVariable()->getLocation(),
5446 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005447 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005448 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005449 } else {
5450 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005451
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005452 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005453 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005454
5455 if (S->getCond()) {
5456 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005457 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005458 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005459 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005460 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005461
John McCall9ae2f072010-08-23 23:25:46 +00005462 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005463 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005464 }
Mike Stump1eb44332009-09-09 15:08:12 +00005465
Chad Rosier4a9d7952012-08-08 18:46:20 +00005466 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005467 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005468 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005469
Douglas Gregor43959a92009-08-20 07:17:43 +00005470 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005471 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005472 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005473 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005474
Richard Smith41956372013-01-14 22:39:08 +00005475 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005476 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005477 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005478
Douglas Gregor43959a92009-08-20 07:17:43 +00005479 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005480 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005481 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005482 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005483
Douglas Gregor43959a92009-08-20 07:17:43 +00005484 if (!getDerived().AlwaysRebuild() &&
5485 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005486 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005487 Inc.get() == S->getInc() &&
5488 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005489 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005490
Douglas Gregor43959a92009-08-20 07:17:43 +00005491 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005492 Init.get(), FullCond, ConditionVar,
5493 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005494}
5495
5496template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005497StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005498TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005499 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5500 S->getLabel());
5501 if (!LD)
5502 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005503
Douglas Gregor43959a92009-08-20 07:17:43 +00005504 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005505 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005506 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005507}
5508
5509template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005510StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005511TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005512 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005513 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005514 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005515 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005516
Douglas Gregor43959a92009-08-20 07:17:43 +00005517 if (!getDerived().AlwaysRebuild() &&
5518 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005519 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005520
5521 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005522 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005523}
5524
5525template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005526StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005527TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005528 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005529}
Mike Stump1eb44332009-09-09 15:08:12 +00005530
Douglas Gregor43959a92009-08-20 07:17:43 +00005531template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005532StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005533TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005534 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005535}
Mike Stump1eb44332009-09-09 15:08:12 +00005536
Douglas Gregor43959a92009-08-20 07:17:43 +00005537template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005538StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005539TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005540 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005541 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005542 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005543
Mike Stump1eb44332009-09-09 15:08:12 +00005544 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005545 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005546 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005547}
Mike Stump1eb44332009-09-09 15:08:12 +00005548
Douglas Gregor43959a92009-08-20 07:17:43 +00005549template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005550StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005551TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005552 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005553 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005554 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5555 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005556 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5557 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005558 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005559 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005560
Douglas Gregor43959a92009-08-20 07:17:43 +00005561 if (Transformed != *D)
5562 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005563
Douglas Gregor43959a92009-08-20 07:17:43 +00005564 Decls.push_back(Transformed);
5565 }
Mike Stump1eb44332009-09-09 15:08:12 +00005566
Douglas Gregor43959a92009-08-20 07:17:43 +00005567 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005568 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005569
5570 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005571 S->getStartLoc(), S->getEndLoc());
5572}
Mike Stump1eb44332009-09-09 15:08:12 +00005573
Douglas Gregor43959a92009-08-20 07:17:43 +00005574template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005575StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005576TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005577
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005578 SmallVector<Expr*, 8> Constraints;
5579 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005580 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005581
John McCall60d7b3a2010-08-24 06:29:42 +00005582 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005583 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005584
5585 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005586
Anders Carlsson703e3942010-01-24 05:50:09 +00005587 // Go through the outputs.
5588 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005589 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005590
Anders Carlsson703e3942010-01-24 05:50:09 +00005591 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005592 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005593
Anders Carlsson703e3942010-01-24 05:50:09 +00005594 // Transform the output expr.
5595 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005596 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005597 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005598 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005599
Anders Carlsson703e3942010-01-24 05:50:09 +00005600 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005601
John McCall9ae2f072010-08-23 23:25:46 +00005602 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005603 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005604
Anders Carlsson703e3942010-01-24 05:50:09 +00005605 // Go through the inputs.
5606 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005607 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005608
Anders Carlsson703e3942010-01-24 05:50:09 +00005609 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005610 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005611
Anders Carlsson703e3942010-01-24 05:50:09 +00005612 // Transform the input expr.
5613 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005614 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005615 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005616 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005617
Anders Carlsson703e3942010-01-24 05:50:09 +00005618 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005619
John McCall9ae2f072010-08-23 23:25:46 +00005620 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005621 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005622
Anders Carlsson703e3942010-01-24 05:50:09 +00005623 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005624 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005625
5626 // Go through the clobbers.
5627 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005628 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005629
5630 // No need to transform the asm string literal.
5631 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005632 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5633 S->isVolatile(), S->getNumOutputs(),
5634 S->getNumInputs(), Names.data(),
5635 Constraints, Exprs, AsmString.get(),
5636 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005637}
5638
Chad Rosier8cd64b42012-06-11 20:47:18 +00005639template<typename Derived>
5640StmtResult
5641TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005642 ArrayRef<Token> AsmToks =
5643 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005644
Chad Rosier7bd092b2012-08-15 16:53:30 +00005645 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
5646 AsmToks, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005647}
Douglas Gregor43959a92009-08-20 07:17:43 +00005648
5649template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005650StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005651TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005652 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005653 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005654 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005655 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005656
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005657 // Transform the @catch statements (if present).
5658 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005659 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005660 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005661 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005662 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005663 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005664 if (Catch.get() != S->getCatchStmt(I))
5665 AnyCatchChanged = true;
5666 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005667 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005668
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005669 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005670 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005671 if (S->getFinallyStmt()) {
5672 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5673 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005674 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005675 }
5676
5677 // If nothing changed, just retain this statement.
5678 if (!getDerived().AlwaysRebuild() &&
5679 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005680 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005681 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005682 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005683
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005684 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005685 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005686 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005687}
Mike Stump1eb44332009-09-09 15:08:12 +00005688
Douglas Gregor43959a92009-08-20 07:17:43 +00005689template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005690StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005691TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005692 // Transform the @catch parameter, if there is one.
5693 VarDecl *Var = 0;
5694 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5695 TypeSourceInfo *TSInfo = 0;
5696 if (FromVar->getTypeSourceInfo()) {
5697 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5698 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005699 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005700 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005701
Douglas Gregorbe270a02010-04-26 17:57:08 +00005702 QualType T;
5703 if (TSInfo)
5704 T = TSInfo->getType();
5705 else {
5706 T = getDerived().TransformType(FromVar->getType());
5707 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005708 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005709 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005710
Douglas Gregorbe270a02010-04-26 17:57:08 +00005711 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5712 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005713 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005714 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005715
John McCall60d7b3a2010-08-24 06:29:42 +00005716 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005717 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005718 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005719
5720 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005721 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005722 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005723}
Mike Stump1eb44332009-09-09 15:08:12 +00005724
Douglas Gregor43959a92009-08-20 07:17:43 +00005725template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005726StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005727TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005728 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005729 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005730 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005731 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005732
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005733 // If nothing changed, just retain this statement.
5734 if (!getDerived().AlwaysRebuild() &&
5735 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005736 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005737
5738 // Build a new statement.
5739 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005740 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005741}
Mike Stump1eb44332009-09-09 15:08:12 +00005742
Douglas Gregor43959a92009-08-20 07:17:43 +00005743template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005744StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005745TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005746 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005747 if (S->getThrowExpr()) {
5748 Operand = getDerived().TransformExpr(S->getThrowExpr());
5749 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005750 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005751 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005752
Douglas Gregord1377b22010-04-22 21:44:01 +00005753 if (!getDerived().AlwaysRebuild() &&
5754 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005755 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005756
John McCall9ae2f072010-08-23 23:25:46 +00005757 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005758}
Mike Stump1eb44332009-09-09 15:08:12 +00005759
Douglas Gregor43959a92009-08-20 07:17:43 +00005760template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005761StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005762TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005763 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005764 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005765 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005766 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005767 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005768 Object =
5769 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5770 Object.get());
5771 if (Object.isInvalid())
5772 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005773
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005774 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005775 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005776 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005777 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005778
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005779 // If nothing change, just retain the current statement.
5780 if (!getDerived().AlwaysRebuild() &&
5781 Object.get() == S->getSynchExpr() &&
5782 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005783 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005784
5785 // Build a new statement.
5786 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005787 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005788}
5789
5790template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005791StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005792TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5793 ObjCAutoreleasePoolStmt *S) {
5794 // Transform the body.
5795 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5796 if (Body.isInvalid())
5797 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005798
John McCallf85e1932011-06-15 23:02:42 +00005799 // If nothing changed, just retain this statement.
5800 if (!getDerived().AlwaysRebuild() &&
5801 Body.get() == S->getSubStmt())
5802 return SemaRef.Owned(S);
5803
5804 // Build a new statement.
5805 return getDerived().RebuildObjCAutoreleasePoolStmt(
5806 S->getAtLoc(), Body.get());
5807}
5808
5809template<typename Derived>
5810StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005811TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005812 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005813 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005814 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005815 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005816 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005817
Douglas Gregorc3203e72010-04-22 23:10:45 +00005818 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005819 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005820 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005821 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005822
Douglas Gregorc3203e72010-04-22 23:10:45 +00005823 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005824 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005825 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005826 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005827
Douglas Gregorc3203e72010-04-22 23:10:45 +00005828 // If nothing changed, just retain this statement.
5829 if (!getDerived().AlwaysRebuild() &&
5830 Element.get() == S->getElement() &&
5831 Collection.get() == S->getCollection() &&
5832 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005833 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005834
Douglas Gregorc3203e72010-04-22 23:10:45 +00005835 // Build a new statement.
5836 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005837 Element.get(),
5838 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005839 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005840 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005841}
5842
5843
5844template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005845StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005846TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5847 // Transform the exception declaration, if any.
5848 VarDecl *Var = 0;
5849 if (S->getExceptionDecl()) {
5850 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005851 TypeSourceInfo *T = getDerived().TransformType(
5852 ExceptionDecl->getTypeSourceInfo());
5853 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005854 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005855
Douglas Gregor83cb9422010-09-09 17:09:21 +00005856 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005857 ExceptionDecl->getInnerLocStart(),
5858 ExceptionDecl->getLocation(),
5859 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005860 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005861 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005862 }
Mike Stump1eb44332009-09-09 15:08:12 +00005863
Douglas Gregor43959a92009-08-20 07:17:43 +00005864 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005865 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005866 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005867 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005868
Douglas Gregor43959a92009-08-20 07:17:43 +00005869 if (!getDerived().AlwaysRebuild() &&
5870 !Var &&
5871 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005872 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005873
5874 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5875 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005876 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005877}
Mike Stump1eb44332009-09-09 15:08:12 +00005878
Douglas Gregor43959a92009-08-20 07:17:43 +00005879template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005880StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005881TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5882 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005883 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005884 = getDerived().TransformCompoundStmt(S->getTryBlock());
5885 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005886 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005887
Douglas Gregor43959a92009-08-20 07:17:43 +00005888 // Transform the handlers.
5889 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005890 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00005891 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005892 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005893 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5894 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005895 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005896
Douglas Gregor43959a92009-08-20 07:17:43 +00005897 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5898 Handlers.push_back(Handler.takeAs<Stmt>());
5899 }
Mike Stump1eb44332009-09-09 15:08:12 +00005900
Douglas Gregor43959a92009-08-20 07:17:43 +00005901 if (!getDerived().AlwaysRebuild() &&
5902 TryBlock.get() == S->getTryBlock() &&
5903 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005904 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005905
John McCall9ae2f072010-08-23 23:25:46 +00005906 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005907 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00005908}
Mike Stump1eb44332009-09-09 15:08:12 +00005909
Richard Smithad762fc2011-04-14 22:09:26 +00005910template<typename Derived>
5911StmtResult
5912TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5913 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5914 if (Range.isInvalid())
5915 return StmtError();
5916
5917 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5918 if (BeginEnd.isInvalid())
5919 return StmtError();
5920
5921 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5922 if (Cond.isInvalid())
5923 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005924 if (Cond.get())
5925 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5926 if (Cond.isInvalid())
5927 return StmtError();
5928 if (Cond.get())
5929 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005930
5931 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5932 if (Inc.isInvalid())
5933 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005934 if (Inc.get())
5935 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005936
5937 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5938 if (LoopVar.isInvalid())
5939 return StmtError();
5940
5941 StmtResult NewStmt = S;
5942 if (getDerived().AlwaysRebuild() ||
5943 Range.get() != S->getRangeStmt() ||
5944 BeginEnd.get() != S->getBeginEndStmt() ||
5945 Cond.get() != S->getCond() ||
5946 Inc.get() != S->getInc() ||
5947 LoopVar.get() != S->getLoopVarStmt())
5948 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5949 S->getColonLoc(), Range.get(),
5950 BeginEnd.get(), Cond.get(),
5951 Inc.get(), LoopVar.get(),
5952 S->getRParenLoc());
5953
5954 StmtResult Body = getDerived().TransformStmt(S->getBody());
5955 if (Body.isInvalid())
5956 return StmtError();
5957
5958 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5959 // it now so we have a new statement to attach the body to.
5960 if (Body.get() != S->getBody() && NewStmt.get() == S)
5961 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5962 S->getColonLoc(), Range.get(),
5963 BeginEnd.get(), Cond.get(),
5964 Inc.get(), LoopVar.get(),
5965 S->getRParenLoc());
5966
5967 if (NewStmt.get() == S)
5968 return SemaRef.Owned(S);
5969
5970 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5971}
5972
John Wiegley28bbe4b2011-04-28 01:08:34 +00005973template<typename Derived>
5974StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005975TreeTransform<Derived>::TransformMSDependentExistsStmt(
5976 MSDependentExistsStmt *S) {
5977 // Transform the nested-name-specifier, if any.
5978 NestedNameSpecifierLoc QualifierLoc;
5979 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005980 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00005981 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5982 if (!QualifierLoc)
5983 return StmtError();
5984 }
5985
5986 // Transform the declaration name.
5987 DeclarationNameInfo NameInfo = S->getNameInfo();
5988 if (NameInfo.getName()) {
5989 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5990 if (!NameInfo.getName())
5991 return StmtError();
5992 }
5993
5994 // Check whether anything changed.
5995 if (!getDerived().AlwaysRebuild() &&
5996 QualifierLoc == S->getQualifierLoc() &&
5997 NameInfo.getName() == S->getNameInfo().getName())
5998 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005999
Douglas Gregorba0513d2011-10-25 01:33:02 +00006000 // Determine whether this name exists, if we can.
6001 CXXScopeSpec SS;
6002 SS.Adopt(QualifierLoc);
6003 bool Dependent = false;
6004 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6005 case Sema::IER_Exists:
6006 if (S->isIfExists())
6007 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006008
Douglas Gregorba0513d2011-10-25 01:33:02 +00006009 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6010
6011 case Sema::IER_DoesNotExist:
6012 if (S->isIfNotExists())
6013 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006014
Douglas Gregorba0513d2011-10-25 01:33:02 +00006015 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006016
Douglas Gregorba0513d2011-10-25 01:33:02 +00006017 case Sema::IER_Dependent:
6018 Dependent = true;
6019 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006020
Douglas Gregor65019ac2011-10-25 03:44:56 +00006021 case Sema::IER_Error:
6022 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006023 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006024
Douglas Gregorba0513d2011-10-25 01:33:02 +00006025 // We need to continue with the instantiation, so do so now.
6026 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6027 if (SubStmt.isInvalid())
6028 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006029
Douglas Gregorba0513d2011-10-25 01:33:02 +00006030 // If we have resolved the name, just transform to the substatement.
6031 if (!Dependent)
6032 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006033
Douglas Gregorba0513d2011-10-25 01:33:02 +00006034 // The name is still dependent, so build a dependent expression again.
6035 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6036 S->isIfExists(),
6037 QualifierLoc,
6038 NameInfo,
6039 SubStmt.get());
6040}
6041
6042template<typename Derived>
John McCall76da55d2013-04-16 07:28:30 +00006043ExprResult
6044TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6045 NestedNameSpecifierLoc QualifierLoc;
6046 if (E->getQualifierLoc()) {
6047 QualifierLoc
6048 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6049 if (!QualifierLoc)
6050 return ExprError();
6051 }
6052
6053 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6054 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6055 if (!PD)
6056 return ExprError();
6057
6058 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6059 if (Base.isInvalid())
6060 return ExprError();
6061
6062 return new (SemaRef.getASTContext())
6063 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6064 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6065 QualifierLoc, E->getMemberLoc());
6066}
6067
6068template<typename Derived>
Douglas Gregorba0513d2011-10-25 01:33:02 +00006069StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006070TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6071 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6072 if(TryBlock.isInvalid()) return StmtError();
6073
6074 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6075 if(!getDerived().AlwaysRebuild() &&
6076 TryBlock.get() == S->getTryBlock() &&
6077 Handler.get() == S->getHandler())
6078 return SemaRef.Owned(S);
6079
6080 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6081 S->getTryLoc(),
6082 TryBlock.take(),
6083 Handler.take());
6084}
6085
6086template<typename Derived>
6087StmtResult
6088TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6089 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6090 if(Block.isInvalid()) return StmtError();
6091
6092 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6093 Block.take());
6094}
6095
6096template<typename Derived>
6097StmtResult
6098TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6099 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6100 if(FilterExpr.isInvalid()) return StmtError();
6101
6102 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6103 if(Block.isInvalid()) return StmtError();
6104
6105 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6106 FilterExpr.take(),
6107 Block.take());
6108}
6109
6110template<typename Derived>
6111StmtResult
6112TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6113 if(isa<SEHFinallyStmt>(Handler))
6114 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6115 else
6116 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6117}
6118
Douglas Gregor43959a92009-08-20 07:17:43 +00006119//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006120// Expression transformation
6121//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006122template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006123ExprResult
John McCall454feb92009-12-08 09:21:05 +00006124TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006125 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006126}
Mike Stump1eb44332009-09-09 15:08:12 +00006127
6128template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006129ExprResult
John McCall454feb92009-12-08 09:21:05 +00006130TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006131 NestedNameSpecifierLoc QualifierLoc;
6132 if (E->getQualifierLoc()) {
6133 QualifierLoc
6134 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6135 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006136 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006137 }
John McCalldbd872f2009-12-08 09:08:17 +00006138
6139 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006140 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6141 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006142 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006143 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006144
John McCallec8045d2010-08-17 21:27:17 +00006145 DeclarationNameInfo NameInfo = E->getNameInfo();
6146 if (NameInfo.getName()) {
6147 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6148 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006149 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006150 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006151
6152 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006153 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006154 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006155 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006156 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006157
6158 // Mark it referenced in the new context regardless.
6159 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006160 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006161
John McCall3fa5cae2010-10-26 07:05:15 +00006162 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006163 }
John McCalldbd872f2009-12-08 09:08:17 +00006164
6165 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006166 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006167 TemplateArgs = &TransArgs;
6168 TransArgs.setLAngleLoc(E->getLAngleLoc());
6169 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006170 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6171 E->getNumTemplateArgs(),
6172 TransArgs))
6173 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006174 }
6175
Chad Rosier4a9d7952012-08-08 18:46:20 +00006176 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006177 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006178}
Mike Stump1eb44332009-09-09 15:08:12 +00006179
Douglas Gregorb98b1992009-08-11 05:31:07 +00006180template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006181ExprResult
John McCall454feb92009-12-08 09:21:05 +00006182TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006183 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006184}
Mike Stump1eb44332009-09-09 15:08:12 +00006185
Douglas Gregorb98b1992009-08-11 05:31:07 +00006186template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006187ExprResult
John McCall454feb92009-12-08 09:21:05 +00006188TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006189 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006190}
Mike Stump1eb44332009-09-09 15:08:12 +00006191
Douglas Gregorb98b1992009-08-11 05:31:07 +00006192template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006193ExprResult
John McCall454feb92009-12-08 09:21:05 +00006194TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006195 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006196}
Mike Stump1eb44332009-09-09 15:08:12 +00006197
Douglas Gregorb98b1992009-08-11 05:31:07 +00006198template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006199ExprResult
John McCall454feb92009-12-08 09:21:05 +00006200TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006201 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006202}
Mike Stump1eb44332009-09-09 15:08:12 +00006203
Douglas Gregorb98b1992009-08-11 05:31:07 +00006204template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006205ExprResult
John McCall454feb92009-12-08 09:21:05 +00006206TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006207 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006208}
6209
6210template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006211ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006212TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis391ca9f2013-04-09 01:17:02 +00006213 if (FunctionDecl *FD = E->getDirectCallee())
6214 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smith9fcce652012-03-07 08:35:16 +00006215 return SemaRef.MaybeBindToTemporary(E);
6216}
6217
6218template<typename Derived>
6219ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006220TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6221 ExprResult ControllingExpr =
6222 getDerived().TransformExpr(E->getControllingExpr());
6223 if (ControllingExpr.isInvalid())
6224 return ExprError();
6225
Chris Lattner686775d2011-07-20 06:58:45 +00006226 SmallVector<Expr *, 4> AssocExprs;
6227 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006228 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6229 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6230 if (TS) {
6231 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6232 if (!AssocType)
6233 return ExprError();
6234 AssocTypes.push_back(AssocType);
6235 } else {
6236 AssocTypes.push_back(0);
6237 }
6238
6239 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6240 if (AssocExpr.isInvalid())
6241 return ExprError();
6242 AssocExprs.push_back(AssocExpr.release());
6243 }
6244
6245 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6246 E->getDefaultLoc(),
6247 E->getRParenLoc(),
6248 ControllingExpr.release(),
6249 AssocTypes.data(),
6250 AssocExprs.data(),
6251 E->getNumAssocs());
6252}
6253
6254template<typename Derived>
6255ExprResult
John McCall454feb92009-12-08 09:21:05 +00006256TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006257 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006258 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006259 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006260
Douglas Gregorb98b1992009-08-11 05:31:07 +00006261 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006262 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006263
John McCall9ae2f072010-08-23 23:25:46 +00006264 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006265 E->getRParen());
6266}
6267
Richard Smithefeeccf2012-10-21 03:28:35 +00006268/// \brief The operand of a unary address-of operator has special rules: it's
6269/// allowed to refer to a non-static member of a class even if there's no 'this'
6270/// object available.
6271template<typename Derived>
6272ExprResult
6273TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6274 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6275 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6276 else
6277 return getDerived().TransformExpr(E);
6278}
6279
Mike Stump1eb44332009-09-09 15:08:12 +00006280template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006281ExprResult
John McCall454feb92009-12-08 09:21:05 +00006282TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00006283 ExprResult SubExpr = TransformAddressOfOperand(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006284 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006285 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006286
Douglas Gregorb98b1992009-08-11 05:31:07 +00006287 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006288 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006289
Douglas Gregorb98b1992009-08-11 05:31:07 +00006290 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6291 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006292 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006293}
Mike Stump1eb44332009-09-09 15:08:12 +00006294
Douglas Gregorb98b1992009-08-11 05:31:07 +00006295template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006296ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006297TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6298 // Transform the type.
6299 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6300 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006301 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006302
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006303 // Transform all of the components into components similar to what the
6304 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006305 // FIXME: It would be slightly more efficient in the non-dependent case to
6306 // just map FieldDecls, rather than requiring the rebuilder to look for
6307 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006308 // template code that we don't care.
6309 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006310 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006311 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006312 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006313 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6314 const Node &ON = E->getComponent(I);
6315 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006316 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006317 Comp.LocStart = ON.getSourceRange().getBegin();
6318 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006319 switch (ON.getKind()) {
6320 case Node::Array: {
6321 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006322 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006323 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006324 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006325
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006326 ExprChanged = ExprChanged || Index.get() != FromIndex;
6327 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006328 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006329 break;
6330 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006331
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006332 case Node::Field:
6333 case Node::Identifier:
6334 Comp.isBrackets = false;
6335 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006336 if (!Comp.U.IdentInfo)
6337 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006338
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006339 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006340
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006341 case Node::Base:
6342 // Will be recomputed during the rebuild.
6343 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006344 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006345
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006346 Components.push_back(Comp);
6347 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006348
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006349 // If nothing changed, retain the existing expression.
6350 if (!getDerived().AlwaysRebuild() &&
6351 Type == E->getTypeSourceInfo() &&
6352 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006353 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006354
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006355 // Build a new offsetof expression.
6356 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6357 Components.data(), Components.size(),
6358 E->getRParenLoc());
6359}
6360
6361template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006362ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006363TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6364 assert(getDerived().AlreadyTransformed(E->getType()) &&
6365 "opaque value expression requires transformation");
6366 return SemaRef.Owned(E);
6367}
6368
6369template<typename Derived>
6370ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006371TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006372 // Rebuild the syntactic form. The original syntactic form has
6373 // opaque-value expressions in it, so strip those away and rebuild
6374 // the result. This is a really awful way of doing this, but the
6375 // better solution (rebuilding the semantic expressions and
6376 // rebinding OVEs as necessary) doesn't work; we'd need
6377 // TreeTransform to not strip away implicit conversions.
6378 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6379 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006380 if (result.isInvalid()) return ExprError();
6381
6382 // If that gives us a pseudo-object result back, the pseudo-object
6383 // expression must have been an lvalue-to-rvalue conversion which we
6384 // should reapply.
6385 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6386 result = SemaRef.checkPseudoObjectRValue(result.take());
6387
6388 return result;
6389}
6390
6391template<typename Derived>
6392ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006393TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6394 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006395 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006396 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006397
John McCalla93c9342009-12-07 02:54:59 +00006398 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006399 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006400 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006401
John McCall5ab75172009-11-04 07:28:41 +00006402 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006403 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006404
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006405 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6406 E->getKind(),
6407 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006408 }
Mike Stump1eb44332009-09-09 15:08:12 +00006409
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006410 // C++0x [expr.sizeof]p1:
6411 // The operand is either an expression, which is an unevaluated operand
6412 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006413 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6414 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006415
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006416 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6417 if (SubExpr.isInvalid())
6418 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006419
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006420 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6421 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006422
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006423 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6424 E->getOperatorLoc(),
6425 E->getKind(),
6426 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006427}
Mike Stump1eb44332009-09-09 15:08:12 +00006428
Douglas Gregorb98b1992009-08-11 05:31:07 +00006429template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006430ExprResult
John McCall454feb92009-12-08 09:21:05 +00006431TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006432 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006433 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006434 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006435
John McCall60d7b3a2010-08-24 06:29:42 +00006436 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006437 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006438 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006439
6440
Douglas Gregorb98b1992009-08-11 05:31:07 +00006441 if (!getDerived().AlwaysRebuild() &&
6442 LHS.get() == E->getLHS() &&
6443 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006444 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006445
John McCall9ae2f072010-08-23 23:25:46 +00006446 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006447 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006448 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006449 E->getRBracketLoc());
6450}
Mike Stump1eb44332009-09-09 15:08:12 +00006451
6452template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006453ExprResult
John McCall454feb92009-12-08 09:21:05 +00006454TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006455 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006456 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006457 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006458 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006459
6460 // Transform arguments.
6461 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006462 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006463 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006464 &ArgChanged))
6465 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006466
Douglas Gregorb98b1992009-08-11 05:31:07 +00006467 if (!getDerived().AlwaysRebuild() &&
6468 Callee.get() == E->getCallee() &&
6469 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006470 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006471
Douglas Gregorb98b1992009-08-11 05:31:07 +00006472 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006473 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006474 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006475 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006476 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006477 E->getRParenLoc());
6478}
Mike Stump1eb44332009-09-09 15:08:12 +00006479
6480template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006481ExprResult
John McCall454feb92009-12-08 09:21:05 +00006482TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006483 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006484 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006485 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006486
Douglas Gregor40d96a62011-02-28 21:54:11 +00006487 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006488 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006489 QualifierLoc
6490 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006491
Douglas Gregor40d96a62011-02-28 21:54:11 +00006492 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006493 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006494 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006495 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006496
Eli Friedmanf595cc42009-12-04 06:40:45 +00006497 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006498 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6499 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006500 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006501 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006502
John McCall6bb80172010-03-30 21:47:33 +00006503 NamedDecl *FoundDecl = E->getFoundDecl();
6504 if (FoundDecl == E->getMemberDecl()) {
6505 FoundDecl = Member;
6506 } else {
6507 FoundDecl = cast_or_null<NamedDecl>(
6508 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6509 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006510 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006511 }
6512
Douglas Gregorb98b1992009-08-11 05:31:07 +00006513 if (!getDerived().AlwaysRebuild() &&
6514 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006515 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006516 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006517 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006518 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006519
Anders Carlsson1f240322009-12-22 05:24:09 +00006520 // Mark it referenced in the new context regardless.
6521 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006522 SemaRef.MarkMemberReferenced(E);
6523
John McCall3fa5cae2010-10-26 07:05:15 +00006524 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006525 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006526
John McCalld5532b62009-11-23 01:53:49 +00006527 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006528 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006529 TransArgs.setLAngleLoc(E->getLAngleLoc());
6530 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006531 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6532 E->getNumTemplateArgs(),
6533 TransArgs))
6534 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006535 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006536
Douglas Gregorb98b1992009-08-11 05:31:07 +00006537 // FIXME: Bogus source location for the operator
6538 SourceLocation FakeOperatorLoc
6539 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6540
John McCallc2233c52010-01-15 08:34:02 +00006541 // FIXME: to do this check properly, we will need to preserve the
6542 // first-qualifier-in-scope here, just in case we had a dependent
6543 // base (and therefore couldn't do the check) and a
6544 // nested-name-qualifier (and therefore could do the lookup).
6545 NamedDecl *FirstQualifierInScope = 0;
6546
John McCall9ae2f072010-08-23 23:25:46 +00006547 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006548 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006549 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006550 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006551 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006552 Member,
John McCall6bb80172010-03-30 21:47:33 +00006553 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006554 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006555 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006556 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006557}
Mike Stump1eb44332009-09-09 15:08:12 +00006558
Douglas Gregorb98b1992009-08-11 05:31:07 +00006559template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006560ExprResult
John McCall454feb92009-12-08 09:21:05 +00006561TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006562 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006563 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006564 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006565
John McCall60d7b3a2010-08-24 06:29:42 +00006566 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006567 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006568 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006569
Douglas Gregorb98b1992009-08-11 05:31:07 +00006570 if (!getDerived().AlwaysRebuild() &&
6571 LHS.get() == E->getLHS() &&
6572 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006573 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006574
Lang Hamesbe9af122012-10-02 04:45:10 +00006575 Sema::FPContractStateRAII FPContractState(getSema());
6576 getSema().FPFeatures.fp_contract = E->isFPContractable();
6577
Douglas Gregorb98b1992009-08-11 05:31:07 +00006578 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006579 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006580}
6581
Mike Stump1eb44332009-09-09 15:08:12 +00006582template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006583ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006584TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006585 CompoundAssignOperator *E) {
6586 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006587}
Mike Stump1eb44332009-09-09 15:08:12 +00006588
Douglas Gregorb98b1992009-08-11 05:31:07 +00006589template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006590ExprResult TreeTransform<Derived>::
6591TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6592 // Just rebuild the common and RHS expressions and see whether we
6593 // get any changes.
6594
6595 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6596 if (commonExpr.isInvalid())
6597 return ExprError();
6598
6599 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6600 if (rhs.isInvalid())
6601 return ExprError();
6602
6603 if (!getDerived().AlwaysRebuild() &&
6604 commonExpr.get() == e->getCommon() &&
6605 rhs.get() == e->getFalseExpr())
6606 return SemaRef.Owned(e);
6607
6608 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6609 e->getQuestionLoc(),
6610 0,
6611 e->getColonLoc(),
6612 rhs.get());
6613}
6614
6615template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006616ExprResult
John McCall454feb92009-12-08 09:21:05 +00006617TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006618 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006619 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006620 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006621
John McCall60d7b3a2010-08-24 06:29:42 +00006622 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006623 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006624 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006625
John McCall60d7b3a2010-08-24 06:29:42 +00006626 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006627 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006628 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006629
Douglas Gregorb98b1992009-08-11 05:31:07 +00006630 if (!getDerived().AlwaysRebuild() &&
6631 Cond.get() == E->getCond() &&
6632 LHS.get() == E->getLHS() &&
6633 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006634 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006635
John McCall9ae2f072010-08-23 23:25:46 +00006636 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006637 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006638 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006639 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006640 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006641}
Mike Stump1eb44332009-09-09 15:08:12 +00006642
6643template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006644ExprResult
John McCall454feb92009-12-08 09:21:05 +00006645TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006646 // Implicit casts are eliminated during transformation, since they
6647 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006648 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006649}
Mike Stump1eb44332009-09-09 15:08:12 +00006650
Douglas Gregorb98b1992009-08-11 05:31:07 +00006651template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006652ExprResult
John McCall454feb92009-12-08 09:21:05 +00006653TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006654 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6655 if (!Type)
6656 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006657
John McCall60d7b3a2010-08-24 06:29:42 +00006658 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006659 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006660 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006661 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006662
Douglas Gregorb98b1992009-08-11 05:31:07 +00006663 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006664 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006665 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006666 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006667
John McCall9d125032010-01-15 18:39:57 +00006668 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006669 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006670 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006671 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006672}
Mike Stump1eb44332009-09-09 15:08:12 +00006673
Douglas Gregorb98b1992009-08-11 05:31:07 +00006674template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006675ExprResult
John McCall454feb92009-12-08 09:21:05 +00006676TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006677 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6678 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6679 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006680 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006681
John McCall60d7b3a2010-08-24 06:29:42 +00006682 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006683 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006684 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006685
Douglas Gregorb98b1992009-08-11 05:31:07 +00006686 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006687 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006688 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006689 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006690
John McCall1d7d8d62010-01-19 22:33:45 +00006691 // Note: the expression type doesn't necessarily match the
6692 // type-as-written, but that's okay, because it should always be
6693 // derivable from the initializer.
6694
John McCall42f56b52010-01-18 19:35:47 +00006695 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006696 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006697 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006698}
Mike Stump1eb44332009-09-09 15:08:12 +00006699
Douglas Gregorb98b1992009-08-11 05:31:07 +00006700template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006701ExprResult
John McCall454feb92009-12-08 09:21:05 +00006702TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006703 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006704 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006705 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006706
Douglas Gregorb98b1992009-08-11 05:31:07 +00006707 if (!getDerived().AlwaysRebuild() &&
6708 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006709 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006710
Douglas Gregorb98b1992009-08-11 05:31:07 +00006711 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006712 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006713 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006714 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006715 E->getAccessorLoc(),
6716 E->getAccessor());
6717}
Mike Stump1eb44332009-09-09 15:08:12 +00006718
Douglas Gregorb98b1992009-08-11 05:31:07 +00006719template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006720ExprResult
John McCall454feb92009-12-08 09:21:05 +00006721TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006722 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006723
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006724 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006725 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006726 Inits, &InitChanged))
6727 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006728
Douglas Gregorb98b1992009-08-11 05:31:07 +00006729 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006730 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006731
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006732 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006733 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006734}
Mike Stump1eb44332009-09-09 15:08:12 +00006735
Douglas Gregorb98b1992009-08-11 05:31:07 +00006736template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006737ExprResult
John McCall454feb92009-12-08 09:21:05 +00006738TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006739 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006740
Douglas Gregor43959a92009-08-20 07:17:43 +00006741 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006742 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006743 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006744 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006745
Douglas Gregor43959a92009-08-20 07:17:43 +00006746 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006747 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006748 bool ExprChanged = false;
6749 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6750 DEnd = E->designators_end();
6751 D != DEnd; ++D) {
6752 if (D->isFieldDesignator()) {
6753 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6754 D->getDotLoc(),
6755 D->getFieldLoc()));
6756 continue;
6757 }
Mike Stump1eb44332009-09-09 15:08:12 +00006758
Douglas Gregorb98b1992009-08-11 05:31:07 +00006759 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006760 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006761 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006762 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006763
6764 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006765 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006766
Douglas Gregorb98b1992009-08-11 05:31:07 +00006767 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6768 ArrayExprs.push_back(Index.release());
6769 continue;
6770 }
Mike Stump1eb44332009-09-09 15:08:12 +00006771
Douglas Gregorb98b1992009-08-11 05:31:07 +00006772 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006773 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006774 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6775 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006776 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006777
John McCall60d7b3a2010-08-24 06:29:42 +00006778 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006779 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006780 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006781
6782 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006783 End.get(),
6784 D->getLBracketLoc(),
6785 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006786
Douglas Gregorb98b1992009-08-11 05:31:07 +00006787 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6788 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006789
Douglas Gregorb98b1992009-08-11 05:31:07 +00006790 ArrayExprs.push_back(Start.release());
6791 ArrayExprs.push_back(End.release());
6792 }
Mike Stump1eb44332009-09-09 15:08:12 +00006793
Douglas Gregorb98b1992009-08-11 05:31:07 +00006794 if (!getDerived().AlwaysRebuild() &&
6795 Init.get() == E->getInit() &&
6796 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006797 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006798
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006799 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006800 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006801 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006802}
Mike Stump1eb44332009-09-09 15:08:12 +00006803
Douglas Gregorb98b1992009-08-11 05:31:07 +00006804template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006805ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006806TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006807 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006808 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006809
Douglas Gregor5557b252009-10-28 00:29:27 +00006810 // FIXME: Will we ever have proper type location here? Will we actually
6811 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006812 QualType T = getDerived().TransformType(E->getType());
6813 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006814 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006815
Douglas Gregorb98b1992009-08-11 05:31:07 +00006816 if (!getDerived().AlwaysRebuild() &&
6817 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006818 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006819
Douglas Gregorb98b1992009-08-11 05:31:07 +00006820 return getDerived().RebuildImplicitValueInitExpr(T);
6821}
Mike Stump1eb44332009-09-09 15:08:12 +00006822
Douglas Gregorb98b1992009-08-11 05:31:07 +00006823template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006824ExprResult
John McCall454feb92009-12-08 09:21:05 +00006825TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006826 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6827 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006828 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006829
John McCall60d7b3a2010-08-24 06:29:42 +00006830 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006831 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006832 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006833
Douglas Gregorb98b1992009-08-11 05:31:07 +00006834 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006835 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006836 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006837 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006838
John McCall9ae2f072010-08-23 23:25:46 +00006839 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006840 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006841}
6842
6843template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006844ExprResult
John McCall454feb92009-12-08 09:21:05 +00006845TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006846 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006847 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00006848 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6849 &ArgumentChanged))
6850 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006851
Douglas Gregorb98b1992009-08-11 05:31:07 +00006852 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006853 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006854 E->getRParenLoc());
6855}
Mike Stump1eb44332009-09-09 15:08:12 +00006856
Douglas Gregorb98b1992009-08-11 05:31:07 +00006857/// \brief Transform an address-of-label expression.
6858///
6859/// By default, the transformation of an address-of-label expression always
6860/// rebuilds the expression, so that the label identifier can be resolved to
6861/// the corresponding label statement by semantic analysis.
6862template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006863ExprResult
John McCall454feb92009-12-08 09:21:05 +00006864TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006865 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6866 E->getLabel());
6867 if (!LD)
6868 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006869
Douglas Gregorb98b1992009-08-11 05:31:07 +00006870 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006871 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006872}
Mike Stump1eb44332009-09-09 15:08:12 +00006873
6874template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006875ExprResult
John McCall454feb92009-12-08 09:21:05 +00006876TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006877 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006878 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006879 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006880 if (SubStmt.isInvalid()) {
6881 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006882 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006883 }
Mike Stump1eb44332009-09-09 15:08:12 +00006884
Douglas Gregorb98b1992009-08-11 05:31:07 +00006885 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006886 SubStmt.get() == E->getSubStmt()) {
6887 // Calling this an 'error' is unintuitive, but it does the right thing.
6888 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006889 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006890 }
Mike Stump1eb44332009-09-09 15:08:12 +00006891
6892 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006893 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006894 E->getRParenLoc());
6895}
Mike Stump1eb44332009-09-09 15:08:12 +00006896
Douglas Gregorb98b1992009-08-11 05:31:07 +00006897template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006898ExprResult
John McCall454feb92009-12-08 09:21:05 +00006899TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006900 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006901 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006902 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006903
John McCall60d7b3a2010-08-24 06:29:42 +00006904 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006905 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006906 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006907
John McCall60d7b3a2010-08-24 06:29:42 +00006908 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006909 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006910 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006911
Douglas Gregorb98b1992009-08-11 05:31:07 +00006912 if (!getDerived().AlwaysRebuild() &&
6913 Cond.get() == E->getCond() &&
6914 LHS.get() == E->getLHS() &&
6915 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006916 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006917
Douglas Gregorb98b1992009-08-11 05:31:07 +00006918 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006919 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006920 E->getRParenLoc());
6921}
Mike Stump1eb44332009-09-09 15:08:12 +00006922
Douglas Gregorb98b1992009-08-11 05:31:07 +00006923template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006924ExprResult
John McCall454feb92009-12-08 09:21:05 +00006925TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006926 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006927}
6928
6929template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006930ExprResult
John McCall454feb92009-12-08 09:21:05 +00006931TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006932 switch (E->getOperator()) {
6933 case OO_New:
6934 case OO_Delete:
6935 case OO_Array_New:
6936 case OO_Array_Delete:
6937 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006938
Douglas Gregor668d6d92009-12-13 20:44:55 +00006939 case OO_Call: {
6940 // This is a call to an object's operator().
6941 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6942
6943 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006944 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006945 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006946 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006947
6948 // FIXME: Poor location information
6949 SourceLocation FakeLParenLoc
6950 = SemaRef.PP.getLocForEndOfToken(
6951 static_cast<Expr *>(Object.get())->getLocEnd());
6952
6953 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006954 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006955 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006956 Args))
6957 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006958
John McCall9ae2f072010-08-23 23:25:46 +00006959 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006960 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006961 E->getLocEnd());
6962 }
6963
6964#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6965 case OO_##Name:
6966#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6967#include "clang/Basic/OperatorKinds.def"
6968 case OO_Subscript:
6969 // Handled below.
6970 break;
6971
6972 case OO_Conditional:
6973 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006974
6975 case OO_None:
6976 case NUM_OVERLOADED_OPERATORS:
6977 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006978 }
6979
John McCall60d7b3a2010-08-24 06:29:42 +00006980 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006981 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006982 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006983
Richard Smithefeeccf2012-10-21 03:28:35 +00006984 ExprResult First;
6985 if (E->getOperator() == OO_Amp)
6986 First = getDerived().TransformAddressOfOperand(E->getArg(0));
6987 else
6988 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006989 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006990 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006991
John McCall60d7b3a2010-08-24 06:29:42 +00006992 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006993 if (E->getNumArgs() == 2) {
6994 Second = getDerived().TransformExpr(E->getArg(1));
6995 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006996 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006997 }
Mike Stump1eb44332009-09-09 15:08:12 +00006998
Douglas Gregorb98b1992009-08-11 05:31:07 +00006999 if (!getDerived().AlwaysRebuild() &&
7000 Callee.get() == E->getCallee() &&
7001 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00007002 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00007003 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007004
Lang Hamesbe9af122012-10-02 04:45:10 +00007005 Sema::FPContractStateRAII FPContractState(getSema());
7006 getSema().FPFeatures.fp_contract = E->isFPContractable();
7007
Douglas Gregorb98b1992009-08-11 05:31:07 +00007008 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7009 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007010 Callee.get(),
7011 First.get(),
7012 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007013}
Mike Stump1eb44332009-09-09 15:08:12 +00007014
Douglas Gregorb98b1992009-08-11 05:31:07 +00007015template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007016ExprResult
John McCall454feb92009-12-08 09:21:05 +00007017TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7018 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007019}
Mike Stump1eb44332009-09-09 15:08:12 +00007020
Douglas Gregorb98b1992009-08-11 05:31:07 +00007021template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007022ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00007023TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7024 // Transform the callee.
7025 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7026 if (Callee.isInvalid())
7027 return ExprError();
7028
7029 // Transform exec config.
7030 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7031 if (EC.isInvalid())
7032 return ExprError();
7033
7034 // Transform arguments.
7035 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007036 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007037 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007038 &ArgChanged))
7039 return ExprError();
7040
7041 if (!getDerived().AlwaysRebuild() &&
7042 Callee.get() == E->getCallee() &&
7043 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007044 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00007045
7046 // FIXME: Wrong source location information for the '('.
7047 SourceLocation FakeLParenLoc
7048 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7049 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007050 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007051 E->getRParenLoc(), EC.get());
7052}
7053
7054template<typename Derived>
7055ExprResult
John McCall454feb92009-12-08 09:21:05 +00007056TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007057 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7058 if (!Type)
7059 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007060
John McCall60d7b3a2010-08-24 06:29:42 +00007061 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007062 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007063 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007064 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007065
Douglas Gregorb98b1992009-08-11 05:31:07 +00007066 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007067 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007068 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007069 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007070 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007071 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007072 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007073 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007074 E->getAngleBrackets().getEnd(),
7075 // FIXME. this should be '(' location
7076 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007077 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007078 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007079}
Mike Stump1eb44332009-09-09 15:08:12 +00007080
Douglas Gregorb98b1992009-08-11 05:31:07 +00007081template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007082ExprResult
John McCall454feb92009-12-08 09:21:05 +00007083TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7084 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007085}
Mike Stump1eb44332009-09-09 15:08:12 +00007086
7087template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007088ExprResult
John McCall454feb92009-12-08 09:21:05 +00007089TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7090 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007091}
7092
Douglas Gregorb98b1992009-08-11 05:31:07 +00007093template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007094ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007095TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007096 CXXReinterpretCastExpr *E) {
7097 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007098}
Mike Stump1eb44332009-09-09 15:08:12 +00007099
Douglas Gregorb98b1992009-08-11 05:31:07 +00007100template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007101ExprResult
John McCall454feb92009-12-08 09:21:05 +00007102TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7103 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007104}
Mike Stump1eb44332009-09-09 15:08:12 +00007105
Douglas Gregorb98b1992009-08-11 05:31:07 +00007106template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007107ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007108TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007109 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007110 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7111 if (!Type)
7112 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007113
John McCall60d7b3a2010-08-24 06:29:42 +00007114 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007115 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007116 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007117 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007118
Douglas Gregorb98b1992009-08-11 05:31:07 +00007119 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007120 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007121 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007122 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007123
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007124 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007125 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007126 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007127 E->getRParenLoc());
7128}
Mike Stump1eb44332009-09-09 15:08:12 +00007129
Douglas Gregorb98b1992009-08-11 05:31:07 +00007130template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007131ExprResult
John McCall454feb92009-12-08 09:21:05 +00007132TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007133 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007134 TypeSourceInfo *TInfo
7135 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7136 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007137 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007138
Douglas Gregorb98b1992009-08-11 05:31:07 +00007139 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007140 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007141 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007142
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007143 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7144 E->getLocStart(),
7145 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007146 E->getLocEnd());
7147 }
Mike Stump1eb44332009-09-09 15:08:12 +00007148
Eli Friedmanef331b72012-01-20 01:26:23 +00007149 // We don't know whether the subexpression is potentially evaluated until
7150 // after we perform semantic analysis. We speculatively assume it is
7151 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007152 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007153 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7154 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007155
John McCall60d7b3a2010-08-24 06:29:42 +00007156 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007157 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007158 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007159
Douglas Gregorb98b1992009-08-11 05:31:07 +00007160 if (!getDerived().AlwaysRebuild() &&
7161 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007162 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007163
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007164 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7165 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007166 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007167 E->getLocEnd());
7168}
7169
7170template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007171ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007172TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7173 if (E->isTypeOperand()) {
7174 TypeSourceInfo *TInfo
7175 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7176 if (!TInfo)
7177 return ExprError();
7178
7179 if (!getDerived().AlwaysRebuild() &&
7180 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007181 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007182
Douglas Gregor3c52a212011-03-06 17:40:41 +00007183 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007184 E->getLocStart(),
7185 TInfo,
7186 E->getLocEnd());
7187 }
7188
Francois Pichet01b7c302010-09-08 12:20:18 +00007189 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7190
7191 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7192 if (SubExpr.isInvalid())
7193 return ExprError();
7194
7195 if (!getDerived().AlwaysRebuild() &&
7196 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007197 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007198
7199 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7200 E->getLocStart(),
7201 SubExpr.get(),
7202 E->getLocEnd());
7203}
7204
7205template<typename Derived>
7206ExprResult
John McCall454feb92009-12-08 09:21:05 +00007207TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007208 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007209}
Mike Stump1eb44332009-09-09 15:08:12 +00007210
Douglas Gregorb98b1992009-08-11 05:31:07 +00007211template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007212ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007213TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007214 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007215 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007216}
Mike Stump1eb44332009-09-09 15:08:12 +00007217
Douglas Gregorb98b1992009-08-11 05:31:07 +00007218template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007219ExprResult
John McCall454feb92009-12-08 09:21:05 +00007220TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007221 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007222 QualType T;
7223 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7224 T = MD->getThisType(getSema().Context);
Douglas Gregore4743be2013-03-08 22:43:48 +00007225 else if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(DC)) {
Richard Smith7a614d82011-06-11 17:19:42 +00007226 T = getSema().Context.getPointerType(
Douglas Gregore4743be2013-03-08 22:43:48 +00007227 getSema().Context.getRecordType(Record));
7228 } else {
7229 assert(SemaRef.Context.getDiagnostics().hasErrorOccurred() &&
7230 "this in the wrong scope?");
7231 return ExprError();
7232 }
Mike Stump1eb44332009-09-09 15:08:12 +00007233
Douglas Gregorec79d872012-02-24 17:41:38 +00007234 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7235 // Make sure that we capture 'this'.
7236 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007237 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007238 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007239
Douglas Gregor828a1972010-01-07 23:12:05 +00007240 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007241}
Mike Stump1eb44332009-09-09 15:08:12 +00007242
Douglas Gregorb98b1992009-08-11 05:31:07 +00007243template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007244ExprResult
John McCall454feb92009-12-08 09:21:05 +00007245TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007246 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007247 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007248 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007249
Douglas Gregorb98b1992009-08-11 05:31:07 +00007250 if (!getDerived().AlwaysRebuild() &&
7251 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007252 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007253
Douglas Gregorbca01b42011-07-06 22:04:06 +00007254 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7255 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007256}
Mike Stump1eb44332009-09-09 15:08:12 +00007257
Douglas Gregorb98b1992009-08-11 05:31:07 +00007258template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007259ExprResult
John McCall454feb92009-12-08 09:21:05 +00007260TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007261 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007262 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7263 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007264 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007265 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007266
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007267 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007268 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007269 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007270
Douglas Gregor036aed12009-12-23 23:03:06 +00007271 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007272}
Mike Stump1eb44332009-09-09 15:08:12 +00007273
Douglas Gregorb98b1992009-08-11 05:31:07 +00007274template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007275ExprResult
Richard Smithc3bf52c2013-04-20 22:23:05 +00007276TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7277 FieldDecl *Field
7278 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7279 E->getField()));
7280 if (!Field)
7281 return ExprError();
7282
7283 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7284 return SemaRef.Owned(E);
7285
7286 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7287}
7288
7289template<typename Derived>
7290ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007291TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7292 CXXScalarValueInitExpr *E) {
7293 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7294 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007295 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007296
Douglas Gregorb98b1992009-08-11 05:31:07 +00007297 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007298 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007299 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007300
Chad Rosier4a9d7952012-08-08 18:46:20 +00007301 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007302 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007303 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007304}
Mike Stump1eb44332009-09-09 15:08:12 +00007305
Douglas Gregorb98b1992009-08-11 05:31:07 +00007306template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007307ExprResult
John McCall454feb92009-12-08 09:21:05 +00007308TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007309 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007310 TypeSourceInfo *AllocTypeInfo
7311 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7312 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007313 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007314
Douglas Gregorb98b1992009-08-11 05:31:07 +00007315 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007316 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007317 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007318 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007319
Douglas Gregorb98b1992009-08-11 05:31:07 +00007320 // Transform the placement arguments (if any).
7321 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007322 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007323 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007324 E->getNumPlacementArgs(), true,
7325 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007326 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007327
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007328 // Transform the initializer (if any).
7329 Expr *OldInit = E->getInitializer();
7330 ExprResult NewInit;
7331 if (OldInit)
7332 NewInit = getDerived().TransformExpr(OldInit);
7333 if (NewInit.isInvalid())
7334 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007335
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007336 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007337 FunctionDecl *OperatorNew = 0;
7338 if (E->getOperatorNew()) {
7339 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007340 getDerived().TransformDecl(E->getLocStart(),
7341 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007342 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007343 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007344 }
7345
7346 FunctionDecl *OperatorDelete = 0;
7347 if (E->getOperatorDelete()) {
7348 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007349 getDerived().TransformDecl(E->getLocStart(),
7350 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007351 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007352 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007353 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007354
Douglas Gregorb98b1992009-08-11 05:31:07 +00007355 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007356 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007357 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007358 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007359 OperatorNew == E->getOperatorNew() &&
7360 OperatorDelete == E->getOperatorDelete() &&
7361 !ArgumentChanged) {
7362 // Mark any declarations we need as referenced.
7363 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007364 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007365 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007366 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007367 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007368
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007369 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007370 QualType ElementType
7371 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7372 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7373 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7374 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007375 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007376 }
7377 }
7378 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007379
John McCall3fa5cae2010-10-26 07:05:15 +00007380 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007381 }
Mike Stump1eb44332009-09-09 15:08:12 +00007382
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007383 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007384 if (!ArraySize.get()) {
7385 // If no array size was specified, but the new expression was
7386 // instantiated with an array type (e.g., "new T" where T is
7387 // instantiated with "int[4]"), extract the outer bound from the
7388 // array type as our array size. We do this with constant and
7389 // dependently-sized array types.
7390 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7391 if (!ArrayT) {
7392 // Do nothing
7393 } else if (const ConstantArrayType *ConsArrayT
7394 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007395 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007396 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007397 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007398 SemaRef.Context.getSizeType(),
7399 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007400 AllocType = ConsArrayT->getElementType();
7401 } else if (const DependentSizedArrayType *DepArrayT
7402 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7403 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007404 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007405 AllocType = DepArrayT->getElementType();
7406 }
7407 }
7408 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007409
Douglas Gregorb98b1992009-08-11 05:31:07 +00007410 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7411 E->isGlobalNew(),
7412 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007413 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007414 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007415 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007416 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007417 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007418 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007419 E->getDirectInitRange(),
7420 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007421}
Mike Stump1eb44332009-09-09 15:08:12 +00007422
Douglas Gregorb98b1992009-08-11 05:31:07 +00007423template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007424ExprResult
John McCall454feb92009-12-08 09:21:05 +00007425TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007426 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007427 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007428 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007429
Douglas Gregor1af74512010-02-26 00:38:10 +00007430 // Transform the delete operator, if known.
7431 FunctionDecl *OperatorDelete = 0;
7432 if (E->getOperatorDelete()) {
7433 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007434 getDerived().TransformDecl(E->getLocStart(),
7435 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007436 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007437 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007438 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007439
Douglas Gregorb98b1992009-08-11 05:31:07 +00007440 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007441 Operand.get() == E->getArgument() &&
7442 OperatorDelete == E->getOperatorDelete()) {
7443 // Mark any declarations we need as referenced.
7444 // FIXME: instantiation-specific.
7445 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007446 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007447
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007448 if (!E->getArgument()->isTypeDependent()) {
7449 QualType Destroyed = SemaRef.Context.getBaseElementType(
7450 E->getDestroyedType());
7451 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7452 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007453 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007454 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007455 }
7456 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007457
John McCall3fa5cae2010-10-26 07:05:15 +00007458 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007459 }
Mike Stump1eb44332009-09-09 15:08:12 +00007460
Douglas Gregorb98b1992009-08-11 05:31:07 +00007461 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7462 E->isGlobalDelete(),
7463 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007464 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007465}
Mike Stump1eb44332009-09-09 15:08:12 +00007466
Douglas Gregorb98b1992009-08-11 05:31:07 +00007467template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007468ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007469TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007470 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007471 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007472 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007473 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007474
John McCallb3d87482010-08-24 05:47:05 +00007475 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007476 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007477 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007478 E->getOperatorLoc(),
7479 E->isArrow()? tok::arrow : tok::period,
7480 ObjectTypePtr,
7481 MayBePseudoDestructor);
7482 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007483 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007484
John McCallb3d87482010-08-24 05:47:05 +00007485 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007486 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7487 if (QualifierLoc) {
7488 QualifierLoc
7489 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7490 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007491 return ExprError();
7492 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007493 CXXScopeSpec SS;
7494 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007495
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007496 PseudoDestructorTypeStorage Destroyed;
7497 if (E->getDestroyedTypeInfo()) {
7498 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007499 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007500 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007501 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007502 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007503 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007504 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007505 // We aren't likely to be able to resolve the identifier down to a type
7506 // now anyway, so just retain the identifier.
7507 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7508 E->getDestroyedTypeLoc());
7509 } else {
7510 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007511 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007512 *E->getDestroyedTypeIdentifier(),
7513 E->getDestroyedTypeLoc(),
7514 /*Scope=*/0,
7515 SS, ObjectTypePtr,
7516 false);
7517 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007518 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007519
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007520 Destroyed
7521 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7522 E->getDestroyedTypeLoc());
7523 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007524
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007525 TypeSourceInfo *ScopeTypeInfo = 0;
7526 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007527 CXXScopeSpec EmptySS;
7528 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7529 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007530 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007531 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007532 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007533
John McCall9ae2f072010-08-23 23:25:46 +00007534 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007535 E->getOperatorLoc(),
7536 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007537 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007538 ScopeTypeInfo,
7539 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007540 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007541 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007542}
Mike Stump1eb44332009-09-09 15:08:12 +00007543
Douglas Gregora71d8192009-09-04 17:36:40 +00007544template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007545ExprResult
John McCallba135432009-11-21 08:51:07 +00007546TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007547 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007548 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7549 Sema::LookupOrdinaryName);
7550
7551 // Transform all the decls.
7552 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7553 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007554 NamedDecl *InstD = static_cast<NamedDecl*>(
7555 getDerived().TransformDecl(Old->getNameLoc(),
7556 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007557 if (!InstD) {
7558 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7559 // This can happen because of dependent hiding.
7560 if (isa<UsingShadowDecl>(*I))
7561 continue;
7562 else
John McCallf312b1e2010-08-26 23:41:50 +00007563 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007564 }
John McCallf7a1a742009-11-24 19:00:30 +00007565
7566 // Expand using declarations.
7567 if (isa<UsingDecl>(InstD)) {
7568 UsingDecl *UD = cast<UsingDecl>(InstD);
7569 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7570 E = UD->shadow_end(); I != E; ++I)
7571 R.addDecl(*I);
7572 continue;
7573 }
7574
7575 R.addDecl(InstD);
7576 }
7577
7578 // Resolve a kind, but don't do any further analysis. If it's
7579 // ambiguous, the callee needs to deal with it.
7580 R.resolveKind();
7581
7582 // Rebuild the nested-name qualifier, if present.
7583 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007584 if (Old->getQualifierLoc()) {
7585 NestedNameSpecifierLoc QualifierLoc
7586 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7587 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007588 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007589
Douglas Gregor4c9be892011-02-28 20:01:57 +00007590 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007591 }
7592
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007593 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007594 CXXRecordDecl *NamingClass
7595 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7596 Old->getNameLoc(),
7597 Old->getNamingClass()));
7598 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007599 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007600
Douglas Gregor66c45152010-04-27 16:10:10 +00007601 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007602 }
7603
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007604 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7605
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007606 // If we have neither explicit template arguments, nor the template keyword,
7607 // it's a normal declaration name.
7608 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007609 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7610
7611 // If we have template arguments, rebuild them, then rebuild the
7612 // templateid expression.
7613 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007614 if (Old->hasExplicitTemplateArgs() &&
7615 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007616 Old->getNumTemplateArgs(),
7617 TransArgs))
7618 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007619
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007620 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007621 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007622}
Mike Stump1eb44332009-09-09 15:08:12 +00007623
Douglas Gregorb98b1992009-08-11 05:31:07 +00007624template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007625ExprResult
John McCall454feb92009-12-08 09:21:05 +00007626TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007627 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7628 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007629 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007630
Douglas Gregorb98b1992009-08-11 05:31:07 +00007631 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007632 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007633 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007634
Mike Stump1eb44332009-09-09 15:08:12 +00007635 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007636 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007637 T,
7638 E->getLocEnd());
7639}
Mike Stump1eb44332009-09-09 15:08:12 +00007640
Douglas Gregorb98b1992009-08-11 05:31:07 +00007641template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007642ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007643TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7644 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7645 if (!LhsT)
7646 return ExprError();
7647
7648 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7649 if (!RhsT)
7650 return ExprError();
7651
7652 if (!getDerived().AlwaysRebuild() &&
7653 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7654 return SemaRef.Owned(E);
7655
7656 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7657 E->getLocStart(),
7658 LhsT, RhsT,
7659 E->getLocEnd());
7660}
7661
7662template<typename Derived>
7663ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007664TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7665 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007666 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007667 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7668 TypeSourceInfo *From = E->getArg(I);
7669 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007670 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007671 TypeLocBuilder TLB;
7672 TLB.reserve(FromTL.getFullDataSize());
7673 QualType To = getDerived().TransformType(TLB, FromTL);
7674 if (To.isNull())
7675 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007676
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007677 if (To == From->getType())
7678 Args.push_back(From);
7679 else {
7680 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7681 ArgChanged = true;
7682 }
7683 continue;
7684 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007685
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007686 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007687
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007688 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007689 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007690 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7691 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7692 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007693
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007694 // Determine whether the set of unexpanded parameter packs can and should
7695 // be expanded.
7696 bool Expand = true;
7697 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007698 Optional<unsigned> OrigNumExpansions =
7699 ExpansionTL.getTypePtr()->getNumExpansions();
7700 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007701 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7702 PatternTL.getSourceRange(),
7703 Unexpanded,
7704 Expand, RetainExpansion,
7705 NumExpansions))
7706 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007707
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007708 if (!Expand) {
7709 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007710 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007711 // expansion.
7712 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007713
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007714 TypeLocBuilder TLB;
7715 TLB.reserve(From->getTypeLoc().getFullDataSize());
7716
7717 QualType To = getDerived().TransformType(TLB, PatternTL);
7718 if (To.isNull())
7719 return ExprError();
7720
Chad Rosier4a9d7952012-08-08 18:46:20 +00007721 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007722 PatternTL.getSourceRange(),
7723 ExpansionTL.getEllipsisLoc(),
7724 NumExpansions);
7725 if (To.isNull())
7726 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007727
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007728 PackExpansionTypeLoc ToExpansionTL
7729 = TLB.push<PackExpansionTypeLoc>(To);
7730 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7731 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7732 continue;
7733 }
7734
7735 // Expand the pack expansion by substituting for each argument in the
7736 // pack(s).
7737 for (unsigned I = 0; I != *NumExpansions; ++I) {
7738 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7739 TypeLocBuilder TLB;
7740 TLB.reserve(PatternTL.getFullDataSize());
7741 QualType To = getDerived().TransformType(TLB, PatternTL);
7742 if (To.isNull())
7743 return ExprError();
7744
7745 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7746 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007747
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007748 if (!RetainExpansion)
7749 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007750
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007751 // If we're supposed to retain a pack expansion, do so by temporarily
7752 // forgetting the partially-substituted parameter pack.
7753 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7754
7755 TypeLocBuilder TLB;
7756 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007757
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007758 QualType To = getDerived().TransformType(TLB, PatternTL);
7759 if (To.isNull())
7760 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007761
7762 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007763 PatternTL.getSourceRange(),
7764 ExpansionTL.getEllipsisLoc(),
7765 NumExpansions);
7766 if (To.isNull())
7767 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007768
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007769 PackExpansionTypeLoc ToExpansionTL
7770 = TLB.push<PackExpansionTypeLoc>(To);
7771 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7772 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7773 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007774
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007775 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7776 return SemaRef.Owned(E);
7777
7778 return getDerived().RebuildTypeTrait(E->getTrait(),
7779 E->getLocStart(),
7780 Args,
7781 E->getLocEnd());
7782}
7783
7784template<typename Derived>
7785ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007786TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7787 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7788 if (!T)
7789 return ExprError();
7790
7791 if (!getDerived().AlwaysRebuild() &&
7792 T == E->getQueriedTypeSourceInfo())
7793 return SemaRef.Owned(E);
7794
7795 ExprResult SubExpr;
7796 {
7797 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7798 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7799 if (SubExpr.isInvalid())
7800 return ExprError();
7801
7802 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7803 return SemaRef.Owned(E);
7804 }
7805
7806 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7807 E->getLocStart(),
7808 T,
7809 SubExpr.get(),
7810 E->getLocEnd());
7811}
7812
7813template<typename Derived>
7814ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007815TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7816 ExprResult SubExpr;
7817 {
7818 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7819 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7820 if (SubExpr.isInvalid())
7821 return ExprError();
7822
7823 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7824 return SemaRef.Owned(E);
7825 }
7826
7827 return getDerived().RebuildExpressionTrait(
7828 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7829}
7830
7831template<typename Derived>
7832ExprResult
John McCall865d4472009-11-19 22:55:06 +00007833TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007834 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00007835 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
7836}
7837
7838template<typename Derived>
7839ExprResult
7840TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
7841 DependentScopeDeclRefExpr *E,
7842 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007843 NestedNameSpecifierLoc QualifierLoc
7844 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7845 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007846 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007847 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007848
John McCall43fed0d2010-11-12 08:19:04 +00007849 // TODO: If this is a conversion-function-id, verify that the
7850 // destination type name (if present) resolves the same way after
7851 // instantiation as it did in the local scope.
7852
Abramo Bagnara25777432010-08-11 22:01:17 +00007853 DeclarationNameInfo NameInfo
7854 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7855 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007856 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007857
John McCallf7a1a742009-11-24 19:00:30 +00007858 if (!E->hasExplicitTemplateArgs()) {
7859 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007860 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007861 // Note: it is sufficient to compare the Name component of NameInfo:
7862 // if name has not changed, DNLoc has not changed either.
7863 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007864 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007865
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007866 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007867 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007868 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007869 /*TemplateArgs*/ 0,
7870 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007871 }
John McCalld5532b62009-11-23 01:53:49 +00007872
7873 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007874 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7875 E->getNumTemplateArgs(),
7876 TransArgs))
7877 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007878
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007879 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007880 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007881 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007882 &TransArgs,
7883 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007884}
7885
7886template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007887ExprResult
John McCall454feb92009-12-08 09:21:05 +00007888TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00007889 // CXXConstructExprs other than for list-initialization and
7890 // CXXTemporaryObjectExpr are always implicit, so when we have
7891 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00007892 if ((E->getNumArgs() == 1 ||
7893 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00007894 (!getDerived().DropCallArgument(E->getArg(0))) &&
7895 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00007896 return getDerived().TransformExpr(E->getArg(0));
7897
Douglas Gregorb98b1992009-08-11 05:31:07 +00007898 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7899
7900 QualType T = getDerived().TransformType(E->getType());
7901 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007902 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007903
7904 CXXConstructorDecl *Constructor
7905 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007906 getDerived().TransformDecl(E->getLocStart(),
7907 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007908 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007909 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007910
Douglas Gregorb98b1992009-08-11 05:31:07 +00007911 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007912 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007913 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007914 &ArgumentChanged))
7915 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007916
Douglas Gregorb98b1992009-08-11 05:31:07 +00007917 if (!getDerived().AlwaysRebuild() &&
7918 T == E->getType() &&
7919 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007920 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007921 // Mark the constructor as referenced.
7922 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007923 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007924 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007925 }
Mike Stump1eb44332009-09-09 15:08:12 +00007926
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007927 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7928 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007929 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007930 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00007931 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007932 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007933 E->getConstructionKind(),
7934 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007935}
Mike Stump1eb44332009-09-09 15:08:12 +00007936
Douglas Gregorb98b1992009-08-11 05:31:07 +00007937/// \brief Transform a C++ temporary-binding expression.
7938///
Douglas Gregor51326552009-12-24 18:51:59 +00007939/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7940/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007941template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007942ExprResult
John McCall454feb92009-12-08 09:21:05 +00007943TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007944 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007945}
Mike Stump1eb44332009-09-09 15:08:12 +00007946
John McCall4765fa02010-12-06 08:20:24 +00007947/// \brief Transform a C++ expression that contains cleanups that should
7948/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007949///
John McCall4765fa02010-12-06 08:20:24 +00007950/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007951/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007952template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007953ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007954TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007955 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007956}
Mike Stump1eb44332009-09-09 15:08:12 +00007957
Douglas Gregorb98b1992009-08-11 05:31:07 +00007958template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007959ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007960TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007961 CXXTemporaryObjectExpr *E) {
7962 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7963 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007964 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007965
Douglas Gregorb98b1992009-08-11 05:31:07 +00007966 CXXConstructorDecl *Constructor
7967 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00007968 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007969 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007970 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007971 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007972
Douglas Gregorb98b1992009-08-11 05:31:07 +00007973 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007974 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007975 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007976 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007977 &ArgumentChanged))
7978 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007979
Douglas Gregorb98b1992009-08-11 05:31:07 +00007980 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007981 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007982 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007983 !ArgumentChanged) {
7984 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007985 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007986 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007987 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007988
Richard Smithc83c2302012-12-19 01:39:02 +00007989 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00007990 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7991 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007992 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007993 E->getLocEnd());
7994}
Mike Stump1eb44332009-09-09 15:08:12 +00007995
Douglas Gregorb98b1992009-08-11 05:31:07 +00007996template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007997ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007998TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007999 // Transform the type of the lambda parameters and start the definition of
8000 // the lambda itself.
8001 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00008002 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00008003 if (!MethodTy)
8004 return ExprError();
8005
Eli Friedman8da8a662012-09-19 01:18:11 +00008006 // Create the local class that will describe the lambda.
8007 CXXRecordDecl *Class
8008 = getSema().createLambdaClosureType(E->getIntroducerRange(),
8009 MethodTy,
8010 /*KnownDependent=*/false);
8011 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8012
Douglas Gregorc6889e72012-02-14 22:28:59 +00008013 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008014 SmallVector<QualType, 4> ParamTypes;
8015 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00008016 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
8017 E->getCallOperator()->param_begin(),
8018 E->getCallOperator()->param_size(),
8019 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00008020 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00008021
Douglas Gregordfca6f52012-02-13 22:00:16 +00008022 // Build the call operator.
8023 CXXMethodDecl *CallOperator
8024 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008025 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00008026 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008027 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008028 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00008029
Richard Smith612409e2012-07-25 03:56:55 +00008030 return getDerived().TransformLambdaScope(E, CallOperator);
8031}
8032
8033template<typename Derived>
8034ExprResult
8035TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8036 CXXMethodDecl *CallOperator) {
Douglas Gregord5387e82012-02-14 00:00:48 +00008037 // Introduce the context of the call operator.
8038 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8039
Douglas Gregordfca6f52012-02-13 22:00:16 +00008040 // Enter the scope of the lambda.
8041 sema::LambdaScopeInfo *LSI
8042 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
8043 E->getCaptureDefault(),
8044 E->hasExplicitParameters(),
8045 E->hasExplicitResultType(),
8046 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008047
Douglas Gregordfca6f52012-02-13 22:00:16 +00008048 // Transform captures.
Richard Smith612409e2012-07-25 03:56:55 +00008049 bool Invalid = false;
Douglas Gregordfca6f52012-02-13 22:00:16 +00008050 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008051 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008052 CEnd = E->capture_end();
8053 C != CEnd; ++C) {
8054 // When we hit the first implicit capture, tell Sema that we've finished
8055 // the list of explicit captures.
8056 if (!FinishedExplicitCaptures && C->isImplicit()) {
8057 getSema().finishLambdaExplicitCaptures(LSI);
8058 FinishedExplicitCaptures = true;
8059 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008060
Douglas Gregordfca6f52012-02-13 22:00:16 +00008061 // Capturing 'this' is trivial.
8062 if (C->capturesThis()) {
8063 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8064 continue;
8065 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008066
Douglas Gregora7365242012-02-14 19:27:52 +00008067 // Determine the capture kind for Sema.
8068 Sema::TryCaptureKind Kind
8069 = C->isImplicit()? Sema::TryCapture_Implicit
8070 : C->getCaptureKind() == LCK_ByCopy
8071 ? Sema::TryCapture_ExplicitByVal
8072 : Sema::TryCapture_ExplicitByRef;
8073 SourceLocation EllipsisLoc;
8074 if (C->isPackExpansion()) {
8075 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8076 bool ShouldExpand = false;
8077 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008078 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008079 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8080 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008081 Unexpanded,
8082 ShouldExpand, RetainExpansion,
8083 NumExpansions))
8084 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008085
Douglas Gregora7365242012-02-14 19:27:52 +00008086 if (ShouldExpand) {
8087 // The transform has determined that we should perform an expansion;
8088 // transform and capture each of the arguments.
8089 // expansion of the pattern. Do so.
8090 VarDecl *Pack = C->getCapturedVar();
8091 for (unsigned I = 0; I != *NumExpansions; ++I) {
8092 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8093 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008094 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008095 Pack));
8096 if (!CapturedVar) {
8097 Invalid = true;
8098 continue;
8099 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008100
Douglas Gregora7365242012-02-14 19:27:52 +00008101 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008102 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8103 }
Douglas Gregora7365242012-02-14 19:27:52 +00008104 continue;
8105 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008106
Douglas Gregora7365242012-02-14 19:27:52 +00008107 EllipsisLoc = C->getEllipsisLoc();
8108 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008109
Douglas Gregordfca6f52012-02-13 22:00:16 +00008110 // Transform the captured variable.
8111 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008112 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008113 C->getCapturedVar()));
8114 if (!CapturedVar) {
8115 Invalid = true;
8116 continue;
8117 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008118
Douglas Gregordfca6f52012-02-13 22:00:16 +00008119 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008120 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008121 }
8122 if (!FinishedExplicitCaptures)
8123 getSema().finishLambdaExplicitCaptures(LSI);
8124
Douglas Gregordfca6f52012-02-13 22:00:16 +00008125
8126 // Enter a new evaluation context to insulate the lambda from any
8127 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008128 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008129
8130 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008131 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008132 /*IsInstantiation=*/true);
8133 return ExprError();
8134 }
8135
8136 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008137 StmtResult Body = getDerived().TransformStmt(E->getBody());
8138 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008139 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008140 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008141 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008142 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008143
Chad Rosier4a9d7952012-08-08 18:46:20 +00008144 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008145 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008146}
8147
8148template<typename Derived>
8149ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008150TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008151 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008152 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8153 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008154 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008155
Douglas Gregorb98b1992009-08-11 05:31:07 +00008156 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008157 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008158 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008159 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008160 &ArgumentChanged))
8161 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008162
Douglas Gregorb98b1992009-08-11 05:31:07 +00008163 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008164 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008165 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008166 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008167
Douglas Gregorb98b1992009-08-11 05:31:07 +00008168 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008169 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008170 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008171 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008172 E->getRParenLoc());
8173}
Mike Stump1eb44332009-09-09 15:08:12 +00008174
Douglas Gregorb98b1992009-08-11 05:31:07 +00008175template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008176ExprResult
John McCall865d4472009-11-19 22:55:06 +00008177TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008178 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008179 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008180 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008181 Expr *OldBase;
8182 QualType BaseType;
8183 QualType ObjectType;
8184 if (!E->isImplicitAccess()) {
8185 OldBase = E->getBase();
8186 Base = getDerived().TransformExpr(OldBase);
8187 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008188 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008189
John McCallaa81e162009-12-01 22:10:20 +00008190 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008191 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008192 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008193 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008194 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008195 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008196 ObjectTy,
8197 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008198 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008199 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008200
John McCallb3d87482010-08-24 05:47:05 +00008201 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008202 BaseType = ((Expr*) Base.get())->getType();
8203 } else {
8204 OldBase = 0;
8205 BaseType = getDerived().TransformType(E->getBaseType());
8206 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8207 }
Mike Stump1eb44332009-09-09 15:08:12 +00008208
Douglas Gregor6cd21982009-10-20 05:58:46 +00008209 // Transform the first part of the nested-name-specifier that qualifies
8210 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008211 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008212 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008213 E->getFirstQualifierFoundInScope(),
8214 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008215
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008216 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008217 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008218 QualifierLoc
8219 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8220 ObjectType,
8221 FirstQualifierInScope);
8222 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008223 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008224 }
Mike Stump1eb44332009-09-09 15:08:12 +00008225
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008226 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8227
John McCall43fed0d2010-11-12 08:19:04 +00008228 // TODO: If this is a conversion-function-id, verify that the
8229 // destination type name (if present) resolves the same way after
8230 // instantiation as it did in the local scope.
8231
Abramo Bagnara25777432010-08-11 22:01:17 +00008232 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008233 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008234 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008235 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008236
John McCallaa81e162009-12-01 22:10:20 +00008237 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008238 // This is a reference to a member without an explicitly-specified
8239 // template argument list. Optimize for this common case.
8240 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008241 Base.get() == OldBase &&
8242 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008243 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008244 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008245 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008246 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008247
John McCall9ae2f072010-08-23 23:25:46 +00008248 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008249 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008250 E->isArrow(),
8251 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008252 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008253 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008254 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008255 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008256 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008257 }
8258
John McCalld5532b62009-11-23 01:53:49 +00008259 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008260 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8261 E->getNumTemplateArgs(),
8262 TransArgs))
8263 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008264
John McCall9ae2f072010-08-23 23:25:46 +00008265 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008266 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008267 E->isArrow(),
8268 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008269 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008270 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008271 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008272 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008273 &TransArgs);
8274}
8275
8276template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008277ExprResult
John McCall454feb92009-12-08 09:21:05 +00008278TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008279 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008280 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008281 QualType BaseType;
8282 if (!Old->isImplicitAccess()) {
8283 Base = getDerived().TransformExpr(Old->getBase());
8284 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008285 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008286 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8287 Old->isArrow());
8288 if (Base.isInvalid())
8289 return ExprError();
8290 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008291 } else {
8292 BaseType = getDerived().TransformType(Old->getBaseType());
8293 }
John McCall129e2df2009-11-30 22:42:35 +00008294
Douglas Gregor4c9be892011-02-28 20:01:57 +00008295 NestedNameSpecifierLoc QualifierLoc;
8296 if (Old->getQualifierLoc()) {
8297 QualifierLoc
8298 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8299 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008300 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008301 }
8302
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008303 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8304
Abramo Bagnara25777432010-08-11 22:01:17 +00008305 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008306 Sema::LookupOrdinaryName);
8307
8308 // Transform all the decls.
8309 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8310 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008311 NamedDecl *InstD = static_cast<NamedDecl*>(
8312 getDerived().TransformDecl(Old->getMemberLoc(),
8313 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008314 if (!InstD) {
8315 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8316 // This can happen because of dependent hiding.
8317 if (isa<UsingShadowDecl>(*I))
8318 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008319 else {
8320 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008321 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008322 }
John McCall9f54ad42009-12-10 09:41:52 +00008323 }
John McCall129e2df2009-11-30 22:42:35 +00008324
8325 // Expand using declarations.
8326 if (isa<UsingDecl>(InstD)) {
8327 UsingDecl *UD = cast<UsingDecl>(InstD);
8328 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8329 E = UD->shadow_end(); I != E; ++I)
8330 R.addDecl(*I);
8331 continue;
8332 }
8333
8334 R.addDecl(InstD);
8335 }
8336
8337 R.resolveKind();
8338
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008339 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008340 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008341 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008342 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008343 Old->getMemberLoc(),
8344 Old->getNamingClass()));
8345 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008346 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008347
Douglas Gregor66c45152010-04-27 16:10:10 +00008348 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008349 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008350
John McCall129e2df2009-11-30 22:42:35 +00008351 TemplateArgumentListInfo TransArgs;
8352 if (Old->hasExplicitTemplateArgs()) {
8353 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8354 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008355 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8356 Old->getNumTemplateArgs(),
8357 TransArgs))
8358 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008359 }
John McCallc2233c52010-01-15 08:34:02 +00008360
8361 // FIXME: to do this check properly, we will need to preserve the
8362 // first-qualifier-in-scope here, just in case we had a dependent
8363 // base (and therefore couldn't do the check) and a
8364 // nested-name-qualifier (and therefore could do the lookup).
8365 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008366
John McCall9ae2f072010-08-23 23:25:46 +00008367 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008368 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008369 Old->getOperatorLoc(),
8370 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008371 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008372 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008373 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008374 R,
8375 (Old->hasExplicitTemplateArgs()
8376 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008377}
8378
8379template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008380ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008381TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008382 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008383 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8384 if (SubExpr.isInvalid())
8385 return ExprError();
8386
8387 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008388 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008389
8390 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8391}
8392
8393template<typename Derived>
8394ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008395TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008396 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8397 if (Pattern.isInvalid())
8398 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008399
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008400 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8401 return SemaRef.Owned(E);
8402
Douglas Gregor67fd1252011-01-14 21:20:45 +00008403 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8404 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008405}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008406
8407template<typename Derived>
8408ExprResult
8409TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8410 // If E is not value-dependent, then nothing will change when we transform it.
8411 // Note: This is an instantiation-centric view.
8412 if (!E->isValueDependent())
8413 return SemaRef.Owned(E);
8414
8415 // Note: None of the implementations of TryExpandParameterPacks can ever
8416 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008417 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008418 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8419 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008420 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008421 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008422 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008423 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008424 ShouldExpand, RetainExpansion,
8425 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008426 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008427
Douglas Gregor089e8932011-10-10 18:59:29 +00008428 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008429 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008430
Douglas Gregor089e8932011-10-10 18:59:29 +00008431 NamedDecl *Pack = E->getPack();
8432 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008433 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008434 Pack));
8435 if (!Pack)
8436 return ExprError();
8437 }
8438
Chad Rosier4a9d7952012-08-08 18:46:20 +00008439
Douglas Gregoree8aff02011-01-04 17:33:58 +00008440 // We now know the length of the parameter pack, so build a new expression
8441 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008442 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8443 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008444 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008445}
8446
Douglas Gregorbe230c32011-01-03 17:17:50 +00008447template<typename Derived>
8448ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008449TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8450 SubstNonTypeTemplateParmPackExpr *E) {
8451 // Default behavior is to do nothing with this transformation.
8452 return SemaRef.Owned(E);
8453}
8454
8455template<typename Derived>
8456ExprResult
John McCall91a57552011-07-15 05:09:51 +00008457TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8458 SubstNonTypeTemplateParmExpr *E) {
8459 // Default behavior is to do nothing with this transformation.
8460 return SemaRef.Owned(E);
8461}
8462
8463template<typename Derived>
8464ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008465TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8466 // Default behavior is to do nothing with this transformation.
8467 return SemaRef.Owned(E);
8468}
8469
8470template<typename Derived>
8471ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008472TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8473 MaterializeTemporaryExpr *E) {
8474 return getDerived().TransformExpr(E->GetTemporaryExpr());
8475}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008476
Douglas Gregor03e80032011-06-21 17:03:29 +00008477template<typename Derived>
8478ExprResult
John McCall454feb92009-12-08 09:21:05 +00008479TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008480 return SemaRef.MaybeBindToTemporary(E);
8481}
8482
8483template<typename Derived>
8484ExprResult
8485TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008486 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008487}
8488
8489template<typename Derived>
8490ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008491TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8492 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8493 if (SubExpr.isInvalid())
8494 return ExprError();
8495
8496 if (!getDerived().AlwaysRebuild() &&
8497 SubExpr.get() == E->getSubExpr())
8498 return SemaRef.Owned(E);
8499
8500 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008501}
8502
8503template<typename Derived>
8504ExprResult
8505TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8506 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008507 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008508 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008509 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008510 /*IsCall=*/false, Elements, &ArgChanged))
8511 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008512
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008513 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8514 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008515
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008516 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8517 Elements.data(),
8518 Elements.size());
8519}
8520
8521template<typename Derived>
8522ExprResult
8523TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008524 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008525 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008526 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008527 bool ArgChanged = false;
8528 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8529 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008530
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008531 if (OrigElement.isPackExpansion()) {
8532 // This key/value element is a pack expansion.
8533 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8534 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8535 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8536 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8537
8538 // Determine whether the set of unexpanded parameter packs can
8539 // and should be expanded.
8540 bool Expand = true;
8541 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008542 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8543 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008544 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8545 OrigElement.Value->getLocEnd());
8546 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8547 PatternRange,
8548 Unexpanded,
8549 Expand, RetainExpansion,
8550 NumExpansions))
8551 return ExprError();
8552
8553 if (!Expand) {
8554 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008555 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008556 // expansion.
8557 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8558 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8559 if (Key.isInvalid())
8560 return ExprError();
8561
8562 if (Key.get() != OrigElement.Key)
8563 ArgChanged = true;
8564
8565 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8566 if (Value.isInvalid())
8567 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008568
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008569 if (Value.get() != OrigElement.Value)
8570 ArgChanged = true;
8571
Chad Rosier4a9d7952012-08-08 18:46:20 +00008572 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008573 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8574 };
8575 Elements.push_back(Expansion);
8576 continue;
8577 }
8578
8579 // Record right away that the argument was changed. This needs
8580 // to happen even if the array expands to nothing.
8581 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008582
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008583 // The transform has determined that we should perform an elementwise
8584 // expansion of the pattern. Do so.
8585 for (unsigned I = 0; I != *NumExpansions; ++I) {
8586 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8587 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8588 if (Key.isInvalid())
8589 return ExprError();
8590
8591 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8592 if (Value.isInvalid())
8593 return ExprError();
8594
Chad Rosier4a9d7952012-08-08 18:46:20 +00008595 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008596 Key.get(), Value.get(), SourceLocation(), NumExpansions
8597 };
8598
8599 // If any unexpanded parameter packs remain, we still have a
8600 // pack expansion.
8601 if (Key.get()->containsUnexpandedParameterPack() ||
8602 Value.get()->containsUnexpandedParameterPack())
8603 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008604
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008605 Elements.push_back(Element);
8606 }
8607
8608 // We've finished with this pack expansion.
8609 continue;
8610 }
8611
8612 // Transform and check key.
8613 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8614 if (Key.isInvalid())
8615 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008616
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008617 if (Key.get() != OrigElement.Key)
8618 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008619
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008620 // Transform and check value.
8621 ExprResult Value
8622 = getDerived().TransformExpr(OrigElement.Value);
8623 if (Value.isInvalid())
8624 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008625
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008626 if (Value.get() != OrigElement.Value)
8627 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008628
8629 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00008630 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008631 };
8632 Elements.push_back(Element);
8633 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008634
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008635 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8636 return SemaRef.MaybeBindToTemporary(E);
8637
8638 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8639 Elements.data(),
8640 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008641}
8642
Mike Stump1eb44332009-09-09 15:08:12 +00008643template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008644ExprResult
John McCall454feb92009-12-08 09:21:05 +00008645TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008646 TypeSourceInfo *EncodedTypeInfo
8647 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8648 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008649 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008650
Douglas Gregorb98b1992009-08-11 05:31:07 +00008651 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008652 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008653 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008654
8655 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008656 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008657 E->getRParenLoc());
8658}
Mike Stump1eb44332009-09-09 15:08:12 +00008659
Douglas Gregorb98b1992009-08-11 05:31:07 +00008660template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008661ExprResult TreeTransform<Derived>::
8662TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCall93b64572013-04-11 02:14:26 +00008663 // This is a kind of implicit conversion, and it needs to get dropped
8664 // and recomputed for the same general reasons that ImplicitCastExprs
8665 // do, as well a more specific one: this expression is only valid when
8666 // it appears *immediately* as an argument expression.
8667 return getDerived().TransformExpr(E->getSubExpr());
John McCallf85e1932011-06-15 23:02:42 +00008668}
8669
8670template<typename Derived>
8671ExprResult TreeTransform<Derived>::
8672TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008673 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008674 = getDerived().TransformType(E->getTypeInfoAsWritten());
8675 if (!TSInfo)
8676 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008677
John McCallf85e1932011-06-15 23:02:42 +00008678 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008679 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008680 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008681
John McCallf85e1932011-06-15 23:02:42 +00008682 if (!getDerived().AlwaysRebuild() &&
8683 TSInfo == E->getTypeInfoAsWritten() &&
8684 Result.get() == E->getSubExpr())
8685 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008686
John McCallf85e1932011-06-15 23:02:42 +00008687 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008688 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008689 Result.get());
8690}
8691
8692template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008693ExprResult
John McCall454feb92009-12-08 09:21:05 +00008694TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008695 // Transform arguments.
8696 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008697 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008698 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008699 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008700 &ArgChanged))
8701 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008702
Douglas Gregor92e986e2010-04-22 16:44:27 +00008703 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8704 // Class message: transform the receiver type.
8705 TypeSourceInfo *ReceiverTypeInfo
8706 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8707 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008708 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008709
Douglas Gregor92e986e2010-04-22 16:44:27 +00008710 // If nothing changed, just retain the existing message send.
8711 if (!getDerived().AlwaysRebuild() &&
8712 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008713 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008714
8715 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008716 SmallVector<SourceLocation, 16> SelLocs;
8717 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008718 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8719 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008720 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008721 E->getMethodDecl(),
8722 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008723 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008724 E->getRightLoc());
8725 }
8726
8727 // Instance message: transform the receiver
8728 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8729 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008730 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008731 = getDerived().TransformExpr(E->getInstanceReceiver());
8732 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008733 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008734
8735 // If nothing changed, just retain the existing message send.
8736 if (!getDerived().AlwaysRebuild() &&
8737 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008738 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008739
Douglas Gregor92e986e2010-04-22 16:44:27 +00008740 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008741 SmallVector<SourceLocation, 16> SelLocs;
8742 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008743 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008744 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008745 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008746 E->getMethodDecl(),
8747 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008748 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008749 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008750}
8751
Mike Stump1eb44332009-09-09 15:08:12 +00008752template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008753ExprResult
John McCall454feb92009-12-08 09:21:05 +00008754TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008755 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008756}
8757
Mike Stump1eb44332009-09-09 15:08:12 +00008758template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008759ExprResult
John McCall454feb92009-12-08 09:21:05 +00008760TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008761 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008762}
8763
Mike Stump1eb44332009-09-09 15:08:12 +00008764template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008765ExprResult
John McCall454feb92009-12-08 09:21:05 +00008766TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008767 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008768 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008769 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008770 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008771
8772 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008773
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008774 // If nothing changed, just retain the existing expression.
8775 if (!getDerived().AlwaysRebuild() &&
8776 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008777 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008778
John McCall9ae2f072010-08-23 23:25:46 +00008779 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008780 E->getLocation(),
8781 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008782}
8783
Mike Stump1eb44332009-09-09 15:08:12 +00008784template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008785ExprResult
John McCall454feb92009-12-08 09:21:05 +00008786TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008787 // 'super' and types never change. Property never changes. Just
8788 // retain the existing expression.
8789 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008790 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008791
Douglas Gregore3303542010-04-26 20:47:02 +00008792 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008793 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008794 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008795 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008796
Douglas Gregore3303542010-04-26 20:47:02 +00008797 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008798
Douglas Gregore3303542010-04-26 20:47:02 +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);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008803
John McCall12f78a62010-12-02 01:19:52 +00008804 if (E->isExplicitProperty())
8805 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8806 E->getExplicitProperty(),
8807 E->getLocation());
8808
8809 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008810 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008811 E->getImplicitPropertyGetter(),
8812 E->getImplicitPropertySetter(),
8813 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008814}
8815
Mike Stump1eb44332009-09-09 15:08:12 +00008816template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008817ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008818TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8819 // Transform the base expression.
8820 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8821 if (Base.isInvalid())
8822 return ExprError();
8823
8824 // Transform the key expression.
8825 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8826 if (Key.isInvalid())
8827 return ExprError();
8828
8829 // If nothing changed, just retain the existing expression.
8830 if (!getDerived().AlwaysRebuild() &&
8831 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8832 return SemaRef.Owned(E);
8833
Chad Rosier4a9d7952012-08-08 18:46:20 +00008834 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008835 Base.get(), Key.get(),
8836 E->getAtIndexMethodDecl(),
8837 E->setAtIndexMethodDecl());
8838}
8839
8840template<typename Derived>
8841ExprResult
John McCall454feb92009-12-08 09:21:05 +00008842TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008843 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008844 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008845 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008846 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008847
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008848 // If nothing changed, just retain the existing expression.
8849 if (!getDerived().AlwaysRebuild() &&
8850 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008851 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008852
John McCall9ae2f072010-08-23 23:25:46 +00008853 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00008854 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008855 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008856}
8857
Mike Stump1eb44332009-09-09 15:08:12 +00008858template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008859ExprResult
John McCall454feb92009-12-08 09:21:05 +00008860TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008861 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008862 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008863 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008864 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008865 SubExprs, &ArgumentChanged))
8866 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008867
Douglas Gregorb98b1992009-08-11 05:31:07 +00008868 if (!getDerived().AlwaysRebuild() &&
8869 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008870 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008871
Douglas Gregorb98b1992009-08-11 05:31:07 +00008872 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008873 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008874 E->getRParenLoc());
8875}
8876
Mike Stump1eb44332009-09-09 15:08:12 +00008877template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008878ExprResult
John McCall454feb92009-12-08 09:21:05 +00008879TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008880 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008881
John McCallc6ac9c32011-02-04 18:33:18 +00008882 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8883 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8884
8885 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008886 blockScope->TheDecl->setBlockMissingReturnType(
8887 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008888
Chris Lattner686775d2011-07-20 06:58:45 +00008889 SmallVector<ParmVarDecl*, 4> params;
8890 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008891
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008892 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008893 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8894 oldBlock->param_begin(),
8895 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008896 0, paramTypes, &params)) {
8897 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008898 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008899 }
John McCallc6ac9c32011-02-04 18:33:18 +00008900
Jordan Rose09189892013-03-08 22:25:36 +00008901 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008902 QualType exprResultType =
8903 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008904
8905 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008906 if (exprResultType->isObjCObjectType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008907 getSema().Diag(E->getCaretLocation(),
8908 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008909 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008910 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008911 return ExprError();
8912 }
John McCall711c52b2011-01-05 12:14:39 +00008913
Jordan Rosebea522f2013-03-08 21:51:21 +00008914 QualType functionType =
8915 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00008916 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00008917 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008918
8919 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008920 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008921 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008922
8923 if (!oldBlock->blockMissingReturnType()) {
8924 blockScope->HasImplicitReturnType = false;
8925 blockScope->ReturnType = exprResultType;
8926 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008927
John McCall711c52b2011-01-05 12:14:39 +00008928 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008929 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008930 if (body.isInvalid()) {
8931 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008932 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008933 }
John McCall711c52b2011-01-05 12:14:39 +00008934
John McCallc6ac9c32011-02-04 18:33:18 +00008935#ifndef NDEBUG
8936 // In builds with assertions, make sure that we captured everything we
8937 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008938 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8939 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8940 e = oldBlock->capture_end(); i != e; ++i) {
8941 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008942
Douglas Gregorfc921372011-05-20 15:32:55 +00008943 // Ignore parameter packs.
8944 if (isa<ParmVarDecl>(oldCapture) &&
8945 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8946 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008947
Douglas Gregorfc921372011-05-20 15:32:55 +00008948 VarDecl *newCapture =
8949 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8950 oldCapture));
8951 assert(blockScope->CaptureMap.count(newCapture));
8952 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008953 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008954 }
8955#endif
8956
8957 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8958 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008959}
8960
Mike Stump1eb44332009-09-09 15:08:12 +00008961template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008962ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008963TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008964 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008965}
Eli Friedman276b0612011-10-11 02:20:01 +00008966
8967template<typename Derived>
8968ExprResult
8969TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008970 QualType RetTy = getDerived().TransformType(E->getType());
8971 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008972 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008973 SubExprs.reserve(E->getNumSubExprs());
8974 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8975 SubExprs, &ArgumentChanged))
8976 return ExprError();
8977
8978 if (!getDerived().AlwaysRebuild() &&
8979 !ArgumentChanged)
8980 return SemaRef.Owned(E);
8981
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008982 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008983 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008984}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008985
Douglas Gregorb98b1992009-08-11 05:31:07 +00008986//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008987// Type reconstruction
8988//===----------------------------------------------------------------------===//
8989
Mike Stump1eb44332009-09-09 15:08:12 +00008990template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008991QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8992 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008993 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008994 getDerived().getBaseEntity());
8995}
8996
Mike Stump1eb44332009-09-09 15:08:12 +00008997template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008998QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8999 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009000 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009001 getDerived().getBaseEntity());
9002}
9003
Mike Stump1eb44332009-09-09 15:08:12 +00009004template<typename Derived>
9005QualType
John McCall85737a72009-10-30 00:06:24 +00009006TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9007 bool WrittenAsLValue,
9008 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009009 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00009010 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009011}
9012
9013template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009014QualType
John McCall85737a72009-10-30 00:06:24 +00009015TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9016 QualType ClassType,
9017 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009018 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00009019 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009020}
9021
9022template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009023QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00009024TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9025 ArrayType::ArraySizeModifier SizeMod,
9026 const llvm::APInt *Size,
9027 Expr *SizeExpr,
9028 unsigned IndexTypeQuals,
9029 SourceRange BracketsRange) {
9030 if (SizeExpr || !Size)
9031 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9032 IndexTypeQuals, BracketsRange,
9033 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00009034
9035 QualType Types[] = {
9036 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9037 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9038 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00009039 };
9040 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
9041 QualType SizeType;
9042 for (unsigned I = 0; I != NumTypes; ++I)
9043 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9044 SizeType = Types[I];
9045 break;
9046 }
Mike Stump1eb44332009-09-09 15:08:12 +00009047
Eli Friedman01f276d2012-01-25 23:20:27 +00009048 // Note that we can return a VariableArrayType here in the case where
9049 // the element type was a dependent VariableArrayType.
9050 IntegerLiteral *ArraySize
9051 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9052 /*FIXME*/BracketsRange.getBegin());
9053 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009054 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00009055 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009056}
Mike Stump1eb44332009-09-09 15:08:12 +00009057
Douglas Gregor577f75a2009-08-04 16:50:30 +00009058template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009059QualType
9060TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009061 ArrayType::ArraySizeModifier SizeMod,
9062 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009063 unsigned IndexTypeQuals,
9064 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009065 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009066 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009067}
9068
9069template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009070QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009071TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009072 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009073 unsigned IndexTypeQuals,
9074 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009075 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009076 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009077}
Mike Stump1eb44332009-09-09 15:08:12 +00009078
Douglas Gregor577f75a2009-08-04 16:50:30 +00009079template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009080QualType
9081TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009082 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009083 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009084 unsigned IndexTypeQuals,
9085 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009086 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009087 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009088 IndexTypeQuals, BracketsRange);
9089}
9090
9091template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009092QualType
9093TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009094 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009095 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009096 unsigned IndexTypeQuals,
9097 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009098 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009099 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009100 IndexTypeQuals, BracketsRange);
9101}
9102
9103template<typename Derived>
9104QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009105 unsigned NumElements,
9106 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009107 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009108 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009109}
Mike Stump1eb44332009-09-09 15:08:12 +00009110
Douglas Gregor577f75a2009-08-04 16:50:30 +00009111template<typename Derived>
9112QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9113 unsigned NumElements,
9114 SourceLocation AttributeLoc) {
9115 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9116 NumElements, true);
9117 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009118 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9119 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009120 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009121}
Mike Stump1eb44332009-09-09 15:08:12 +00009122
Douglas Gregor577f75a2009-08-04 16:50:30 +00009123template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009124QualType
9125TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009126 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009127 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009128 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009129}
Mike Stump1eb44332009-09-09 15:08:12 +00009130
Douglas Gregor577f75a2009-08-04 16:50:30 +00009131template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009132QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9133 QualType T,
9134 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009135 const FunctionProtoType::ExtProtoInfo &EPI) {
9136 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009137 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009138 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009139 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009140}
Mike Stump1eb44332009-09-09 15:08:12 +00009141
Douglas Gregor577f75a2009-08-04 16:50:30 +00009142template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009143QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9144 return SemaRef.Context.getFunctionNoProtoType(T);
9145}
9146
9147template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009148QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9149 assert(D && "no decl found");
9150 if (D->isInvalidDecl()) return QualType();
9151
Douglas Gregor92e986e2010-04-22 16:44:27 +00009152 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009153 TypeDecl *Ty;
9154 if (isa<UsingDecl>(D)) {
9155 UsingDecl *Using = cast<UsingDecl>(D);
9156 assert(Using->isTypeName() &&
9157 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9158
9159 // A valid resolved using typename decl points to exactly one type decl.
9160 assert(++Using->shadow_begin() == Using->shadow_end());
9161 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009162
John McCalled976492009-12-04 22:46:56 +00009163 } else {
9164 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9165 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9166 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9167 }
9168
9169 return SemaRef.Context.getTypeDeclType(Ty);
9170}
9171
9172template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009173QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9174 SourceLocation Loc) {
9175 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009176}
9177
9178template<typename Derived>
9179QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9180 return SemaRef.Context.getTypeOfType(Underlying);
9181}
9182
9183template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009184QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9185 SourceLocation Loc) {
9186 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009187}
9188
9189template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009190QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9191 UnaryTransformType::UTTKind UKind,
9192 SourceLocation Loc) {
9193 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9194}
9195
9196template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009197QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009198 TemplateName Template,
9199 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009200 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009201 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009202}
Mike Stump1eb44332009-09-09 15:08:12 +00009203
Douglas Gregordcee1a12009-08-06 05:28:30 +00009204template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009205QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9206 SourceLocation KWLoc) {
9207 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9208}
9209
9210template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009211TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009212TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009213 bool TemplateKW,
9214 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009215 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009216 Template);
9217}
9218
9219template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009220TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009221TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9222 const IdentifierInfo &Name,
9223 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009224 QualType ObjectType,
9225 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009226 UnqualifiedId TemplateName;
9227 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009228 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009229 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009230 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009231 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009232 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009233 /*EnteringContext=*/false,
9234 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009235 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009236}
Mike Stump1eb44332009-09-09 15:08:12 +00009237
Douglas Gregorb98b1992009-08-11 05:31:07 +00009238template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009239TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009240TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009241 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009242 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009243 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009244 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009245 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009246 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009247 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009248 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009249 Sema::TemplateTy Template;
9250 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009251 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009252 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009253 /*EnteringContext=*/false,
9254 Template);
9255 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009256}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009257
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009258template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009259ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009260TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9261 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009262 Expr *OrigCallee,
9263 Expr *First,
9264 Expr *Second) {
9265 Expr *Callee = OrigCallee->IgnoreParenCasts();
9266 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009267
Douglas Gregorb98b1992009-08-11 05:31:07 +00009268 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009269 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009270 if (!First->getType()->isOverloadableType() &&
9271 !Second->getType()->isOverloadableType())
9272 return getSema().CreateBuiltinArraySubscriptExpr(First,
9273 Callee->getLocStart(),
9274 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009275 } else if (Op == OO_Arrow) {
9276 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009277 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9278 } else if (Second == 0 || isPostIncDec) {
9279 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009280 // The argument is not of overloadable type, so try to create a
9281 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009282 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009283 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009284
John McCall9ae2f072010-08-23 23:25:46 +00009285 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009286 }
9287 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009288 if (!First->getType()->isOverloadableType() &&
9289 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009290 // Neither of the arguments is an overloadable type, so try to
9291 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009292 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009293 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009294 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009295 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009296 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009297
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009298 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009299 }
9300 }
Mike Stump1eb44332009-09-09 15:08:12 +00009301
9302 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009303 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009304 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009305
John McCall9ae2f072010-08-23 23:25:46 +00009306 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009307 assert(ULE->requiresADL());
9308
9309 // FIXME: Do we have to check
9310 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009311 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009312 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009313 // If we've resolved this to a particular non-member function, just call
9314 // that function. If we resolved it to a member function,
9315 // CreateOverloaded* will find that function for us.
9316 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9317 if (!isa<CXXMethodDecl>(ND))
9318 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009319 }
Mike Stump1eb44332009-09-09 15:08:12 +00009320
Douglas Gregorb98b1992009-08-11 05:31:07 +00009321 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009322 Expr *Args[2] = { First, Second };
9323 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009324
Douglas Gregorb98b1992009-08-11 05:31:07 +00009325 // Create the overloaded operator invocation for unary operators.
9326 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009327 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009328 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009329 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009330 }
Mike Stump1eb44332009-09-09 15:08:12 +00009331
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009332 if (Op == OO_Subscript) {
9333 SourceLocation LBrace;
9334 SourceLocation RBrace;
9335
9336 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9337 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9338 LBrace = SourceLocation::getFromRawEncoding(
9339 NameLoc.CXXOperatorName.BeginOpNameLoc);
9340 RBrace = SourceLocation::getFromRawEncoding(
9341 NameLoc.CXXOperatorName.EndOpNameLoc);
9342 } else {
9343 LBrace = Callee->getLocStart();
9344 RBrace = OpLoc;
9345 }
9346
9347 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9348 First, Second);
9349 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009350
Douglas Gregorb98b1992009-08-11 05:31:07 +00009351 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009352 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009353 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009354 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9355 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009356 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009357
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009358 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009359}
Mike Stump1eb44332009-09-09 15:08:12 +00009360
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009361template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009362ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009363TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009364 SourceLocation OperatorLoc,
9365 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009366 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009367 TypeSourceInfo *ScopeType,
9368 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009369 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009370 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009371 QualType BaseType = Base->getType();
9372 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009373 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009374 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009375 !BaseType->getAs<PointerType>()->getPointeeType()
9376 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009377 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009378 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009379 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009380 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009381 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009382 /*FIXME?*/true);
9383 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009384
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009385 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009386 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9387 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9388 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9389 NameInfo.setNamedTypeInfo(DestroyedType);
9390
Richard Smith6314db92012-05-15 06:15:11 +00009391 // The scope type is now known to be a valid nested name specifier
9392 // component. Tack it on to the end of the nested name specifier.
9393 if (ScopeType)
9394 SS.Extend(SemaRef.Context, SourceLocation(),
9395 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009396
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009397 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009398 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009399 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009400 SS, TemplateKWLoc,
9401 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009402 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009403 /*TemplateArgs*/ 0);
9404}
9405
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009406template<typename Derived>
9407StmtResult
9408TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
9409 llvm_unreachable("not implement yet");
9410}
9411
Douglas Gregor577f75a2009-08-04 16:50:30 +00009412} // end namespace clang
9413
9414#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H