blob: 925860a6000063893a155b2a67ebd367e32a7e05 [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
Richard Smitha2c36462013-04-26 16:15:35 +0000757 /// \brief Build a new C++11 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 Smitha2c36462013-04-26 16:15:35 +0000763 /// \brief Build a new C++11 auto type.
Richard Smith34b41d92011-02-20 03:19:35 +0000764 ///
765 /// By default, builds a new AutoType with the given deduced type.
Richard Smitha2c36462013-04-26 16:15:35 +0000766 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smithdc7a4f52013-04-30 13:56:41 +0000767 // Note, IsDependent is always false here: we implicitly convert an 'auto'
768 // which has been deduced to a dependent type into an undeduced 'auto', so
769 // that we'll retry deduction after the transformation.
Richard Smitha2c36462013-04-26 16:15:35 +0000770 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto);
Richard Smith34b41d92011-02-20 03:19:35 +0000771 }
772
Douglas Gregor577f75a2009-08-04 16:50:30 +0000773 /// \brief Build a new template specialization type.
774 ///
775 /// By default, performs semantic analysis when building the template
776 /// specialization type. Subclasses may override this routine to provide
777 /// different behavior.
778 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000779 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000780 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000781
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000782 /// \brief Build a new parenthesized type.
783 ///
784 /// By default, builds a new ParenType type from the inner type.
785 /// Subclasses may override this routine to provide different behavior.
786 QualType RebuildParenType(QualType InnerType) {
787 return SemaRef.Context.getParenType(InnerType);
788 }
789
Douglas Gregor577f75a2009-08-04 16:50:30 +0000790 /// \brief Build a new qualified name type.
791 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000792 /// By default, builds a new ElaboratedType type from the keyword,
793 /// the nested-name-specifier and the named type.
794 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000795 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
796 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000797 NestedNameSpecifierLoc QualifierLoc,
798 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000799 return SemaRef.Context.getElaboratedType(Keyword,
800 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000801 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000802 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000803
804 /// \brief Build a new typename type that refers to a template-id.
805 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000806 /// By default, builds a new DependentNameType type from the
807 /// nested-name-specifier and the given type. Subclasses may override
808 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000809 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000810 ElaboratedTypeKeyword Keyword,
811 NestedNameSpecifierLoc QualifierLoc,
812 const IdentifierInfo *Name,
813 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000814 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000815 // Rebuild the template name.
816 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000817 CXXScopeSpec SS;
818 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000819 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000820 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000821
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000822 if (InstName.isNull())
823 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000824
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000825 // If it's still dependent, make a dependent specialization.
826 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000827 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
828 QualifierLoc.getNestedNameSpecifier(),
829 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000830 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000831
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000832 // Otherwise, make an elaborated type wrapping a non-dependent
833 // specialization.
834 QualType T =
835 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
836 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000837
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000838 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
839 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000840
841 return SemaRef.Context.getElaboratedType(Keyword,
842 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000843 T);
844 }
845
Douglas Gregor577f75a2009-08-04 16:50:30 +0000846 /// \brief Build a new typename type that refers to an identifier.
847 ///
848 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000849 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000850 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000851 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000852 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000853 NestedNameSpecifierLoc QualifierLoc,
854 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000855 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000856 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000857 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000858
Douglas Gregor2494dd02011-03-01 01:34:45 +0000859 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000860 // If the name is still dependent, just build a new dependent name type.
861 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000862 return SemaRef.Context.getDependentNameType(Keyword,
863 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000864 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000865 }
866
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000867 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000868 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000869 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000870
871 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
872
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000873 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000874 // into a non-dependent elaborated-type-specifier. Find the tag we're
875 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000876 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000877 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
878 if (!DC)
879 return QualType();
880
John McCall56138762010-05-27 06:40:31 +0000881 if (SemaRef.RequireCompleteDeclContext(SS, DC))
882 return QualType();
883
Douglas Gregor40336422010-03-31 22:19:08 +0000884 TagDecl *Tag = 0;
885 SemaRef.LookupQualifiedName(Result, DC);
886 switch (Result.getResultKind()) {
887 case LookupResult::NotFound:
888 case LookupResult::NotFoundInCurrentInstantiation:
889 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000890
Douglas Gregor40336422010-03-31 22:19:08 +0000891 case LookupResult::Found:
892 Tag = Result.getAsSingle<TagDecl>();
893 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000894
Douglas Gregor40336422010-03-31 22:19:08 +0000895 case LookupResult::FoundOverloaded:
896 case LookupResult::FoundUnresolvedValue:
897 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000898
Douglas Gregor40336422010-03-31 22:19:08 +0000899 case LookupResult::Ambiguous:
900 // Let the LookupResult structure handle ambiguities.
901 return QualType();
902 }
903
904 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000905 // Check where the name exists but isn't a tag type and use that to emit
906 // better diagnostics.
907 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
908 SemaRef.LookupQualifiedName(Result, DC);
909 switch (Result.getResultKind()) {
910 case LookupResult::Found:
911 case LookupResult::FoundOverloaded:
912 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000913 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000914 unsigned Kind = 0;
915 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000916 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
917 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000918 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
919 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
920 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000921 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000922 default:
923 // FIXME: Would be nice to highlight just the source range.
924 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
925 << Kind << Id << DC;
926 break;
927 }
Douglas Gregor40336422010-03-31 22:19:08 +0000928 return QualType();
929 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000930
Richard Trieubbf34c02011-06-10 03:11:26 +0000931 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
932 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000933 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000934 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
935 return QualType();
936 }
937
938 // Build the elaborated-type-specifier type.
939 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000940 return SemaRef.Context.getElaboratedType(Keyword,
941 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000942 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000943 }
Mike Stump1eb44332009-09-09 15:08:12 +0000944
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000945 /// \brief Build a new pack expansion type.
946 ///
947 /// By default, builds a new PackExpansionType type from the given pattern.
948 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000949 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000950 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000951 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +0000952 Optional<unsigned> NumExpansions) {
Douglas Gregorcded4f62011-01-14 17:04:44 +0000953 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
954 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000955 }
956
Eli Friedmanb001de72011-10-06 23:00:33 +0000957 /// \brief Build a new atomic type given its value type.
958 ///
959 /// By default, performs semantic analysis when building the atomic type.
960 /// Subclasses may override this routine to provide different behavior.
961 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
962
Douglas Gregord1067e52009-08-06 06:41:21 +0000963 /// \brief Build a new template name given a nested name specifier, a flag
964 /// indicating whether the "template" keyword was provided, and the template
965 /// that the template name refers to.
966 ///
967 /// By default, builds the new template name directly. Subclasses may override
968 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000969 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000970 bool TemplateKW,
971 TemplateDecl *Template);
972
Douglas Gregord1067e52009-08-06 06:41:21 +0000973 /// \brief Build a new template name given a nested name specifier and the
974 /// name that is referred to as a template.
975 ///
976 /// By default, performs semantic analysis to determine whether the name can
977 /// be resolved to a specific template, then builds the appropriate kind of
978 /// template name. Subclasses may override this routine to provide different
979 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000980 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
981 const IdentifierInfo &Name,
982 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000983 QualType ObjectType,
984 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000985
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000986 /// \brief Build a new template name given a nested name specifier and the
987 /// overloaded operator name that is referred to as a template.
988 ///
989 /// By default, performs semantic analysis to determine whether the name can
990 /// be resolved to a specific template, then builds the appropriate kind of
991 /// template name. Subclasses may override this routine to provide different
992 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000993 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000994 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000995 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000996 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000997
998 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +0000999 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001000 ///
1001 /// By default, performs semantic analysis to determine whether the name can
1002 /// be resolved to a specific template, then builds the appropriate kind of
1003 /// template name. Subclasses may override this routine to provide different
1004 /// behavior.
1005 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1006 const TemplateArgument &ArgPack) {
1007 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1008 }
1009
Douglas Gregor43959a92009-08-20 07:17:43 +00001010 /// \brief Build a new compound statement.
1011 ///
1012 /// By default, performs semantic analysis to build the new statement.
1013 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001014 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001015 MultiStmtArg Statements,
1016 SourceLocation RBraceLoc,
1017 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001018 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001019 IsStmtExpr);
1020 }
1021
1022 /// \brief Build a new case statement.
1023 ///
1024 /// By default, performs semantic analysis to build the new statement.
1025 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001026 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001027 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001028 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001029 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001030 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001031 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001032 ColonLoc);
1033 }
Mike Stump1eb44332009-09-09 15:08:12 +00001034
Douglas Gregor43959a92009-08-20 07:17:43 +00001035 /// \brief Attach the body to a new case statement.
1036 ///
1037 /// By default, performs semantic analysis to build the new statement.
1038 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001039 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001040 getSema().ActOnCaseStmtBody(S, Body);
1041 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001042 }
Mike Stump1eb44332009-09-09 15:08:12 +00001043
Douglas Gregor43959a92009-08-20 07:17:43 +00001044 /// \brief Build a new default statement.
1045 ///
1046 /// By default, performs semantic analysis to build the new statement.
1047 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001048 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001049 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001050 Stmt *SubStmt) {
1051 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001052 /*CurScope=*/0);
1053 }
Mike Stump1eb44332009-09-09 15:08:12 +00001054
Douglas Gregor43959a92009-08-20 07:17:43 +00001055 /// \brief Build a new label statement.
1056 ///
1057 /// By default, performs semantic analysis to build the new statement.
1058 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001059 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1060 SourceLocation ColonLoc, Stmt *SubStmt) {
1061 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001062 }
Mike Stump1eb44332009-09-09 15:08:12 +00001063
Richard Smith534986f2012-04-14 00:33:13 +00001064 /// \brief Build a new label statement.
1065 ///
1066 /// By default, performs semantic analysis to build the new statement.
1067 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001068 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1069 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001070 Stmt *SubStmt) {
1071 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1072 }
1073
Douglas Gregor43959a92009-08-20 07:17:43 +00001074 /// \brief Build a new "if" statement.
1075 ///
1076 /// By default, performs semantic analysis to build the new statement.
1077 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001078 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001079 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001080 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001081 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001082 }
Mike Stump1eb44332009-09-09 15:08:12 +00001083
Douglas Gregor43959a92009-08-20 07:17:43 +00001084 /// \brief Start building a new switch statement.
1085 ///
1086 /// By default, performs semantic analysis to build the new statement.
1087 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001088 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001089 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001090 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001091 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001092 }
Mike Stump1eb44332009-09-09 15:08:12 +00001093
Douglas Gregor43959a92009-08-20 07:17:43 +00001094 /// \brief Attach the body to the switch statement.
1095 ///
1096 /// By default, performs semantic analysis to build the new statement.
1097 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001098 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001099 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001100 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001101 }
1102
1103 /// \brief Build a new while statement.
1104 ///
1105 /// By default, performs semantic analysis to build the new statement.
1106 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001107 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1108 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001109 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001110 }
Mike Stump1eb44332009-09-09 15:08:12 +00001111
Douglas Gregor43959a92009-08-20 07:17:43 +00001112 /// \brief Build a new do-while statement.
1113 ///
1114 /// By default, performs semantic analysis to build the new statement.
1115 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001116 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001117 SourceLocation WhileLoc, SourceLocation LParenLoc,
1118 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001119 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1120 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001121 }
1122
1123 /// \brief Build a new for statement.
1124 ///
1125 /// By default, performs semantic analysis to build the new statement.
1126 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001127 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001128 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001129 VarDecl *CondVar, Sema::FullExprArg Inc,
1130 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001131 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001132 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001133 }
Mike Stump1eb44332009-09-09 15:08:12 +00001134
Douglas Gregor43959a92009-08-20 07:17:43 +00001135 /// \brief Build a new goto statement.
1136 ///
1137 /// By default, performs semantic analysis to build the new statement.
1138 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001139 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1140 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001141 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001142 }
1143
1144 /// \brief Build a new indirect goto statement.
1145 ///
1146 /// By default, performs semantic analysis to build the new statement.
1147 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001148 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001149 SourceLocation StarLoc,
1150 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001151 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001152 }
Mike Stump1eb44332009-09-09 15:08:12 +00001153
Douglas Gregor43959a92009-08-20 07:17:43 +00001154 /// \brief Build a new return statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001158 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001159 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001160 }
Mike Stump1eb44332009-09-09 15:08:12 +00001161
Douglas Gregor43959a92009-08-20 07:17:43 +00001162 /// \brief Build a new declaration statement.
1163 ///
1164 /// By default, performs semantic analysis to build the new statement.
1165 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001166 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001167 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001168 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001169 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1170 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001171 }
Mike Stump1eb44332009-09-09 15:08:12 +00001172
Anders Carlsson703e3942010-01-24 05:50:09 +00001173 /// \brief Build a new inline asm statement.
1174 ///
1175 /// By default, performs semantic analysis to build the new statement.
1176 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001177 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1178 bool IsVolatile, unsigned NumOutputs,
1179 unsigned NumInputs, IdentifierInfo **Names,
1180 MultiExprArg Constraints, MultiExprArg Exprs,
1181 Expr *AsmString, MultiExprArg Clobbers,
1182 SourceLocation RParenLoc) {
1183 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1184 NumInputs, Names, Constraints, Exprs,
1185 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001186 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001187
Chad Rosier8cd64b42012-06-11 20:47:18 +00001188 /// \brief Build a new MS style inline asm statement.
1189 ///
1190 /// By default, performs semantic analysis to build the new statement.
1191 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001192 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
1193 ArrayRef<Token> AsmToks, SourceLocation EndLoc) {
Chad Rosier7bd092b2012-08-15 16:53:30 +00001194 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001195 }
1196
James Dennett699c9042012-06-15 07:13:21 +00001197 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001198 ///
1199 /// By default, performs semantic analysis to build the new statement.
1200 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001201 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001202 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001203 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001204 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001205 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001206 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001207 }
1208
Douglas Gregorbe270a02010-04-26 17:57:08 +00001209 /// \brief Rebuild an Objective-C exception declaration.
1210 ///
1211 /// By default, performs semantic analysis to build the new declaration.
1212 /// Subclasses may override this routine to provide different behavior.
1213 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1214 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001215 return getSema().BuildObjCExceptionDecl(TInfo, T,
1216 ExceptionDecl->getInnerLocStart(),
1217 ExceptionDecl->getLocation(),
1218 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001219 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001220
James Dennett699c9042012-06-15 07:13:21 +00001221 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001222 ///
1223 /// By default, performs semantic analysis to build the new statement.
1224 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001225 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001226 SourceLocation RParenLoc,
1227 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001228 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001229 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001230 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001231 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001232
James Dennett699c9042012-06-15 07:13:21 +00001233 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001234 ///
1235 /// By default, performs semantic analysis to build the new statement.
1236 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001237 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001238 Stmt *Body) {
1239 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001240 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001241
James Dennett699c9042012-06-15 07:13:21 +00001242 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001243 ///
1244 /// By default, performs semantic analysis to build the new statement.
1245 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001246 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001247 Expr *Operand) {
1248 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001249 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001250
James Dennett699c9042012-06-15 07:13:21 +00001251 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001252 ///
1253 /// By default, performs semantic analysis to build the new statement.
1254 /// Subclasses may override this routine to provide different behavior.
1255 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1256 Expr *object) {
1257 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1258 }
1259
James Dennett699c9042012-06-15 07:13:21 +00001260 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001261 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001262 /// By default, performs semantic analysis to build the new statement.
1263 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001264 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001265 Expr *Object, Stmt *Body) {
1266 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001267 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001268
James Dennett699c9042012-06-15 07:13:21 +00001269 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001270 ///
1271 /// By default, performs semantic analysis to build the new statement.
1272 /// Subclasses may override this routine to provide different behavior.
1273 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1274 Stmt *Body) {
1275 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1276 }
John McCall990567c2011-07-27 01:07:15 +00001277
Douglas Gregorc3203e72010-04-22 23:10:45 +00001278 /// \brief Build a new Objective-C fast enumeration statement.
1279 ///
1280 /// By default, performs semantic analysis to build the new statement.
1281 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001282 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001283 Stmt *Element,
1284 Expr *Collection,
1285 SourceLocation RParenLoc,
1286 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001287 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001288 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001289 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001290 RParenLoc);
1291 if (ForEachStmt.isInvalid())
1292 return StmtError();
1293
1294 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001295 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001296
Douglas Gregor43959a92009-08-20 07:17:43 +00001297 /// \brief Build a new C++ exception declaration.
1298 ///
1299 /// By default, performs semantic analysis to build the new decaration.
1300 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001301 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001302 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001303 SourceLocation StartLoc,
1304 SourceLocation IdLoc,
1305 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001306 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1307 StartLoc, IdLoc, Id);
1308 if (Var)
1309 getSema().CurContext->addDecl(Var);
1310 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001311 }
1312
1313 /// \brief Build a new C++ catch statement.
1314 ///
1315 /// By default, performs semantic analysis to build the new statement.
1316 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001317 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001318 VarDecl *ExceptionDecl,
1319 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001320 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1321 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001322 }
Mike Stump1eb44332009-09-09 15:08:12 +00001323
Douglas Gregor43959a92009-08-20 07:17:43 +00001324 /// \brief Build a new C++ try statement.
1325 ///
1326 /// By default, performs semantic analysis to build the new statement.
1327 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001328 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001329 Stmt *TryBlock,
1330 MultiStmtArg Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001331 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001332 }
Mike Stump1eb44332009-09-09 15:08:12 +00001333
Richard Smithad762fc2011-04-14 22:09:26 +00001334 /// \brief Build a new C++0x range-based for statement.
1335 ///
1336 /// By default, performs semantic analysis to build the new statement.
1337 /// Subclasses may override this routine to provide different behavior.
1338 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1339 SourceLocation ColonLoc,
1340 Stmt *Range, Stmt *BeginEnd,
1341 Expr *Cond, Expr *Inc,
1342 Stmt *LoopVar,
1343 SourceLocation RParenLoc) {
Douglas Gregor6f96f4b2013-04-08 18:40:13 +00001344 // If we've just learned that the range is actually an Objective-C
1345 // collection, treat this as an Objective-C fast enumeration loop.
1346 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1347 if (RangeStmt->isSingleDecl()) {
1348 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
1349 Expr *RangeExpr = RangeVar->getInit();
1350 if (!RangeExpr->isTypeDependent() &&
1351 RangeExpr->getType()->isObjCObjectPointerType())
1352 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1353 RParenLoc);
1354 }
1355 }
1356 }
1357
Richard Smithad762fc2011-04-14 22:09:26 +00001358 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001359 Cond, Inc, LoopVar, RParenLoc,
1360 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001361 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001362
1363 /// \brief Build a new C++0x range-based for statement.
1364 ///
1365 /// By default, performs semantic analysis to build the new statement.
1366 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001367 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001368 bool IsIfExists,
1369 NestedNameSpecifierLoc QualifierLoc,
1370 DeclarationNameInfo NameInfo,
1371 Stmt *Nested) {
1372 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1373 QualifierLoc, NameInfo, Nested);
1374 }
1375
Richard Smithad762fc2011-04-14 22:09:26 +00001376 /// \brief Attach body to a C++0x range-based for statement.
1377 ///
1378 /// By default, performs semantic analysis to finish the new statement.
1379 /// Subclasses may override this routine to provide different behavior.
1380 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1381 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1382 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001383
John Wiegley28bbe4b2011-04-28 01:08:34 +00001384 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1385 SourceLocation TryLoc,
1386 Stmt *TryBlock,
1387 Stmt *Handler) {
1388 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1389 }
1390
1391 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1392 Expr *FilterExpr,
1393 Stmt *Block) {
1394 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1395 }
1396
1397 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1398 Stmt *Block) {
1399 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1400 }
1401
Douglas Gregorb98b1992009-08-11 05:31:07 +00001402 /// \brief Build a new expression that references a declaration.
1403 ///
1404 /// By default, performs semantic analysis to build the new expression.
1405 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001406 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001407 LookupResult &R,
1408 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001409 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1410 }
1411
1412
1413 /// \brief Build a new expression that references a declaration.
1414 ///
1415 /// By default, performs semantic analysis to build the new expression.
1416 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001417 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001418 ValueDecl *VD,
1419 const DeclarationNameInfo &NameInfo,
1420 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001421 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001422 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001423
1424 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001425
1426 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001427 }
Mike Stump1eb44332009-09-09 15:08:12 +00001428
Douglas Gregorb98b1992009-08-11 05:31:07 +00001429 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001430 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001431 /// By default, performs semantic analysis to build the new expression.
1432 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001433 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001434 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001435 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001436 }
1437
Douglas Gregora71d8192009-09-04 17:36:40 +00001438 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001439 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001440 /// By default, performs semantic analysis to build the new expression.
1441 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001442 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001443 SourceLocation OperatorLoc,
1444 bool isArrow,
1445 CXXScopeSpec &SS,
1446 TypeSourceInfo *ScopeType,
1447 SourceLocation CCLoc,
1448 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001449 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001450
Douglas Gregorb98b1992009-08-11 05:31:07 +00001451 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001452 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001453 /// By default, performs semantic analysis to build the new expression.
1454 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001455 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001456 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001457 Expr *SubExpr) {
1458 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001459 }
Mike Stump1eb44332009-09-09 15:08:12 +00001460
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001461 /// \brief Build a new builtin offsetof expression.
1462 ///
1463 /// By default, performs semantic analysis to build the new expression.
1464 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001465 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001466 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001467 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001468 unsigned NumComponents,
1469 SourceLocation RParenLoc) {
1470 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1471 NumComponents, RParenLoc);
1472 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001473
1474 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001475 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001476 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001477 /// By default, performs semantic analysis to build the new expression.
1478 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001479 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1480 SourceLocation OpLoc,
1481 UnaryExprOrTypeTrait ExprKind,
1482 SourceRange R) {
1483 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001484 }
1485
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001486 /// \brief Build a new sizeof, alignof or vec step expression with an
1487 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001488 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001489 /// By default, performs semantic analysis to build the new expression.
1490 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001491 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1492 UnaryExprOrTypeTrait ExprKind,
1493 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001494 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001495 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001496 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001497 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001498
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001499 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001500 }
Mike Stump1eb44332009-09-09 15:08:12 +00001501
Douglas Gregorb98b1992009-08-11 05:31:07 +00001502 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001503 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001504 /// By default, performs semantic analysis to build the new expression.
1505 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001506 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001507 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001508 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001509 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001510 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1511 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001512 RBracketLoc);
1513 }
1514
1515 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001516 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001517 /// By default, performs semantic analysis to build the new expression.
1518 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001519 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001520 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001521 SourceLocation RParenLoc,
1522 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001523 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001524 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001525 }
1526
1527 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001528 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001529 /// By default, performs semantic analysis to build the new expression.
1530 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001531 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001532 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001533 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001534 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001535 const DeclarationNameInfo &MemberNameInfo,
1536 ValueDecl *Member,
1537 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001538 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001539 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001540 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1541 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001542 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001543 // We have a reference to an unnamed field. This is always the
1544 // base of an anonymous struct/union member access, i.e. the
1545 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001546 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001547 assert(Member->getType()->isRecordType() &&
1548 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001549
Richard Smith9138b4e2011-10-26 19:06:56 +00001550 BaseResult =
1551 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001552 QualifierLoc.getNestedNameSpecifier(),
1553 FoundDecl, Member);
1554 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001555 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001556 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001557 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001558 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001559 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001560 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001561 cast<FieldDecl>(Member)->getType(),
1562 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001563 return getSema().Owned(ME);
1564 }
Mike Stump1eb44332009-09-09 15:08:12 +00001565
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001566 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001567 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001568
John Wiegley429bb272011-04-08 18:41:53 +00001569 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001570 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001571
John McCall6bb80172010-03-30 21:47:33 +00001572 // FIXME: this involves duplicating earlier analysis in a lot of
1573 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001574 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001575 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001576 R.resolveKind();
1577
John McCall9ae2f072010-08-23 23:25:46 +00001578 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001579 SS, TemplateKWLoc,
1580 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001581 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001582 }
Mike Stump1eb44332009-09-09 15:08:12 +00001583
Douglas Gregorb98b1992009-08-11 05:31:07 +00001584 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001585 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001586 /// By default, performs semantic analysis to build the new expression.
1587 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001588 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001589 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001590 Expr *LHS, Expr *RHS) {
1591 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001592 }
1593
1594 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001595 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001596 /// By default, performs semantic analysis to build the new expression.
1597 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001598 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001599 SourceLocation QuestionLoc,
1600 Expr *LHS,
1601 SourceLocation ColonLoc,
1602 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001603 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1604 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001605 }
1606
Douglas Gregorb98b1992009-08-11 05:31:07 +00001607 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001608 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001609 /// By default, performs semantic analysis to build the new expression.
1610 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001611 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001612 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001613 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001614 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001615 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001616 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001617 }
Mike Stump1eb44332009-09-09 15:08:12 +00001618
Douglas Gregorb98b1992009-08-11 05:31:07 +00001619 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001620 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001621 /// By default, performs semantic analysis to build the new expression.
1622 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001623 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001624 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001625 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001626 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001627 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001628 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001629 }
Mike Stump1eb44332009-09-09 15:08:12 +00001630
Douglas Gregorb98b1992009-08-11 05:31:07 +00001631 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001632 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001633 /// By default, performs semantic analysis to build the new expression.
1634 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001635 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001636 SourceLocation OpLoc,
1637 SourceLocation AccessorLoc,
1638 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001639
John McCall129e2df2009-11-30 22:42:35 +00001640 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001641 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001642 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001643 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001644 SS, SourceLocation(),
1645 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001646 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001647 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001648 }
Mike Stump1eb44332009-09-09 15:08:12 +00001649
Douglas Gregorb98b1992009-08-11 05:31:07 +00001650 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001651 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001652 /// By default, performs semantic analysis to build the new expression.
1653 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001654 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001655 MultiExprArg Inits,
1656 SourceLocation RBraceLoc,
1657 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001658 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001659 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001660 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001661 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001662
Douglas Gregore48319a2009-11-09 17:16:50 +00001663 // Patch in the result type we were given, which may have been computed
1664 // when the initial InitListExpr was built.
1665 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1666 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001667 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001668 }
Mike Stump1eb44332009-09-09 15:08:12 +00001669
Douglas Gregorb98b1992009-08-11 05:31:07 +00001670 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001671 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001672 /// By default, performs semantic analysis to build the new expression.
1673 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001674 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001675 MultiExprArg ArrayExprs,
1676 SourceLocation EqualOrColonLoc,
1677 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001678 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001679 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001680 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001681 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001682 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001683 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001684
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001685 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001686 }
Mike Stump1eb44332009-09-09 15:08:12 +00001687
Douglas Gregorb98b1992009-08-11 05:31:07 +00001688 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001689 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001690 /// By default, builds the implicit value initialization without performing
1691 /// any semantic analysis. Subclasses may override this routine to provide
1692 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001693 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001694 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1695 }
Mike Stump1eb44332009-09-09 15:08:12 +00001696
Douglas Gregorb98b1992009-08-11 05:31:07 +00001697 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001698 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001699 /// By default, performs semantic analysis to build the new expression.
1700 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001701 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001702 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001703 SourceLocation RParenLoc) {
1704 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001705 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001706 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001707 }
1708
1709 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001710 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001711 /// By default, performs semantic analysis to build the new expression.
1712 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001713 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001714 MultiExprArg SubExprs,
1715 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001716 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001717 }
Mike Stump1eb44332009-09-09 15:08:12 +00001718
Douglas Gregorb98b1992009-08-11 05:31:07 +00001719 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001720 ///
1721 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001722 /// rather than attempting to map the label statement itself.
1723 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001724 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001725 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001726 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001727 }
Mike Stump1eb44332009-09-09 15:08:12 +00001728
Douglas Gregorb98b1992009-08-11 05:31:07 +00001729 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001730 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001731 /// By default, performs semantic analysis to build the new expression.
1732 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001733 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001734 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001735 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001736 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001737 }
Mike Stump1eb44332009-09-09 15:08:12 +00001738
Douglas Gregorb98b1992009-08-11 05:31:07 +00001739 /// \brief Build a new __builtin_choose_expr expression.
1740 ///
1741 /// By default, performs semantic analysis to build the new expression.
1742 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001743 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001744 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001745 SourceLocation RParenLoc) {
1746 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001747 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001748 RParenLoc);
1749 }
Mike Stump1eb44332009-09-09 15:08:12 +00001750
Peter Collingbournef111d932011-04-15 00:35:48 +00001751 /// \brief Build a new generic selection expression.
1752 ///
1753 /// By default, performs semantic analysis to build the new expression.
1754 /// Subclasses may override this routine to provide different behavior.
1755 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1756 SourceLocation DefaultLoc,
1757 SourceLocation RParenLoc,
1758 Expr *ControllingExpr,
1759 TypeSourceInfo **Types,
1760 Expr **Exprs,
1761 unsigned NumAssocs) {
1762 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1763 ControllingExpr, Types, Exprs,
1764 NumAssocs);
1765 }
1766
Douglas Gregorb98b1992009-08-11 05:31:07 +00001767 /// \brief Build a new overloaded operator call expression.
1768 ///
1769 /// By default, performs semantic analysis to build the new expression.
1770 /// The semantic analysis provides the behavior of template instantiation,
1771 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001772 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001773 /// argument-dependent lookup, etc. Subclasses may override this routine to
1774 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001775 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001776 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001777 Expr *Callee,
1778 Expr *First,
1779 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001780
1781 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001782 /// reinterpret_cast.
1783 ///
1784 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001785 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001786 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001787 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001788 Stmt::StmtClass Class,
1789 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001790 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791 SourceLocation RAngleLoc,
1792 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001793 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001794 SourceLocation RParenLoc) {
1795 switch (Class) {
1796 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001797 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001798 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001799 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001800
1801 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001802 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001803 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001804 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001805
Douglas Gregorb98b1992009-08-11 05:31:07 +00001806 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001807 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001808 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001809 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001810 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001811
Douglas Gregorb98b1992009-08-11 05:31:07 +00001812 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001813 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001814 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001815 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001816
Douglas Gregorb98b1992009-08-11 05:31:07 +00001817 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001818 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001819 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001820 }
Mike Stump1eb44332009-09-09 15:08:12 +00001821
Douglas Gregorb98b1992009-08-11 05:31:07 +00001822 /// \brief Build a new C++ static_cast expression.
1823 ///
1824 /// By default, performs semantic analysis to build the new expression.
1825 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001826 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001827 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001828 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001829 SourceLocation RAngleLoc,
1830 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001831 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001832 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001833 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001834 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001835 SourceRange(LAngleLoc, RAngleLoc),
1836 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001837 }
1838
1839 /// \brief Build a new C++ dynamic_cast expression.
1840 ///
1841 /// By default, performs semantic analysis to build the new expression.
1842 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001843 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001844 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001845 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001846 SourceLocation RAngleLoc,
1847 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001848 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001849 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001850 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001851 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001852 SourceRange(LAngleLoc, RAngleLoc),
1853 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001854 }
1855
1856 /// \brief Build a new C++ reinterpret_cast expression.
1857 ///
1858 /// By default, performs semantic analysis to build the new expression.
1859 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001860 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001861 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001862 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001863 SourceLocation RAngleLoc,
1864 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001865 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001866 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001867 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001868 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001869 SourceRange(LAngleLoc, RAngleLoc),
1870 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001871 }
1872
1873 /// \brief Build a new C++ const_cast expression.
1874 ///
1875 /// By default, performs semantic analysis to build the new expression.
1876 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001877 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001878 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001879 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001880 SourceLocation RAngleLoc,
1881 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001882 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001883 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001884 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001885 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001886 SourceRange(LAngleLoc, RAngleLoc),
1887 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001888 }
Mike Stump1eb44332009-09-09 15:08:12 +00001889
Douglas Gregorb98b1992009-08-11 05:31:07 +00001890 /// \brief Build a new C++ functional-style cast expression.
1891 ///
1892 /// By default, performs semantic analysis to build the new expression.
1893 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001894 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1895 SourceLocation LParenLoc,
1896 Expr *Sub,
1897 SourceLocation RParenLoc) {
1898 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001899 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001900 RParenLoc);
1901 }
Mike Stump1eb44332009-09-09 15:08:12 +00001902
Douglas Gregorb98b1992009-08-11 05:31:07 +00001903 /// \brief Build a new C++ typeid(type) expression.
1904 ///
1905 /// By default, performs semantic analysis to build the new expression.
1906 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001907 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001908 SourceLocation TypeidLoc,
1909 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001910 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001911 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001912 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001913 }
Mike Stump1eb44332009-09-09 15:08:12 +00001914
Francois Pichet01b7c302010-09-08 12:20:18 +00001915
Douglas Gregorb98b1992009-08-11 05:31:07 +00001916 /// \brief Build a new C++ typeid(expr) expression.
1917 ///
1918 /// By default, performs semantic analysis to build the new expression.
1919 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001920 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001921 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001922 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001923 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001924 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001925 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001926 }
1927
Francois Pichet01b7c302010-09-08 12:20:18 +00001928 /// \brief Build a new C++ __uuidof(type) expression.
1929 ///
1930 /// By default, performs semantic analysis to build the new expression.
1931 /// Subclasses may override this routine to provide different behavior.
1932 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1933 SourceLocation TypeidLoc,
1934 TypeSourceInfo *Operand,
1935 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001936 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00001937 RParenLoc);
1938 }
1939
1940 /// \brief Build a new C++ __uuidof(expr) expression.
1941 ///
1942 /// By default, performs semantic analysis to build the new expression.
1943 /// Subclasses may override this routine to provide different behavior.
1944 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1945 SourceLocation TypeidLoc,
1946 Expr *Operand,
1947 SourceLocation RParenLoc) {
1948 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1949 RParenLoc);
1950 }
1951
Douglas Gregorb98b1992009-08-11 05:31:07 +00001952 /// \brief Build a new C++ "this" expression.
1953 ///
1954 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001955 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001956 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001957 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001958 QualType ThisType,
1959 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001960 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001961 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001962 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1963 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001964 }
1965
1966 /// \brief Build a new C++ throw expression.
1967 ///
1968 /// By default, performs semantic analysis to build the new expression.
1969 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001970 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1971 bool IsThrownVariableInScope) {
1972 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001973 }
1974
1975 /// \brief Build a new C++ default-argument expression.
1976 ///
1977 /// By default, builds a new default-argument expression, which does not
1978 /// require any semantic analysis. Subclasses may override this routine to
1979 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001980 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001981 ParmVarDecl *Param) {
1982 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1983 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001984 }
1985
Richard Smithc3bf52c2013-04-20 22:23:05 +00001986 /// \brief Build a new C++11 default-initialization expression.
1987 ///
1988 /// By default, builds a new default field initialization expression, which
1989 /// does not require any semantic analysis. Subclasses may override this
1990 /// routine to provide different behavior.
1991 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
1992 FieldDecl *Field) {
1993 return getSema().Owned(CXXDefaultInitExpr::Create(getSema().Context, Loc,
1994 Field));
1995 }
1996
Douglas Gregorb98b1992009-08-11 05:31:07 +00001997 /// \brief Build a new C++ zero-initialization expression.
1998 ///
1999 /// By default, performs semantic analysis to build the new expression.
2000 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002001 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2002 SourceLocation LParenLoc,
2003 SourceLocation RParenLoc) {
2004 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Benjamin Kramer5354e772012-08-23 23:38:35 +00002005 MultiExprArg(), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002006 }
Mike Stump1eb44332009-09-09 15:08:12 +00002007
Douglas Gregorb98b1992009-08-11 05:31:07 +00002008 /// \brief Build a new C++ "new" expression.
2009 ///
2010 /// By default, performs semantic analysis to build the new expression.
2011 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002012 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002013 bool UseGlobal,
2014 SourceLocation PlacementLParen,
2015 MultiExprArg PlacementArgs,
2016 SourceLocation PlacementRParen,
2017 SourceRange TypeIdParens,
2018 QualType AllocatedType,
2019 TypeSourceInfo *AllocatedTypeInfo,
2020 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002021 SourceRange DirectInitRange,
2022 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00002023 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002024 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002025 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002026 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002027 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002028 AllocatedType,
2029 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002030 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002031 DirectInitRange,
2032 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002033 }
Mike Stump1eb44332009-09-09 15:08:12 +00002034
Douglas Gregorb98b1992009-08-11 05:31:07 +00002035 /// \brief Build a new C++ "delete" expression.
2036 ///
2037 /// By default, performs semantic analysis to build the new expression.
2038 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002039 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002040 bool IsGlobalDelete,
2041 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002042 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002043 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002044 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002045 }
Mike Stump1eb44332009-09-09 15:08:12 +00002046
Douglas Gregorb98b1992009-08-11 05:31:07 +00002047 /// \brief Build a new unary type trait expression.
2048 ///
2049 /// By default, performs semantic analysis to build the new expression.
2050 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002051 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002052 SourceLocation StartLoc,
2053 TypeSourceInfo *T,
2054 SourceLocation RParenLoc) {
2055 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002056 }
2057
Francois Pichet6ad6f282010-12-07 00:08:36 +00002058 /// \brief Build a new binary type trait expression.
2059 ///
2060 /// By default, performs semantic analysis to build the new expression.
2061 /// Subclasses may override this routine to provide different behavior.
2062 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2063 SourceLocation StartLoc,
2064 TypeSourceInfo *LhsT,
2065 TypeSourceInfo *RhsT,
2066 SourceLocation RParenLoc) {
2067 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2068 }
2069
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002070 /// \brief Build a new type trait expression.
2071 ///
2072 /// By default, performs semantic analysis to build the new expression.
2073 /// Subclasses may override this routine to provide different behavior.
2074 ExprResult RebuildTypeTrait(TypeTrait Trait,
2075 SourceLocation StartLoc,
2076 ArrayRef<TypeSourceInfo *> Args,
2077 SourceLocation RParenLoc) {
2078 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2079 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002080
John Wiegley21ff2e52011-04-28 00:16:57 +00002081 /// \brief Build a new array type trait expression.
2082 ///
2083 /// By default, performs semantic analysis to build the new expression.
2084 /// Subclasses may override this routine to provide different behavior.
2085 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2086 SourceLocation StartLoc,
2087 TypeSourceInfo *TSInfo,
2088 Expr *DimExpr,
2089 SourceLocation RParenLoc) {
2090 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2091 }
2092
John Wiegley55262202011-04-25 06:54:41 +00002093 /// \brief Build a new expression trait expression.
2094 ///
2095 /// By default, performs semantic analysis to build the new expression.
2096 /// Subclasses may override this routine to provide different behavior.
2097 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2098 SourceLocation StartLoc,
2099 Expr *Queried,
2100 SourceLocation RParenLoc) {
2101 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2102 }
2103
Mike Stump1eb44332009-09-09 15:08:12 +00002104 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002105 /// expression.
2106 ///
2107 /// By default, performs semantic analysis to build the new expression.
2108 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002109 ExprResult RebuildDependentScopeDeclRefExpr(
2110 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002111 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002112 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002113 const TemplateArgumentListInfo *TemplateArgs,
2114 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002115 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002116 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002117
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002118 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002119 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002120 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002121
Richard Smithefeeccf2012-10-21 03:28:35 +00002122 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2123 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002124 }
2125
2126 /// \brief Build a new template-id expression.
2127 ///
2128 /// By default, performs semantic analysis to build the new expression.
2129 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002130 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002131 SourceLocation TemplateKWLoc,
2132 LookupResult &R,
2133 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002134 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002135 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2136 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002137 }
2138
2139 /// \brief Build a new object-construction expression.
2140 ///
2141 /// By default, performs semantic analysis to build the new expression.
2142 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002143 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002144 SourceLocation Loc,
2145 CXXConstructorDecl *Constructor,
2146 bool IsElidable,
2147 MultiExprArg Args,
2148 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002149 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002150 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002151 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002152 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002153 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002154 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002155 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002156 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002157
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002158 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002159 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002160 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002161 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002162 RequiresZeroInit, ConstructKind,
2163 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002164 }
2165
2166 /// \brief Build a new object-construction expression.
2167 ///
2168 /// By default, performs semantic analysis to build the new expression.
2169 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002170 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2171 SourceLocation LParenLoc,
2172 MultiExprArg Args,
2173 SourceLocation RParenLoc) {
2174 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002175 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002176 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002177 RParenLoc);
2178 }
2179
2180 /// \brief Build a new object-construction expression.
2181 ///
2182 /// By default, performs semantic analysis to build the new expression.
2183 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002184 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2185 SourceLocation LParenLoc,
2186 MultiExprArg Args,
2187 SourceLocation RParenLoc) {
2188 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002189 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002190 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002191 RParenLoc);
2192 }
Mike Stump1eb44332009-09-09 15:08:12 +00002193
Douglas Gregorb98b1992009-08-11 05:31:07 +00002194 /// \brief Build a new member reference expression.
2195 ///
2196 /// By default, performs semantic analysis to build the new expression.
2197 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002198 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002199 QualType BaseType,
2200 bool IsArrow,
2201 SourceLocation OperatorLoc,
2202 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002203 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002204 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002205 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002206 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002207 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002208 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002209
John McCall9ae2f072010-08-23 23:25:46 +00002210 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002211 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002212 SS, TemplateKWLoc,
2213 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002214 MemberNameInfo,
2215 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002216 }
2217
John McCall129e2df2009-11-30 22:42:35 +00002218 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002219 ///
2220 /// By default, performs semantic analysis to build the new expression.
2221 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002222 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2223 SourceLocation OperatorLoc,
2224 bool IsArrow,
2225 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002226 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002227 NamedDecl *FirstQualifierInScope,
2228 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002229 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002230 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002231 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002232
John McCall9ae2f072010-08-23 23:25:46 +00002233 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002234 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002235 SS, TemplateKWLoc,
2236 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002237 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002238 }
Mike Stump1eb44332009-09-09 15:08:12 +00002239
Sebastian Redl2e156222010-09-10 20:55:43 +00002240 /// \brief Build a new noexcept expression.
2241 ///
2242 /// By default, performs semantic analysis to build the new expression.
2243 /// Subclasses may override this routine to provide different behavior.
2244 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2245 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2246 }
2247
Douglas Gregoree8aff02011-01-04 17:33:58 +00002248 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002249 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2250 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002251 SourceLocation RParenLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002252 Optional<unsigned> Length) {
Douglas Gregor089e8932011-10-10 18:59:29 +00002253 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002254 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2255 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002256 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002257
2258 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2259 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002260 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002261 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002262
Patrick Beardeb382ec2012-04-19 00:25:12 +00002263 /// \brief Build a new Objective-C boxed expression.
2264 ///
2265 /// By default, performs semantic analysis to build the new expression.
2266 /// Subclasses may override this routine to provide different behavior.
2267 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2268 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2269 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002270
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002271 /// \brief Build a new Objective-C array literal.
2272 ///
2273 /// By default, performs semantic analysis to build the new expression.
2274 /// Subclasses may override this routine to provide different behavior.
2275 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2276 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002277 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002278 MultiExprArg(Elements, NumElements));
2279 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002280
2281 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002282 Expr *Base, Expr *Key,
2283 ObjCMethodDecl *getterMethod,
2284 ObjCMethodDecl *setterMethod) {
2285 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2286 getterMethod, setterMethod);
2287 }
2288
2289 /// \brief Build a new Objective-C dictionary literal.
2290 ///
2291 /// By default, performs semantic analysis to build the new expression.
2292 /// Subclasses may override this routine to provide different behavior.
2293 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2294 ObjCDictionaryElement *Elements,
2295 unsigned NumElements) {
2296 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2297 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002298
James Dennett699c9042012-06-15 07:13:21 +00002299 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002300 ///
2301 /// By default, performs semantic analysis to build the new expression.
2302 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002303 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002304 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002305 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002306 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002307 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002308 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002309
Douglas Gregor92e986e2010-04-22 16:44:27 +00002310 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002311 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002312 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002313 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002314 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002315 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002316 MultiExprArg Args,
2317 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002318 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2319 ReceiverTypeInfo->getType(),
2320 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002321 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002322 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002323 }
2324
2325 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002326 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002327 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002328 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002329 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002330 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002331 MultiExprArg Args,
2332 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002333 return SemaRef.BuildInstanceMessage(Receiver,
2334 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002335 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002336 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002337 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002338 }
2339
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002340 /// \brief Build a new Objective-C ivar reference expression.
2341 ///
2342 /// By default, performs semantic analysis to build the new expression.
2343 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002344 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002345 SourceLocation IvarLoc,
2346 bool IsArrow, bool IsFreeIvar) {
2347 // FIXME: We lose track of the IsFreeIvar bit.
2348 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002349 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002350 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2351 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002352 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002353 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002354 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002355 false);
John Wiegley429bb272011-04-08 18:41:53 +00002356 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002357 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002358
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002359 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002360 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002361
John Wiegley429bb272011-04-08 18:41:53 +00002362 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002363 /*FIXME:*/IvarLoc, IsArrow,
2364 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002365 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002366 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002367 /*TemplateArgs=*/0);
2368 }
Douglas Gregore3303542010-04-26 20:47:02 +00002369
2370 /// \brief Build a new Objective-C property reference expression.
2371 ///
2372 /// By default, performs semantic analysis to build the new expression.
2373 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002374 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002375 ObjCPropertyDecl *Property,
2376 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002377 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002378 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002379 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2380 Sema::LookupMemberName);
2381 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002382 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002383 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002384 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002385 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002386 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002387
Douglas Gregore3303542010-04-26 20:47:02 +00002388 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002389 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002390
John Wiegley429bb272011-04-08 18:41:53 +00002391 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002392 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002393 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002394 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002395 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002396 /*TemplateArgs=*/0);
2397 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002398
John McCall12f78a62010-12-02 01:19:52 +00002399 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002400 ///
2401 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002402 /// Subclasses may override this routine to provide different behavior.
2403 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2404 ObjCMethodDecl *Getter,
2405 ObjCMethodDecl *Setter,
2406 SourceLocation PropertyLoc) {
2407 // Since these expressions can only be value-dependent, we do not
2408 // need to perform semantic analysis again.
2409 return Owned(
2410 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2411 VK_LValue, OK_ObjCProperty,
2412 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002413 }
2414
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002415 /// \brief Build a new Objective-C "isa" expression.
2416 ///
2417 /// By default, performs semantic analysis to build the new expression.
2418 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002419 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002420 SourceLocation OpLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002421 bool IsArrow) {
2422 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002423 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002424 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2425 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002426 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002427 OpLoc,
John McCalld226f652010-08-21 09:40:31 +00002428 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002429 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002430 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002431
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002432 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002433 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002434
John Wiegley429bb272011-04-08 18:41:53 +00002435 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002436 OpLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002437 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002438 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002439 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002440 /*TemplateArgs=*/0);
2441 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002442
Douglas Gregorb98b1992009-08-11 05:31:07 +00002443 /// \brief Build a new shuffle vector expression.
2444 ///
2445 /// By default, performs semantic analysis to build the new expression.
2446 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002447 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002448 MultiExprArg SubExprs,
2449 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002450 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002451 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002452 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2453 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2454 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002455 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002456
Douglas Gregorb98b1992009-08-11 05:31:07 +00002457 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002458 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002459 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2460 SemaRef.Context.BuiltinFnTy,
2461 VK_RValue, BuiltinLoc);
2462 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2463 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2464 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002465
2466 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002467 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002468 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002469 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002470 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002471 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002472
Douglas Gregorb98b1992009-08-11 05:31:07 +00002473 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002474 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002475 }
John McCall43fed0d2010-11-12 08:19:04 +00002476
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002477 /// \brief Build a new template argument pack expansion.
2478 ///
2479 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002480 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002481 /// different behavior.
2482 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002483 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002484 Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002485 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002486 case TemplateArgument::Expression: {
2487 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002488 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2489 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002490 if (Result.isInvalid())
2491 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002492
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002493 return TemplateArgumentLoc(Result.get(), Result.get());
2494 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002495
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002496 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002497 return TemplateArgumentLoc(TemplateArgument(
2498 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002499 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002500 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002501 Pattern.getTemplateNameLoc(),
2502 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002503
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002504 case TemplateArgument::Null:
2505 case TemplateArgument::Integral:
2506 case TemplateArgument::Declaration:
2507 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002508 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002509 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002510 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002511
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002512 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002513 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002514 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002515 EllipsisLoc,
2516 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002517 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2518 Expansion);
2519 break;
2520 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002521
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002522 return TemplateArgumentLoc();
2523 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002524
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002525 /// \brief Build a new expression pack expansion.
2526 ///
2527 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002528 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002529 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002530 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002531 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002532 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002533 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002534
2535 /// \brief Build a new atomic operation expression.
2536 ///
2537 /// By default, performs semantic analysis to build the new expression.
2538 /// Subclasses may override this routine to provide different behavior.
2539 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2540 MultiExprArg SubExprs,
2541 QualType RetTy,
2542 AtomicExpr::AtomicOp Op,
2543 SourceLocation RParenLoc) {
2544 // Just create the expression; there is not any interesting semantic
2545 // analysis here because we can't actually build an AtomicExpr until
2546 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002547 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002548 RParenLoc);
2549 }
2550
John McCall43fed0d2010-11-12 08:19:04 +00002551private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002552 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2553 QualType ObjectType,
2554 NamedDecl *FirstQualifierInScope,
2555 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002556
2557 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2558 QualType ObjectType,
2559 NamedDecl *FirstQualifierInScope,
2560 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002561};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002562
Douglas Gregor43959a92009-08-20 07:17:43 +00002563template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002564StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002565 if (!S)
2566 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002567
Douglas Gregor43959a92009-08-20 07:17:43 +00002568 switch (S->getStmtClass()) {
2569 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002570
Douglas Gregor43959a92009-08-20 07:17:43 +00002571 // Transform individual statement nodes
2572#define STMT(Node, Parent) \
2573 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002574#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002575#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002576#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002577
Douglas Gregor43959a92009-08-20 07:17:43 +00002578 // Transform expressions by calling TransformExpr.
2579#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002580#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002581#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002582#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002583 {
John McCall60d7b3a2010-08-24 06:29:42 +00002584 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002585 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002586 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002587
Richard Smith41956372013-01-14 22:39:08 +00002588 return getSema().ActOnExprStmt(E);
Douglas Gregor43959a92009-08-20 07:17:43 +00002589 }
Mike Stump1eb44332009-09-09 15:08:12 +00002590 }
2591
John McCall3fa5cae2010-10-26 07:05:15 +00002592 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002593}
Mike Stump1eb44332009-09-09 15:08:12 +00002594
2595
Douglas Gregor670444e2009-08-04 22:27:00 +00002596template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002597ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002598 if (!E)
2599 return SemaRef.Owned(E);
2600
2601 switch (E->getStmtClass()) {
2602 case Stmt::NoStmtClass: break;
2603#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002604#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002605#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002606 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002607#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002608 }
2609
John McCall3fa5cae2010-10-26 07:05:15 +00002610 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002611}
2612
2613template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002614ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2615 bool CXXDirectInit) {
2616 // Initializers are instantiated like expressions, except that various outer
2617 // layers are stripped.
2618 if (!Init)
2619 return SemaRef.Owned(Init);
2620
2621 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2622 Init = ExprTemp->getSubExpr();
2623
2624 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2625 Init = Binder->getSubExpr();
2626
2627 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2628 Init = ICE->getSubExprAsWritten();
2629
Richard Smith5cf15892012-12-21 08:13:35 +00002630 // If this is not a direct-initializer, we only need to reconstruct
2631 // InitListExprs. Other forms of copy-initialization will be a no-op if
2632 // the initializer is already the right type.
2633 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2634 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2635 return getDerived().TransformExpr(Init);
2636
2637 // Revert value-initialization back to empty parens.
2638 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2639 SourceRange Parens = VIE->getSourceRange();
2640 return getDerived().RebuildParenListExpr(Parens.getBegin(), MultiExprArg(),
2641 Parens.getEnd());
2642 }
2643
2644 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2645 if (isa<ImplicitValueInitExpr>(Init))
2646 return getDerived().RebuildParenListExpr(SourceLocation(), MultiExprArg(),
2647 SourceLocation());
2648
2649 // Revert initialization by constructor back to a parenthesized or braced list
2650 // of expressions. Any other form of initializer can just be reused directly.
2651 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002652 return getDerived().TransformExpr(Init);
2653
2654 SmallVector<Expr*, 8> NewArgs;
2655 bool ArgChanged = false;
2656 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2657 /*IsCall*/true, NewArgs, &ArgChanged))
2658 return ExprError();
2659
2660 // If this was list initialization, revert to list form.
2661 if (Construct->isListInitialization())
2662 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2663 Construct->getLocEnd(),
2664 Construct->getType());
2665
Richard Smithc83c2302012-12-19 01:39:02 +00002666 // Build a ParenListExpr to represent anything else.
2667 SourceRange Parens = Construct->getParenRange();
2668 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2669 Parens.getEnd());
2670}
2671
2672template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002673bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2674 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002675 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002676 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002677 bool *ArgChanged) {
2678 for (unsigned I = 0; I != NumInputs; ++I) {
2679 // If requested, drop call arguments that need to be dropped.
2680 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2681 if (ArgChanged)
2682 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002683
Douglas Gregoraa165f82011-01-03 19:04:46 +00002684 break;
2685 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002686
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002687 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2688 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002689
Chris Lattner686775d2011-07-20 06:58:45 +00002690 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002691 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2692 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002693
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002694 // Determine whether the set of unexpanded parameter packs can and should
2695 // be expanded.
2696 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002697 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00002698 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2699 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002700 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2701 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002702 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002703 Expand, RetainExpansion,
2704 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002705 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002706
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002707 if (!Expand) {
2708 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002709 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002710 // expansion.
2711 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2712 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2713 if (OutPattern.isInvalid())
2714 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002715
2716 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002717 Expansion->getEllipsisLoc(),
2718 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002719 if (Out.isInvalid())
2720 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002721
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002722 if (ArgChanged)
2723 *ArgChanged = true;
2724 Outputs.push_back(Out.get());
2725 continue;
2726 }
John McCallc8fc90a2011-07-06 07:30:07 +00002727
2728 // Record right away that the argument was changed. This needs
2729 // to happen even if the array expands to nothing.
2730 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002731
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002732 // The transform has determined that we should perform an elementwise
2733 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002734 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002735 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2736 ExprResult Out = getDerived().TransformExpr(Pattern);
2737 if (Out.isInvalid())
2738 return true;
2739
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002740 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002741 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2742 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002743 if (Out.isInvalid())
2744 return true;
2745 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002746
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002747 Outputs.push_back(Out.get());
2748 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002749
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002750 continue;
2751 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002752
Richard Smithc83c2302012-12-19 01:39:02 +00002753 ExprResult Result =
2754 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2755 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002756 if (Result.isInvalid())
2757 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002758
Douglas Gregoraa165f82011-01-03 19:04:46 +00002759 if (Result.get() != Inputs[I] && ArgChanged)
2760 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002761
2762 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002763 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002764
Douglas Gregoraa165f82011-01-03 19:04:46 +00002765 return false;
2766}
2767
2768template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002769NestedNameSpecifierLoc
2770TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2771 NestedNameSpecifierLoc NNS,
2772 QualType ObjectType,
2773 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002774 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002775 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002776 Qualifier = Qualifier.getPrefix())
2777 Qualifiers.push_back(Qualifier);
2778
2779 CXXScopeSpec SS;
2780 while (!Qualifiers.empty()) {
2781 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2782 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002783
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002784 switch (QNNS->getKind()) {
2785 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002786 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002787 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002788 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002789 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002790 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002791 FirstQualifierInScope, false))
2792 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002793
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002794 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002795
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002796 case NestedNameSpecifier::Namespace: {
2797 NamespaceDecl *NS
2798 = cast_or_null<NamespaceDecl>(
2799 getDerived().TransformDecl(
2800 Q.getLocalBeginLoc(),
2801 QNNS->getAsNamespace()));
2802 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2803 break;
2804 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002805
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002806 case NestedNameSpecifier::NamespaceAlias: {
2807 NamespaceAliasDecl *Alias
2808 = cast_or_null<NamespaceAliasDecl>(
2809 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2810 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002811 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002812 Q.getLocalEndLoc());
2813 break;
2814 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002815
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002816 case NestedNameSpecifier::Global:
2817 // There is no meaningful transformation that one could perform on the
2818 // global scope.
2819 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2820 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002821
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002822 case NestedNameSpecifier::TypeSpecWithTemplate:
2823 case NestedNameSpecifier::TypeSpec: {
2824 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2825 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002826
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002827 if (!TL)
2828 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002829
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002830 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002831 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002832 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002833 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002834 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002835 if (TL.getType()->isEnumeralType())
2836 SemaRef.Diag(TL.getBeginLoc(),
2837 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002838 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2839 Q.getLocalEndLoc());
2840 break;
2841 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002842 // If the nested-name-specifier is an invalid type def, don't emit an
2843 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002844 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2845 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002846 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002847 << TL.getType() << SS.getRange();
2848 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002849 return NestedNameSpecifierLoc();
2850 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002851 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002852
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002853 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002854 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002855 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002856 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002857
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002858 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002859 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002860 !getDerived().AlwaysRebuild())
2861 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002862
2863 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002864 // nested-name-specifier, do so.
2865 if (SS.location_size() == NNS.getDataLength() &&
2866 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2867 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2868
2869 // Allocate new nested-name-specifier location information.
2870 return SS.getWithLocInContext(SemaRef.Context);
2871}
2872
2873template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002874DeclarationNameInfo
2875TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002876::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002877 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002878 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002879 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002880
2881 switch (Name.getNameKind()) {
2882 case DeclarationName::Identifier:
2883 case DeclarationName::ObjCZeroArgSelector:
2884 case DeclarationName::ObjCOneArgSelector:
2885 case DeclarationName::ObjCMultiArgSelector:
2886 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002887 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002888 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002889 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002890
Douglas Gregor81499bb2009-09-03 22:13:48 +00002891 case DeclarationName::CXXConstructorName:
2892 case DeclarationName::CXXDestructorName:
2893 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002894 TypeSourceInfo *NewTInfo;
2895 CanQualType NewCanTy;
2896 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002897 NewTInfo = getDerived().TransformType(OldTInfo);
2898 if (!NewTInfo)
2899 return DeclarationNameInfo();
2900 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002901 }
2902 else {
2903 NewTInfo = 0;
2904 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002905 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002906 if (NewT.isNull())
2907 return DeclarationNameInfo();
2908 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2909 }
Mike Stump1eb44332009-09-09 15:08:12 +00002910
Abramo Bagnara25777432010-08-11 22:01:17 +00002911 DeclarationName NewName
2912 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2913 NewCanTy);
2914 DeclarationNameInfo NewNameInfo(NameInfo);
2915 NewNameInfo.setName(NewName);
2916 NewNameInfo.setNamedTypeInfo(NewTInfo);
2917 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002918 }
Mike Stump1eb44332009-09-09 15:08:12 +00002919 }
2920
David Blaikieb219cfc2011-09-23 05:06:16 +00002921 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002922}
2923
2924template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002925TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002926TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2927 TemplateName Name,
2928 SourceLocation NameLoc,
2929 QualType ObjectType,
2930 NamedDecl *FirstQualifierInScope) {
2931 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2932 TemplateDecl *Template = QTN->getTemplateDecl();
2933 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002934
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002935 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002936 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002937 Template));
2938 if (!TransTemplate)
2939 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002940
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002941 if (!getDerived().AlwaysRebuild() &&
2942 SS.getScopeRep() == QTN->getQualifier() &&
2943 TransTemplate == Template)
2944 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002945
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002946 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2947 TransTemplate);
2948 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002949
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002950 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2951 if (SS.getScopeRep()) {
2952 // These apply to the scope specifier, not the template.
2953 ObjectType = QualType();
2954 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002955 }
2956
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002957 if (!getDerived().AlwaysRebuild() &&
2958 SS.getScopeRep() == DTN->getQualifier() &&
2959 ObjectType.isNull())
2960 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002961
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002962 if (DTN->isIdentifier()) {
2963 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002964 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002965 NameLoc,
2966 ObjectType,
2967 FirstQualifierInScope);
2968 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002969
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002970 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2971 ObjectType);
2972 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002973
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002974 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2975 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002976 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002977 Template));
2978 if (!TransTemplate)
2979 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002980
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002981 if (!getDerived().AlwaysRebuild() &&
2982 TransTemplate == Template)
2983 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002984
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002985 return TemplateName(TransTemplate);
2986 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002987
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002988 if (SubstTemplateTemplateParmPackStorage *SubstPack
2989 = Name.getAsSubstTemplateTemplateParmPack()) {
2990 TemplateTemplateParmDecl *TransParam
2991 = cast_or_null<TemplateTemplateParmDecl>(
2992 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2993 if (!TransParam)
2994 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002995
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002996 if (!getDerived().AlwaysRebuild() &&
2997 TransParam == SubstPack->getParameterPack())
2998 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002999
3000 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003001 SubstPack->getArgumentPack());
3002 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003003
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003004 // These should be getting filtered out before they reach the AST.
3005 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003006}
3007
3008template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003009void TreeTransform<Derived>::InventTemplateArgumentLoc(
3010 const TemplateArgument &Arg,
3011 TemplateArgumentLoc &Output) {
3012 SourceLocation Loc = getDerived().getBaseLocation();
3013 switch (Arg.getKind()) {
3014 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003015 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00003016 break;
3017
3018 case TemplateArgument::Type:
3019 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00003020 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00003021
John McCall833ca992009-10-29 08:12:44 +00003022 break;
3023
Douglas Gregor788cd062009-11-11 01:00:40 +00003024 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003025 case TemplateArgument::TemplateExpansion: {
3026 NestedNameSpecifierLocBuilder Builder;
3027 TemplateName Template = Arg.getAsTemplate();
3028 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3029 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3030 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3031 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003032
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003033 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003034 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003035 Builder.getWithLocInContext(SemaRef.Context),
3036 Loc);
3037 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003038 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003039 Builder.getWithLocInContext(SemaRef.Context),
3040 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003041
Douglas Gregor788cd062009-11-11 01:00:40 +00003042 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003043 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003044
John McCall833ca992009-10-29 08:12:44 +00003045 case TemplateArgument::Expression:
3046 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3047 break;
3048
3049 case TemplateArgument::Declaration:
3050 case TemplateArgument::Integral:
3051 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003052 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003053 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003054 break;
3055 }
3056}
3057
3058template<typename Derived>
3059bool TreeTransform<Derived>::TransformTemplateArgument(
3060 const TemplateArgumentLoc &Input,
3061 TemplateArgumentLoc &Output) {
3062 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003063 switch (Arg.getKind()) {
3064 case TemplateArgument::Null:
3065 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003066 case TemplateArgument::Pack:
3067 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003068 case TemplateArgument::NullPtr:
3069 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003070
Douglas Gregor670444e2009-08-04 22:27:00 +00003071 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003072 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003073 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003074 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003075
3076 DI = getDerived().TransformType(DI);
3077 if (!DI) return true;
3078
3079 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3080 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003081 }
Mike Stump1eb44332009-09-09 15:08:12 +00003082
Douglas Gregor788cd062009-11-11 01:00:40 +00003083 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003084 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3085 if (QualifierLoc) {
3086 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3087 if (!QualifierLoc)
3088 return true;
3089 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003090
Douglas Gregor1d752d72011-03-02 18:46:51 +00003091 CXXScopeSpec SS;
3092 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003093 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003094 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3095 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003096 if (Template.isNull())
3097 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003098
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003099 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003100 Input.getTemplateNameLoc());
3101 return false;
3102 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003103
3104 case TemplateArgument::TemplateExpansion:
3105 llvm_unreachable("Caller should expand pack expansions");
3106
Douglas Gregor670444e2009-08-04 22:27:00 +00003107 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003108 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003109 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003110 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003111
John McCall833ca992009-10-29 08:12:44 +00003112 Expr *InputExpr = Input.getSourceExpression();
3113 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3114
Chris Lattner223de242011-04-25 20:37:58 +00003115 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003116 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003117 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003118 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003119 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003120 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003121 }
Mike Stump1eb44332009-09-09 15:08:12 +00003122
Douglas Gregor670444e2009-08-04 22:27:00 +00003123 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003124 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003125}
3126
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003127/// \brief Iterator adaptor that invents template argument location information
3128/// for each of the template arguments in its underlying iterator.
3129template<typename Derived, typename InputIterator>
3130class TemplateArgumentLocInventIterator {
3131 TreeTransform<Derived> &Self;
3132 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003133
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003134public:
3135 typedef TemplateArgumentLoc value_type;
3136 typedef TemplateArgumentLoc reference;
3137 typedef typename std::iterator_traits<InputIterator>::difference_type
3138 difference_type;
3139 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003140
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003141 class pointer {
3142 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003143
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003144 public:
3145 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003146
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003147 const TemplateArgumentLoc *operator->() const { return &Arg; }
3148 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003149
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003150 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003151
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003152 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3153 InputIterator Iter)
3154 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003155
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003156 TemplateArgumentLocInventIterator &operator++() {
3157 ++Iter;
3158 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003159 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003160
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003161 TemplateArgumentLocInventIterator operator++(int) {
3162 TemplateArgumentLocInventIterator Old(*this);
3163 ++(*this);
3164 return Old;
3165 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003166
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003167 reference operator*() const {
3168 TemplateArgumentLoc Result;
3169 Self.InventTemplateArgumentLoc(*Iter, Result);
3170 return Result;
3171 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003172
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003173 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003174
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003175 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3176 const TemplateArgumentLocInventIterator &Y) {
3177 return X.Iter == Y.Iter;
3178 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003179
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003180 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3181 const TemplateArgumentLocInventIterator &Y) {
3182 return X.Iter != Y.Iter;
3183 }
3184};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003185
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003186template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003187template<typename InputIterator>
3188bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3189 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003190 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003191 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003192 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003193 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003194
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003195 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3196 // Unpack argument packs, which we translate them into separate
3197 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003198 // FIXME: We could do much better if we could guarantee that the
3199 // TemplateArgumentLocInfo for the pack expansion would be usable for
3200 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003201 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003202 TemplateArgument::pack_iterator>
3203 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003204 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003205 In.getArgument().pack_begin()),
3206 PackLocIterator(*this,
3207 In.getArgument().pack_end()),
3208 Outputs))
3209 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003210
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003211 continue;
3212 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003213
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003214 if (In.getArgument().isPackExpansion()) {
3215 // We have a pack expansion, for which we will be substituting into
3216 // the pattern.
3217 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003218 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003219 TemplateArgumentLoc Pattern
Chad Rosier4a9d7952012-08-08 18:46:20 +00003220 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
Douglas Gregorcded4f62011-01-14 17:04:44 +00003221 getSema().Context);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003222
Chris Lattner686775d2011-07-20 06:58:45 +00003223 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003224 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3225 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003226
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003227 // Determine whether the set of unexpanded parameter packs can and should
3228 // be expanded.
3229 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003230 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003231 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003232 if (getDerived().TryExpandParameterPacks(Ellipsis,
3233 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003234 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003235 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003236 RetainExpansion,
3237 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003238 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003239
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003240 if (!Expand) {
3241 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003242 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003243 // expansion.
3244 TemplateArgumentLoc OutPattern;
3245 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3246 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3247 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003248
Douglas Gregorcded4f62011-01-14 17:04:44 +00003249 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3250 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003251 if (Out.getArgument().isNull())
3252 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003253
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003254 Outputs.addArgument(Out);
3255 continue;
3256 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003257
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003258 // The transform has determined that we should perform an elementwise
3259 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003260 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003261 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3262
3263 if (getDerived().TransformTemplateArgument(Pattern, Out))
3264 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003265
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003266 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003267 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3268 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003269 if (Out.getArgument().isNull())
3270 return true;
3271 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003272
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003273 Outputs.addArgument(Out);
3274 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003275
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003276 // If we're supposed to retain a pack expansion, do so by temporarily
3277 // forgetting the partially-substituted parameter pack.
3278 if (RetainExpansion) {
3279 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003280
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003281 if (getDerived().TransformTemplateArgument(Pattern, Out))
3282 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003283
Douglas Gregorcded4f62011-01-14 17:04:44 +00003284 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3285 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003286 if (Out.getArgument().isNull())
3287 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003288
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003289 Outputs.addArgument(Out);
3290 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003291
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003292 continue;
3293 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003294
3295 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003296 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003297 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003298
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003299 Outputs.addArgument(Out);
3300 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003301
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003302 return false;
3303
3304}
3305
Douglas Gregor577f75a2009-08-04 16:50:30 +00003306//===----------------------------------------------------------------------===//
3307// Type transformation
3308//===----------------------------------------------------------------------===//
3309
3310template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003311QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003312 if (getDerived().AlreadyTransformed(T))
3313 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003314
John McCalla2becad2009-10-21 00:40:46 +00003315 // Temporary workaround. All of these transformations should
3316 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003317 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3318 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003319
John McCall43fed0d2010-11-12 08:19:04 +00003320 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003321
John McCalla2becad2009-10-21 00:40:46 +00003322 if (!NewDI)
3323 return QualType();
3324
3325 return NewDI->getType();
3326}
3327
3328template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003329TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003330 // Refine the base location to the type's location.
3331 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3332 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003333 if (getDerived().AlreadyTransformed(DI->getType()))
3334 return DI;
3335
3336 TypeLocBuilder TLB;
3337
3338 TypeLoc TL = DI->getTypeLoc();
3339 TLB.reserve(TL.getFullDataSize());
3340
John McCall43fed0d2010-11-12 08:19:04 +00003341 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003342 if (Result.isNull())
3343 return 0;
3344
John McCalla93c9342009-12-07 02:54:59 +00003345 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003346}
3347
3348template<typename Derived>
3349QualType
John McCall43fed0d2010-11-12 08:19:04 +00003350TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003351 switch (T.getTypeLocClass()) {
3352#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003353#define TYPELOC(CLASS, PARENT) \
3354 case TypeLoc::CLASS: \
3355 return getDerived().Transform##CLASS##Type(TLB, \
3356 T.castAs<CLASS##TypeLoc>());
John McCalla2becad2009-10-21 00:40:46 +00003357#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003358 }
Mike Stump1eb44332009-09-09 15:08:12 +00003359
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003360 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003361}
3362
3363/// FIXME: By default, this routine adds type qualifiers only to types
3364/// that can have qualifiers, and silently suppresses those qualifiers
3365/// that are not permitted (e.g., qualifiers on reference or function
3366/// types). This is the right thing for template instantiation, but
3367/// probably not for other clients.
3368template<typename Derived>
3369QualType
3370TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003371 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003372 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003373
John McCall43fed0d2010-11-12 08:19:04 +00003374 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003375 if (Result.isNull())
3376 return QualType();
3377
3378 // Silently suppress qualifiers if the result type can't be qualified.
3379 // FIXME: this is the right thing for template instantiation, but
3380 // probably not for other clients.
3381 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003382 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003383
John McCallf85e1932011-06-15 23:02:42 +00003384 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003385 // resulting type.
3386 if (Quals.hasObjCLifetime()) {
3387 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3388 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003389 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003390 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003391 // A lifetime qualifier applied to a substituted template parameter
3392 // overrides the lifetime qualifier from the template argument.
Douglas Gregor92d13872013-01-17 23:59:28 +00003393 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003394 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003395 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3396 QualType Replacement = SubstTypeParam->getReplacementType();
3397 Qualifiers Qs = Replacement.getQualifiers();
3398 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003399 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003400 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3401 Qs);
3402 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003403 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003404 Replacement);
3405 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003406 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3407 // 'auto' types behave the same way as template parameters.
3408 QualType Deduced = AutoTy->getDeducedType();
3409 Qualifiers Qs = Deduced.getQualifiers();
3410 Qs.removeObjCLifetime();
3411 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3412 Qs);
Richard Smitha2c36462013-04-26 16:15:35 +00003413 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto());
Douglas Gregor92d13872013-01-17 23:59:28 +00003414 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003415 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003416 // Otherwise, complain about the addition of a qualifier to an
3417 // already-qualified type.
3418 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003419 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003420 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003421
Douglas Gregore559ca12011-06-17 22:11:49 +00003422 Quals.removeObjCLifetime();
3423 }
3424 }
3425 }
John McCall28654742010-06-05 06:41:15 +00003426 if (!Quals.empty()) {
3427 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smith9807a2e2013-03-27 23:36:39 +00003428 // BuildQualifiedType might not add qualifiers if they are invalid.
3429 if (Result.hasLocalQualifiers())
3430 TLB.push<QualifiedTypeLoc>(Result);
John McCall28654742010-06-05 06:41:15 +00003431 // No location information to preserve.
3432 }
John McCalla2becad2009-10-21 00:40:46 +00003433
3434 return Result;
3435}
3436
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003437template<typename Derived>
3438TypeLoc
3439TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3440 QualType ObjectType,
3441 NamedDecl *UnqualLookup,
3442 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003443 QualType T = TL.getType();
3444 if (getDerived().AlreadyTransformed(T))
3445 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003446
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003447 TypeLocBuilder TLB;
3448 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003449
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003450 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003451 TemplateSpecializationTypeLoc SpecTL =
3452 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003453
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003454 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003455 getDerived().TransformTemplateName(SS,
3456 SpecTL.getTypePtr()->getTemplateName(),
3457 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003458 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003459 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003460 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003461
3462 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003463 Template);
3464 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003465 DependentTemplateSpecializationTypeLoc SpecTL =
3466 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003467
Douglas Gregora88f09f2011-02-28 17:23:35 +00003468 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003469 = getDerived().RebuildTemplateName(SS,
3470 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003471 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003472 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003473 if (Template.isNull())
3474 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003475
3476 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003477 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003478 Template,
3479 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003480 } else {
3481 // Nothing special needs to be done for these.
3482 Result = getDerived().TransformType(TLB, TL);
3483 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003484
3485 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003486 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003487
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003488 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3489}
3490
Douglas Gregorb71d8212011-03-02 18:32:08 +00003491template<typename Derived>
3492TypeSourceInfo *
3493TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3494 QualType ObjectType,
3495 NamedDecl *UnqualLookup,
3496 CXXScopeSpec &SS) {
3497 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003498
Douglas Gregorb71d8212011-03-02 18:32:08 +00003499 QualType T = TSInfo->getType();
3500 if (getDerived().AlreadyTransformed(T))
3501 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003502
Douglas Gregorb71d8212011-03-02 18:32:08 +00003503 TypeLocBuilder TLB;
3504 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003505
Douglas Gregorb71d8212011-03-02 18:32:08 +00003506 TypeLoc TL = TSInfo->getTypeLoc();
3507 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003508 TemplateSpecializationTypeLoc SpecTL =
3509 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003510
Douglas Gregorb71d8212011-03-02 18:32:08 +00003511 TemplateName Template
3512 = getDerived().TransformTemplateName(SS,
3513 SpecTL.getTypePtr()->getTemplateName(),
3514 SpecTL.getTemplateNameLoc(),
3515 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003516 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003517 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003518
3519 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003520 Template);
3521 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003522 DependentTemplateSpecializationTypeLoc SpecTL =
3523 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003524
Douglas Gregorb71d8212011-03-02 18:32:08 +00003525 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003526 = getDerived().RebuildTemplateName(SS,
3527 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003528 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003529 ObjectType, UnqualLookup);
3530 if (Template.isNull())
3531 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003532
3533 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003534 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003535 Template,
3536 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003537 } else {
3538 // Nothing special needs to be done for these.
3539 Result = getDerived().TransformType(TLB, TL);
3540 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003541
3542 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003543 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003544
Douglas Gregorb71d8212011-03-02 18:32:08 +00003545 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3546}
3547
John McCalla2becad2009-10-21 00:40:46 +00003548template <class TyLoc> static inline
3549QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3550 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3551 NewT.setNameLoc(T.getNameLoc());
3552 return T.getType();
3553}
3554
John McCalla2becad2009-10-21 00:40:46 +00003555template<typename Derived>
3556QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003557 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003558 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3559 NewT.setBuiltinLoc(T.getBuiltinLoc());
3560 if (T.needsExtraLocalData())
3561 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3562 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003563}
Mike Stump1eb44332009-09-09 15:08:12 +00003564
Douglas Gregor577f75a2009-08-04 16:50:30 +00003565template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003566QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003567 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003568 // FIXME: recurse?
3569 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003570}
Mike Stump1eb44332009-09-09 15:08:12 +00003571
Douglas Gregor577f75a2009-08-04 16:50:30 +00003572template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003573QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003574 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003575 QualType PointeeType
3576 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003577 if (PointeeType.isNull())
3578 return QualType();
3579
3580 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003581 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003582 // A dependent pointer type 'T *' has is being transformed such
3583 // that an Objective-C class type is being replaced for 'T'. The
3584 // resulting pointer type is an ObjCObjectPointerType, not a
3585 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003586 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003587
John McCallc12c5bb2010-05-15 11:32:37 +00003588 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3589 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003590 return Result;
3591 }
John McCall43fed0d2010-11-12 08:19:04 +00003592
Douglas Gregor92e986e2010-04-22 16:44:27 +00003593 if (getDerived().AlwaysRebuild() ||
3594 PointeeType != TL.getPointeeLoc().getType()) {
3595 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3596 if (Result.isNull())
3597 return QualType();
3598 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003599
John McCallf85e1932011-06-15 23:02:42 +00003600 // Objective-C ARC can add lifetime qualifiers to the type that we're
3601 // pointing to.
3602 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003603
Douglas Gregor92e986e2010-04-22 16:44:27 +00003604 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3605 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003606 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003607}
Mike Stump1eb44332009-09-09 15:08:12 +00003608
3609template<typename Derived>
3610QualType
John McCalla2becad2009-10-21 00:40:46 +00003611TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003612 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003613 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003614 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3615 if (PointeeType.isNull())
3616 return QualType();
3617
3618 QualType Result = TL.getType();
3619 if (getDerived().AlwaysRebuild() ||
3620 PointeeType != TL.getPointeeLoc().getType()) {
3621 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003622 TL.getSigilLoc());
3623 if (Result.isNull())
3624 return QualType();
3625 }
3626
Douglas Gregor39968ad2010-04-22 16:50:51 +00003627 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003628 NewT.setSigilLoc(TL.getSigilLoc());
3629 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003630}
3631
John McCall85737a72009-10-30 00:06:24 +00003632/// Transforms a reference type. Note that somewhat paradoxically we
3633/// don't care whether the type itself is an l-value type or an r-value
3634/// type; we only care if the type was *written* as an l-value type
3635/// or an r-value type.
3636template<typename Derived>
3637QualType
3638TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003639 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003640 const ReferenceType *T = TL.getTypePtr();
3641
3642 // Note that this works with the pointee-as-written.
3643 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3644 if (PointeeType.isNull())
3645 return QualType();
3646
3647 QualType Result = TL.getType();
3648 if (getDerived().AlwaysRebuild() ||
3649 PointeeType != T->getPointeeTypeAsWritten()) {
3650 Result = getDerived().RebuildReferenceType(PointeeType,
3651 T->isSpelledAsLValue(),
3652 TL.getSigilLoc());
3653 if (Result.isNull())
3654 return QualType();
3655 }
3656
John McCallf85e1932011-06-15 23:02:42 +00003657 // Objective-C ARC can add lifetime qualifiers to the type that we're
3658 // referring to.
3659 TLB.TypeWasModifiedSafely(
3660 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3661
John McCall85737a72009-10-30 00:06:24 +00003662 // r-value references can be rebuilt as l-value references.
3663 ReferenceTypeLoc NewTL;
3664 if (isa<LValueReferenceType>(Result))
3665 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3666 else
3667 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3668 NewTL.setSigilLoc(TL.getSigilLoc());
3669
3670 return Result;
3671}
3672
Mike Stump1eb44332009-09-09 15:08:12 +00003673template<typename Derived>
3674QualType
John McCalla2becad2009-10-21 00:40:46 +00003675TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003676 LValueReferenceTypeLoc TL) {
3677 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003678}
3679
Mike Stump1eb44332009-09-09 15:08:12 +00003680template<typename Derived>
3681QualType
John McCalla2becad2009-10-21 00:40:46 +00003682TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003683 RValueReferenceTypeLoc TL) {
3684 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003685}
Mike Stump1eb44332009-09-09 15:08:12 +00003686
Douglas Gregor577f75a2009-08-04 16:50:30 +00003687template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003688QualType
John McCalla2becad2009-10-21 00:40:46 +00003689TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003690 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003691 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003692 if (PointeeType.isNull())
3693 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003694
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003695 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3696 TypeSourceInfo* NewClsTInfo = 0;
3697 if (OldClsTInfo) {
3698 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3699 if (!NewClsTInfo)
3700 return QualType();
3701 }
3702
3703 const MemberPointerType *T = TL.getTypePtr();
3704 QualType OldClsType = QualType(T->getClass(), 0);
3705 QualType NewClsType;
3706 if (NewClsTInfo)
3707 NewClsType = NewClsTInfo->getType();
3708 else {
3709 NewClsType = getDerived().TransformType(OldClsType);
3710 if (NewClsType.isNull())
3711 return QualType();
3712 }
Mike Stump1eb44332009-09-09 15:08:12 +00003713
John McCalla2becad2009-10-21 00:40:46 +00003714 QualType Result = TL.getType();
3715 if (getDerived().AlwaysRebuild() ||
3716 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003717 NewClsType != OldClsType) {
3718 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003719 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003720 if (Result.isNull())
3721 return QualType();
3722 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003723
John McCalla2becad2009-10-21 00:40:46 +00003724 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3725 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003726 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003727
3728 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003729}
3730
Mike Stump1eb44332009-09-09 15:08:12 +00003731template<typename Derived>
3732QualType
John McCalla2becad2009-10-21 00:40:46 +00003733TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003734 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003735 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003736 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003737 if (ElementType.isNull())
3738 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003739
John McCalla2becad2009-10-21 00:40:46 +00003740 QualType Result = TL.getType();
3741 if (getDerived().AlwaysRebuild() ||
3742 ElementType != T->getElementType()) {
3743 Result = getDerived().RebuildConstantArrayType(ElementType,
3744 T->getSizeModifier(),
3745 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003746 T->getIndexTypeCVRQualifiers(),
3747 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003748 if (Result.isNull())
3749 return QualType();
3750 }
Eli Friedman457a3772012-01-25 22:19:07 +00003751
3752 // We might have either a ConstantArrayType or a VariableArrayType now:
3753 // a ConstantArrayType is allowed to have an element type which is a
3754 // VariableArrayType if the type is dependent. Fortunately, all array
3755 // types have the same location layout.
3756 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003757 NewTL.setLBracketLoc(TL.getLBracketLoc());
3758 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003759
John McCalla2becad2009-10-21 00:40:46 +00003760 Expr *Size = TL.getSizeExpr();
3761 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003762 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3763 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003764 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003765 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003766 }
3767 NewTL.setSizeExpr(Size);
3768
3769 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003770}
Mike Stump1eb44332009-09-09 15:08:12 +00003771
Douglas Gregor577f75a2009-08-04 16:50:30 +00003772template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003773QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003774 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003775 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003776 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003777 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003778 if (ElementType.isNull())
3779 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003780
John McCalla2becad2009-10-21 00:40:46 +00003781 QualType Result = TL.getType();
3782 if (getDerived().AlwaysRebuild() ||
3783 ElementType != T->getElementType()) {
3784 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003785 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003786 T->getIndexTypeCVRQualifiers(),
3787 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003788 if (Result.isNull())
3789 return QualType();
3790 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003791
John McCalla2becad2009-10-21 00:40:46 +00003792 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3793 NewTL.setLBracketLoc(TL.getLBracketLoc());
3794 NewTL.setRBracketLoc(TL.getRBracketLoc());
3795 NewTL.setSizeExpr(0);
3796
3797 return Result;
3798}
3799
3800template<typename Derived>
3801QualType
3802TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003803 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003804 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003805 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3806 if (ElementType.isNull())
3807 return QualType();
3808
John McCall60d7b3a2010-08-24 06:29:42 +00003809 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003810 = getDerived().TransformExpr(T->getSizeExpr());
3811 if (SizeResult.isInvalid())
3812 return QualType();
3813
John McCall9ae2f072010-08-23 23:25:46 +00003814 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003815
3816 QualType Result = TL.getType();
3817 if (getDerived().AlwaysRebuild() ||
3818 ElementType != T->getElementType() ||
3819 Size != T->getSizeExpr()) {
3820 Result = getDerived().RebuildVariableArrayType(ElementType,
3821 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003822 Size,
John McCalla2becad2009-10-21 00:40:46 +00003823 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003824 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003825 if (Result.isNull())
3826 return QualType();
3827 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003828
John McCalla2becad2009-10-21 00:40:46 +00003829 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3830 NewTL.setLBracketLoc(TL.getLBracketLoc());
3831 NewTL.setRBracketLoc(TL.getRBracketLoc());
3832 NewTL.setSizeExpr(Size);
3833
3834 return Result;
3835}
3836
3837template<typename Derived>
3838QualType
3839TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003840 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003841 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003842 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3843 if (ElementType.isNull())
3844 return QualType();
3845
Richard Smithf6702a32011-12-20 02:08:33 +00003846 // Array bounds are constant expressions.
3847 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3848 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003849
John McCall3b657512011-01-19 10:06:00 +00003850 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3851 Expr *origSize = TL.getSizeExpr();
3852 if (!origSize) origSize = T->getSizeExpr();
3853
3854 ExprResult sizeResult
3855 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003856 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003857 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003858 return QualType();
3859
John McCall3b657512011-01-19 10:06:00 +00003860 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003861
3862 QualType Result = TL.getType();
3863 if (getDerived().AlwaysRebuild() ||
3864 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003865 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003866 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3867 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003868 size,
John McCalla2becad2009-10-21 00:40:46 +00003869 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003870 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003871 if (Result.isNull())
3872 return QualType();
3873 }
John McCalla2becad2009-10-21 00:40:46 +00003874
3875 // We might have any sort of array type now, but fortunately they
3876 // all have the same location layout.
3877 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3878 NewTL.setLBracketLoc(TL.getLBracketLoc());
3879 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003880 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003881
3882 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003883}
Mike Stump1eb44332009-09-09 15:08:12 +00003884
3885template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003886QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003887 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003888 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003889 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003890
3891 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003892 QualType ElementType = getDerived().TransformType(T->getElementType());
3893 if (ElementType.isNull())
3894 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003895
Richard Smithf6702a32011-12-20 02:08:33 +00003896 // Vector sizes are constant expressions.
3897 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3898 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003899
John McCall60d7b3a2010-08-24 06:29:42 +00003900 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003901 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003902 if (Size.isInvalid())
3903 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003904
John McCalla2becad2009-10-21 00:40:46 +00003905 QualType Result = TL.getType();
3906 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003907 ElementType != T->getElementType() ||
3908 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003909 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003910 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003911 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003912 if (Result.isNull())
3913 return QualType();
3914 }
John McCalla2becad2009-10-21 00:40:46 +00003915
3916 // Result might be dependent or not.
3917 if (isa<DependentSizedExtVectorType>(Result)) {
3918 DependentSizedExtVectorTypeLoc NewTL
3919 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3920 NewTL.setNameLoc(TL.getNameLoc());
3921 } else {
3922 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3923 NewTL.setNameLoc(TL.getNameLoc());
3924 }
3925
3926 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003927}
Mike Stump1eb44332009-09-09 15:08:12 +00003928
3929template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003930QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003931 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003932 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003933 QualType ElementType = getDerived().TransformType(T->getElementType());
3934 if (ElementType.isNull())
3935 return QualType();
3936
John McCalla2becad2009-10-21 00:40:46 +00003937 QualType Result = TL.getType();
3938 if (getDerived().AlwaysRebuild() ||
3939 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003940 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003941 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003942 if (Result.isNull())
3943 return QualType();
3944 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003945
John McCalla2becad2009-10-21 00:40:46 +00003946 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3947 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003948
John McCalla2becad2009-10-21 00:40:46 +00003949 return Result;
3950}
3951
3952template<typename Derived>
3953QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003954 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003955 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003956 QualType ElementType = getDerived().TransformType(T->getElementType());
3957 if (ElementType.isNull())
3958 return QualType();
3959
3960 QualType Result = TL.getType();
3961 if (getDerived().AlwaysRebuild() ||
3962 ElementType != T->getElementType()) {
3963 Result = getDerived().RebuildExtVectorType(ElementType,
3964 T->getNumElements(),
3965 /*FIXME*/ SourceLocation());
3966 if (Result.isNull())
3967 return QualType();
3968 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003969
John McCalla2becad2009-10-21 00:40:46 +00003970 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3971 NewTL.setNameLoc(TL.getNameLoc());
3972
3973 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003974}
Mike Stump1eb44332009-09-09 15:08:12 +00003975
David Blaikiedc84cd52013-02-20 22:23:23 +00003976template <typename Derived>
3977ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
3978 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
3979 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003980 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003981 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003982
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003983 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003984 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003985 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003986 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00003987 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003988
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003989 TypeLocBuilder TLB;
3990 TypeLoc NewTL = OldDI->getTypeLoc();
3991 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003992
3993 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003994 OldExpansionTL.getPatternLoc());
3995 if (Result.isNull())
3996 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003997
3998 Result = RebuildPackExpansionType(Result,
3999 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004000 OldExpansionTL.getEllipsisLoc(),
4001 NumExpansions);
4002 if (Result.isNull())
4003 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004004
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004005 PackExpansionTypeLoc NewExpansionTL
4006 = TLB.push<PackExpansionTypeLoc>(Result);
4007 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4008 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4009 } else
4010 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00004011 if (!NewDI)
4012 return 0;
4013
John McCallfb44de92011-05-01 22:35:37 +00004014 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00004015 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00004016
4017 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4018 OldParm->getDeclContext(),
4019 OldParm->getInnerLocStart(),
4020 OldParm->getLocation(),
4021 OldParm->getIdentifier(),
4022 NewDI->getType(),
4023 NewDI,
4024 OldParm->getStorageClass(),
John McCallfb44de92011-05-01 22:35:37 +00004025 /* DefArg */ NULL);
4026 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4027 OldParm->getFunctionScopeIndex() + indexAdjustment);
4028 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004029}
4030
4031template<typename Derived>
4032bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004033 TransformFunctionTypeParams(SourceLocation Loc,
4034 ParmVarDecl **Params, unsigned NumParams,
4035 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004036 SmallVectorImpl<QualType> &OutParamTypes,
4037 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004038 int indexAdjustment = 0;
4039
Douglas Gregora009b592011-01-07 00:20:55 +00004040 for (unsigned i = 0; i != NumParams; ++i) {
4041 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004042 assert(OldParm->getFunctionScopeIndex() == i);
4043
David Blaikiedc84cd52013-02-20 22:23:23 +00004044 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004045 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004046 if (OldParm->isParameterPack()) {
4047 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004048 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004049
Douglas Gregor603cfb42011-01-05 23:12:31 +00004050 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004051 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004052 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004053 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4054 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004055 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4056
Douglas Gregor603cfb42011-01-05 23:12:31 +00004057 // Determine whether we should expand the parameter packs.
4058 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004059 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004060 Optional<unsigned> OrigNumExpansions =
4061 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004062 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004063 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4064 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004065 Unexpanded,
4066 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004067 RetainExpansion,
4068 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004069 return true;
4070 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004071
Douglas Gregor603cfb42011-01-05 23:12:31 +00004072 if (ShouldExpand) {
4073 // Expand the function parameter pack into multiple, separate
4074 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004075 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004076 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004077 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004078 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004079 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004080 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004081 OrigNumExpansions,
4082 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004083 if (!NewParm)
4084 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004085
Douglas Gregora009b592011-01-07 00:20:55 +00004086 OutParamTypes.push_back(NewParm->getType());
4087 if (PVars)
4088 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004089 }
Douglas Gregord3731192011-01-10 07:32:04 +00004090
4091 // If we're supposed to retain a pack expansion, do so by temporarily
4092 // forgetting the partially-substituted parameter pack.
4093 if (RetainExpansion) {
4094 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004095 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004096 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004097 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004098 OrigNumExpansions,
4099 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004100 if (!NewParm)
4101 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004102
Douglas Gregord3731192011-01-10 07:32:04 +00004103 OutParamTypes.push_back(NewParm->getType());
4104 if (PVars)
4105 PVars->push_back(NewParm);
4106 }
4107
John McCallfb44de92011-05-01 22:35:37 +00004108 // The next parameter should have the same adjustment as the
4109 // last thing we pushed, but we post-incremented indexAdjustment
4110 // on every push. Also, if we push nothing, the adjustment should
4111 // go down by one.
4112 indexAdjustment--;
4113
Douglas Gregor603cfb42011-01-05 23:12:31 +00004114 // We're done with the pack expansion.
4115 continue;
4116 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004117
4118 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004119 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004120 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4121 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004122 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004123 NumExpansions,
4124 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004125 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004126 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004127 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004128 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004129
John McCall21ef0fa2010-03-11 09:03:00 +00004130 if (!NewParm)
4131 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004132
Douglas Gregora009b592011-01-07 00:20:55 +00004133 OutParamTypes.push_back(NewParm->getType());
4134 if (PVars)
4135 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004136 continue;
4137 }
John McCall21ef0fa2010-03-11 09:03:00 +00004138
4139 // Deal with the possibility that we don't have a parameter
4140 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004141 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004142 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004143 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004144 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004145 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004146 = dyn_cast<PackExpansionType>(OldType)) {
4147 // We have a function parameter pack that may need to be expanded.
4148 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004149 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004150 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004151
Douglas Gregor603cfb42011-01-05 23:12:31 +00004152 // Determine whether we should expand the parameter packs.
4153 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004154 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004155 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004156 Unexpanded,
4157 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004158 RetainExpansion,
4159 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004160 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004161 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004162
Douglas Gregor603cfb42011-01-05 23:12:31 +00004163 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004164 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004165 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004166 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004167 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4168 QualType NewType = getDerived().TransformType(Pattern);
4169 if (NewType.isNull())
4170 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004171
Douglas Gregora009b592011-01-07 00:20:55 +00004172 OutParamTypes.push_back(NewType);
4173 if (PVars)
4174 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004175 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004176
Douglas Gregor603cfb42011-01-05 23:12:31 +00004177 // We're done with the pack expansion.
4178 continue;
4179 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004180
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004181 // If we're supposed to retain a pack expansion, do so by temporarily
4182 // forgetting the partially-substituted parameter pack.
4183 if (RetainExpansion) {
4184 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4185 QualType NewType = getDerived().TransformType(Pattern);
4186 if (NewType.isNull())
4187 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004188
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004189 OutParamTypes.push_back(NewType);
4190 if (PVars)
4191 PVars->push_back(0);
4192 }
Douglas Gregord3731192011-01-10 07:32:04 +00004193
Chad Rosier4a9d7952012-08-08 18:46:20 +00004194 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004195 // expansion.
4196 OldType = Expansion->getPattern();
4197 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004198 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4199 NewType = getDerived().TransformType(OldType);
4200 } else {
4201 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004202 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004203
Douglas Gregor603cfb42011-01-05 23:12:31 +00004204 if (NewType.isNull())
4205 return true;
4206
4207 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004208 NewType = getSema().Context.getPackExpansionType(NewType,
4209 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004210
Douglas Gregora009b592011-01-07 00:20:55 +00004211 OutParamTypes.push_back(NewType);
4212 if (PVars)
4213 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004214 }
4215
John McCallfb44de92011-05-01 22:35:37 +00004216#ifndef NDEBUG
4217 if (PVars) {
4218 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4219 if (ParmVarDecl *parm = (*PVars)[i])
4220 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004221 }
John McCallfb44de92011-05-01 22:35:37 +00004222#endif
4223
4224 return false;
4225}
John McCall21ef0fa2010-03-11 09:03:00 +00004226
4227template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004228QualType
John McCalla2becad2009-10-21 00:40:46 +00004229TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004230 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004231 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4232}
4233
4234template<typename Derived>
4235QualType
4236TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4237 FunctionProtoTypeLoc TL,
4238 CXXRecordDecl *ThisContext,
4239 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004240 // Transform the parameters and return type.
4241 //
Richard Smithe6975e92012-04-17 00:58:00 +00004242 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004243 // When the function has a trailing return type, we instantiate the
4244 // parameters before the return type, since the return type can then refer
4245 // to the parameters themselves (via decltype, sizeof, etc.).
4246 //
Chris Lattner686775d2011-07-20 06:58:45 +00004247 SmallVector<QualType, 4> ParamTypes;
4248 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004249 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004250
Douglas Gregordab60ad2010-10-01 18:44:50 +00004251 QualType ResultType;
4252
Richard Smith9fbf3272012-08-14 22:51:13 +00004253 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004254 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004255 TL.getParmArray(),
4256 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004257 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004258 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004259 return QualType();
4260
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004261 {
4262 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004263 // If a declaration declares a member function or member function
4264 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004265 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004266 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004267 // declarator.
4268 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004269
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004270 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4271 if (ResultType.isNull())
4272 return QualType();
4273 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004274 }
4275 else {
4276 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4277 if (ResultType.isNull())
4278 return QualType();
4279
Chad Rosier4a9d7952012-08-08 18:46:20 +00004280 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004281 TL.getParmArray(),
4282 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004283 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004284 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004285 return QualType();
4286 }
4287
Richard Smithe6975e92012-04-17 00:58:00 +00004288 // FIXME: Need to transform the exception-specification too.
4289
John McCalla2becad2009-10-21 00:40:46 +00004290 QualType Result = TL.getType();
4291 if (getDerived().AlwaysRebuild() ||
4292 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004293 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004294 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004295 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004296 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004297 if (Result.isNull())
4298 return QualType();
4299 }
Mike Stump1eb44332009-09-09 15:08:12 +00004300
John McCalla2becad2009-10-21 00:40:46 +00004301 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004302 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004303 NewTL.setLParenLoc(TL.getLParenLoc());
4304 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004305 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004306 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4307 NewTL.setArg(i, ParamDecls[i]);
4308
4309 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004310}
Mike Stump1eb44332009-09-09 15:08:12 +00004311
Douglas Gregor577f75a2009-08-04 16:50:30 +00004312template<typename Derived>
4313QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004314 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004315 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004316 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004317 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4318 if (ResultType.isNull())
4319 return QualType();
4320
4321 QualType Result = TL.getType();
4322 if (getDerived().AlwaysRebuild() ||
4323 ResultType != T->getResultType())
4324 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4325
4326 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004327 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004328 NewTL.setLParenLoc(TL.getLParenLoc());
4329 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004330 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004331
4332 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004333}
Mike Stump1eb44332009-09-09 15:08:12 +00004334
John McCalled976492009-12-04 22:46:56 +00004335template<typename Derived> QualType
4336TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004337 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004338 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004339 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004340 if (!D)
4341 return QualType();
4342
4343 QualType Result = TL.getType();
4344 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4345 Result = getDerived().RebuildUnresolvedUsingType(D);
4346 if (Result.isNull())
4347 return QualType();
4348 }
4349
4350 // We might get an arbitrary type spec type back. We should at
4351 // least always get a type spec type, though.
4352 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4353 NewTL.setNameLoc(TL.getNameLoc());
4354
4355 return Result;
4356}
4357
Douglas Gregor577f75a2009-08-04 16:50:30 +00004358template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004359QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004360 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004361 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004362 TypedefNameDecl *Typedef
4363 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4364 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004365 if (!Typedef)
4366 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004367
John McCalla2becad2009-10-21 00:40:46 +00004368 QualType Result = TL.getType();
4369 if (getDerived().AlwaysRebuild() ||
4370 Typedef != T->getDecl()) {
4371 Result = getDerived().RebuildTypedefType(Typedef);
4372 if (Result.isNull())
4373 return QualType();
4374 }
Mike Stump1eb44332009-09-09 15:08:12 +00004375
John McCalla2becad2009-10-21 00:40:46 +00004376 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4377 NewTL.setNameLoc(TL.getNameLoc());
4378
4379 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004380}
Mike Stump1eb44332009-09-09 15:08:12 +00004381
Douglas Gregor577f75a2009-08-04 16:50:30 +00004382template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004383QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004384 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004385 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004386 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4387 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004388
John McCall60d7b3a2010-08-24 06:29:42 +00004389 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004390 if (E.isInvalid())
4391 return QualType();
4392
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004393 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4394 if (E.isInvalid())
4395 return QualType();
4396
John McCalla2becad2009-10-21 00:40:46 +00004397 QualType Result = TL.getType();
4398 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004399 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004400 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004401 if (Result.isNull())
4402 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004403 }
John McCalla2becad2009-10-21 00:40:46 +00004404 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004405
John McCalla2becad2009-10-21 00:40:46 +00004406 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004407 NewTL.setTypeofLoc(TL.getTypeofLoc());
4408 NewTL.setLParenLoc(TL.getLParenLoc());
4409 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004410
4411 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004412}
Mike Stump1eb44332009-09-09 15:08:12 +00004413
4414template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004415QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004416 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004417 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4418 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4419 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004420 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004421
John McCalla2becad2009-10-21 00:40:46 +00004422 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004423 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4424 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004425 if (Result.isNull())
4426 return QualType();
4427 }
Mike Stump1eb44332009-09-09 15:08:12 +00004428
John McCalla2becad2009-10-21 00:40:46 +00004429 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004430 NewTL.setTypeofLoc(TL.getTypeofLoc());
4431 NewTL.setLParenLoc(TL.getLParenLoc());
4432 NewTL.setRParenLoc(TL.getRParenLoc());
4433 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004434
4435 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004436}
Mike Stump1eb44332009-09-09 15:08:12 +00004437
4438template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004439QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004440 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004441 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004442
Douglas Gregor670444e2009-08-04 22:27:00 +00004443 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004444 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4445 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004446
John McCall60d7b3a2010-08-24 06:29:42 +00004447 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004448 if (E.isInvalid())
4449 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004450
Richard Smith76f3f692012-02-22 02:04:18 +00004451 E = getSema().ActOnDecltypeExpression(E.take());
4452 if (E.isInvalid())
4453 return QualType();
4454
John McCalla2becad2009-10-21 00:40:46 +00004455 QualType Result = TL.getType();
4456 if (getDerived().AlwaysRebuild() ||
4457 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004458 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004459 if (Result.isNull())
4460 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004461 }
John McCalla2becad2009-10-21 00:40:46 +00004462 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004463
John McCalla2becad2009-10-21 00:40:46 +00004464 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4465 NewTL.setNameLoc(TL.getNameLoc());
4466
4467 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004468}
4469
4470template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004471QualType TreeTransform<Derived>::TransformUnaryTransformType(
4472 TypeLocBuilder &TLB,
4473 UnaryTransformTypeLoc TL) {
4474 QualType Result = TL.getType();
4475 if (Result->isDependentType()) {
4476 const UnaryTransformType *T = TL.getTypePtr();
4477 QualType NewBase =
4478 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4479 Result = getDerived().RebuildUnaryTransformType(NewBase,
4480 T->getUTTKind(),
4481 TL.getKWLoc());
4482 if (Result.isNull())
4483 return QualType();
4484 }
4485
4486 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4487 NewTL.setKWLoc(TL.getKWLoc());
4488 NewTL.setParensRange(TL.getParensRange());
4489 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4490 return Result;
4491}
4492
4493template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004494QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4495 AutoTypeLoc TL) {
4496 const AutoType *T = TL.getTypePtr();
4497 QualType OldDeduced = T->getDeducedType();
4498 QualType NewDeduced;
4499 if (!OldDeduced.isNull()) {
4500 NewDeduced = getDerived().TransformType(OldDeduced);
4501 if (NewDeduced.isNull())
4502 return QualType();
4503 }
4504
4505 QualType Result = TL.getType();
Richard Smithdc7a4f52013-04-30 13:56:41 +00004506 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
4507 T->isDependentType()) {
Richard Smitha2c36462013-04-26 16:15:35 +00004508 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith34b41d92011-02-20 03:19:35 +00004509 if (Result.isNull())
4510 return QualType();
4511 }
4512
4513 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4514 NewTL.setNameLoc(TL.getNameLoc());
4515
4516 return Result;
4517}
4518
4519template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004520QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004521 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004522 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004523 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004524 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4525 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004526 if (!Record)
4527 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004528
John McCalla2becad2009-10-21 00:40:46 +00004529 QualType Result = TL.getType();
4530 if (getDerived().AlwaysRebuild() ||
4531 Record != T->getDecl()) {
4532 Result = getDerived().RebuildRecordType(Record);
4533 if (Result.isNull())
4534 return QualType();
4535 }
Mike Stump1eb44332009-09-09 15:08:12 +00004536
John McCalla2becad2009-10-21 00:40:46 +00004537 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4538 NewTL.setNameLoc(TL.getNameLoc());
4539
4540 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004541}
Mike Stump1eb44332009-09-09 15:08:12 +00004542
4543template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004544QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004545 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004546 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004547 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004548 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4549 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004550 if (!Enum)
4551 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004552
John McCalla2becad2009-10-21 00:40:46 +00004553 QualType Result = TL.getType();
4554 if (getDerived().AlwaysRebuild() ||
4555 Enum != T->getDecl()) {
4556 Result = getDerived().RebuildEnumType(Enum);
4557 if (Result.isNull())
4558 return QualType();
4559 }
Mike Stump1eb44332009-09-09 15:08:12 +00004560
John McCalla2becad2009-10-21 00:40:46 +00004561 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4562 NewTL.setNameLoc(TL.getNameLoc());
4563
4564 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004565}
John McCall7da24312009-09-05 00:15:47 +00004566
John McCall3cb0ebd2010-03-10 03:28:59 +00004567template<typename Derived>
4568QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4569 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004570 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004571 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4572 TL.getTypePtr()->getDecl());
4573 if (!D) return QualType();
4574
4575 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4576 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4577 return T;
4578}
4579
Douglas Gregor577f75a2009-08-04 16:50:30 +00004580template<typename Derived>
4581QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004582 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004583 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004584 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004585}
4586
Mike Stump1eb44332009-09-09 15:08:12 +00004587template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004588QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004589 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004590 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004591 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004592
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004593 // Substitute into the replacement type, which itself might involve something
4594 // that needs to be transformed. This only tends to occur with default
4595 // template arguments of template template parameters.
4596 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4597 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4598 if (Replacement.isNull())
4599 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004600
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004601 // Always canonicalize the replacement type.
4602 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4603 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004604 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004605 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004606
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004607 // Propagate type-source information.
4608 SubstTemplateTypeParmTypeLoc NewTL
4609 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4610 NewTL.setNameLoc(TL.getNameLoc());
4611 return Result;
4612
John McCall49a832b2009-10-18 09:09:24 +00004613}
4614
4615template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004616QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4617 TypeLocBuilder &TLB,
4618 SubstTemplateTypeParmPackTypeLoc TL) {
4619 return TransformTypeSpecType(TLB, TL);
4620}
4621
4622template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004623QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004624 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004625 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004626 const TemplateSpecializationType *T = TL.getTypePtr();
4627
Douglas Gregor1d752d72011-03-02 18:46:51 +00004628 // The nested-name-specifier never matters in a TemplateSpecializationType,
4629 // because we can't have a dependent nested-name-specifier anyway.
4630 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004631 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004632 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4633 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004634 if (Template.isNull())
4635 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004636
John McCall43fed0d2010-11-12 08:19:04 +00004637 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4638}
4639
Eli Friedmanb001de72011-10-06 23:00:33 +00004640template<typename Derived>
4641QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4642 AtomicTypeLoc TL) {
4643 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4644 if (ValueType.isNull())
4645 return QualType();
4646
4647 QualType Result = TL.getType();
4648 if (getDerived().AlwaysRebuild() ||
4649 ValueType != TL.getValueLoc().getType()) {
4650 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4651 if (Result.isNull())
4652 return QualType();
4653 }
4654
4655 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4656 NewTL.setKWLoc(TL.getKWLoc());
4657 NewTL.setLParenLoc(TL.getLParenLoc());
4658 NewTL.setRParenLoc(TL.getRParenLoc());
4659
4660 return Result;
4661}
4662
Chad Rosier4a9d7952012-08-08 18:46:20 +00004663 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004664 /// container that provides a \c getArgLoc() member function.
4665 ///
4666 /// This iterator is intended to be used with the iterator form of
4667 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4668 template<typename ArgLocContainer>
4669 class TemplateArgumentLocContainerIterator {
4670 ArgLocContainer *Container;
4671 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004672
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004673 public:
4674 typedef TemplateArgumentLoc value_type;
4675 typedef TemplateArgumentLoc reference;
4676 typedef int difference_type;
4677 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004678
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004679 class pointer {
4680 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004681
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004682 public:
4683 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004684
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004685 const TemplateArgumentLoc *operator->() const {
4686 return &Arg;
4687 }
4688 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004689
4690
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004691 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004692
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004693 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4694 unsigned Index)
4695 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004696
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004697 TemplateArgumentLocContainerIterator &operator++() {
4698 ++Index;
4699 return *this;
4700 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004701
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004702 TemplateArgumentLocContainerIterator operator++(int) {
4703 TemplateArgumentLocContainerIterator Old(*this);
4704 ++(*this);
4705 return Old;
4706 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004707
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004708 TemplateArgumentLoc operator*() const {
4709 return Container->getArgLoc(Index);
4710 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004711
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004712 pointer operator->() const {
4713 return pointer(Container->getArgLoc(Index));
4714 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004715
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004716 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004717 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004718 return X.Container == Y.Container && X.Index == Y.Index;
4719 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004720
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004721 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004722 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004723 return !(X == Y);
4724 }
4725 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004726
4727
John McCall43fed0d2010-11-12 08:19:04 +00004728template <typename Derived>
4729QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4730 TypeLocBuilder &TLB,
4731 TemplateSpecializationTypeLoc TL,
4732 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004733 TemplateArgumentListInfo NewTemplateArgs;
4734 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4735 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004736 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4737 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004738 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004739 ArgIterator(TL, TL.getNumArgs()),
4740 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004741 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004742
John McCall833ca992009-10-29 08:12:44 +00004743 // FIXME: maybe don't rebuild if all the template arguments are the same.
4744
4745 QualType Result =
4746 getDerived().RebuildTemplateSpecializationType(Template,
4747 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004748 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004749
4750 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004751 // Specializations of template template parameters are represented as
4752 // TemplateSpecializationTypes, and substitution of type alias templates
4753 // within a dependent context can transform them into
4754 // DependentTemplateSpecializationTypes.
4755 if (isa<DependentTemplateSpecializationType>(Result)) {
4756 DependentTemplateSpecializationTypeLoc NewTL
4757 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004758 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004759 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004760 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004761 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004762 NewTL.setLAngleLoc(TL.getLAngleLoc());
4763 NewTL.setRAngleLoc(TL.getRAngleLoc());
4764 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4765 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4766 return Result;
4767 }
4768
John McCall833ca992009-10-29 08:12:44 +00004769 TemplateSpecializationTypeLoc NewTL
4770 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004771 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004772 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4773 NewTL.setLAngleLoc(TL.getLAngleLoc());
4774 NewTL.setRAngleLoc(TL.getRAngleLoc());
4775 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4776 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004777 }
Mike Stump1eb44332009-09-09 15:08:12 +00004778
John McCall833ca992009-10-29 08:12:44 +00004779 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004780}
Mike Stump1eb44332009-09-09 15:08:12 +00004781
Douglas Gregora88f09f2011-02-28 17:23:35 +00004782template <typename Derived>
4783QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4784 TypeLocBuilder &TLB,
4785 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004786 TemplateName Template,
4787 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004788 TemplateArgumentListInfo NewTemplateArgs;
4789 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4790 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4791 typedef TemplateArgumentLocContainerIterator<
4792 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004793 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004794 ArgIterator(TL, TL.getNumArgs()),
4795 NewTemplateArgs))
4796 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004797
Douglas Gregora88f09f2011-02-28 17:23:35 +00004798 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004799
Douglas Gregora88f09f2011-02-28 17:23:35 +00004800 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4801 QualType Result
4802 = getSema().Context.getDependentTemplateSpecializationType(
4803 TL.getTypePtr()->getKeyword(),
4804 DTN->getQualifier(),
4805 DTN->getIdentifier(),
4806 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004807
Douglas Gregora88f09f2011-02-28 17:23:35 +00004808 DependentTemplateSpecializationTypeLoc NewTL
4809 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004810 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004811 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004812 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004813 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004814 NewTL.setLAngleLoc(TL.getLAngleLoc());
4815 NewTL.setRAngleLoc(TL.getRAngleLoc());
4816 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4817 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4818 return Result;
4819 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004820
4821 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004822 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004823 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004824 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004825
Douglas Gregora88f09f2011-02-28 17:23:35 +00004826 if (!Result.isNull()) {
4827 /// FIXME: Wrap this in an elaborated-type-specifier?
4828 TemplateSpecializationTypeLoc NewTL
4829 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004830 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004831 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004832 NewTL.setLAngleLoc(TL.getLAngleLoc());
4833 NewTL.setRAngleLoc(TL.getRAngleLoc());
4834 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4835 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4836 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004837
Douglas Gregora88f09f2011-02-28 17:23:35 +00004838 return Result;
4839}
4840
Mike Stump1eb44332009-09-09 15:08:12 +00004841template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004842QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004843TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004844 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004845 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004846
Douglas Gregor9e876872011-03-01 18:12:44 +00004847 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004848 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004849 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004850 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004851 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4852 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004853 return QualType();
4854 }
Mike Stump1eb44332009-09-09 15:08:12 +00004855
John McCall43fed0d2010-11-12 08:19:04 +00004856 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4857 if (NamedT.isNull())
4858 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004859
Richard Smith3e4c6c42011-05-05 21:57:07 +00004860 // C++0x [dcl.type.elab]p2:
4861 // If the identifier resolves to a typedef-name or the simple-template-id
4862 // resolves to an alias template specialization, the
4863 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004864 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4865 if (const TemplateSpecializationType *TST =
4866 NamedT->getAs<TemplateSpecializationType>()) {
4867 TemplateName Template = TST->getTemplateName();
4868 if (TypeAliasTemplateDecl *TAT =
4869 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4870 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4871 diag::err_tag_reference_non_tag) << 4;
4872 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4873 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004874 }
4875 }
4876
John McCalla2becad2009-10-21 00:40:46 +00004877 QualType Result = TL.getType();
4878 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004879 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004880 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004881 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004882 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004883 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004884 if (Result.isNull())
4885 return QualType();
4886 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004887
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004888 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004889 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004890 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004891 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004892}
Mike Stump1eb44332009-09-09 15:08:12 +00004893
4894template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004895QualType TreeTransform<Derived>::TransformAttributedType(
4896 TypeLocBuilder &TLB,
4897 AttributedTypeLoc TL) {
4898 const AttributedType *oldType = TL.getTypePtr();
4899 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4900 if (modifiedType.isNull())
4901 return QualType();
4902
4903 QualType result = TL.getType();
4904
4905 // FIXME: dependent operand expressions?
4906 if (getDerived().AlwaysRebuild() ||
4907 modifiedType != oldType->getModifiedType()) {
4908 // TODO: this is really lame; we should really be rebuilding the
4909 // equivalent type from first principles.
4910 QualType equivalentType
4911 = getDerived().TransformType(oldType->getEquivalentType());
4912 if (equivalentType.isNull())
4913 return QualType();
4914 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4915 modifiedType,
4916 equivalentType);
4917 }
4918
4919 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4920 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4921 if (TL.hasAttrOperand())
4922 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4923 if (TL.hasAttrExprOperand())
4924 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4925 else if (TL.hasAttrEnumOperand())
4926 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4927
4928 return result;
4929}
4930
4931template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004932QualType
4933TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4934 ParenTypeLoc TL) {
4935 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4936 if (Inner.isNull())
4937 return QualType();
4938
4939 QualType Result = TL.getType();
4940 if (getDerived().AlwaysRebuild() ||
4941 Inner != TL.getInnerLoc().getType()) {
4942 Result = getDerived().RebuildParenType(Inner);
4943 if (Result.isNull())
4944 return QualType();
4945 }
4946
4947 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4948 NewTL.setLParenLoc(TL.getLParenLoc());
4949 NewTL.setRParenLoc(TL.getRParenLoc());
4950 return Result;
4951}
4952
4953template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004954QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004955 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004956 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004957
Douglas Gregor2494dd02011-03-01 01:34:45 +00004958 NestedNameSpecifierLoc QualifierLoc
4959 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4960 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004961 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004962
John McCall33500952010-06-11 00:33:02 +00004963 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004964 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004965 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004966 QualifierLoc,
4967 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004968 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004969 if (Result.isNull())
4970 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004971
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004972 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4973 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004974 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4975
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004976 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004977 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004978 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004979 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004980 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004981 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004982 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004983 NewTL.setNameLoc(TL.getNameLoc());
4984 }
John McCalla2becad2009-10-21 00:40:46 +00004985 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004986}
Mike Stump1eb44332009-09-09 15:08:12 +00004987
Douglas Gregor577f75a2009-08-04 16:50:30 +00004988template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004989QualType TreeTransform<Derived>::
4990 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004991 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004992 NestedNameSpecifierLoc QualifierLoc;
4993 if (TL.getQualifierLoc()) {
4994 QualifierLoc
4995 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4996 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004997 return QualType();
4998 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004999
John McCall43fed0d2010-11-12 08:19:04 +00005000 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005001 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00005002}
5003
5004template<typename Derived>
5005QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005006TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5007 DependentTemplateSpecializationTypeLoc TL,
5008 NestedNameSpecifierLoc QualifierLoc) {
5009 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005010
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005011 TemplateArgumentListInfo NewTemplateArgs;
5012 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5013 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005014
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005015 typedef TemplateArgumentLocContainerIterator<
5016 DependentTemplateSpecializationTypeLoc> ArgIterator;
5017 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5018 ArgIterator(TL, TL.getNumArgs()),
5019 NewTemplateArgs))
5020 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005021
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005022 QualType Result
5023 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5024 QualifierLoc,
5025 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005026 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005027 NewTemplateArgs);
5028 if (Result.isNull())
5029 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005030
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005031 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5032 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005033
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005034 // Copy information relevant to the template specialization.
5035 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005036 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005037 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005038 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005039 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5040 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005041 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005042 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005043
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005044 // Copy information relevant to the elaborated type.
5045 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005046 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005047 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005048 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5049 DependentTemplateSpecializationTypeLoc SpecTL
5050 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005051 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005052 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005053 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005054 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005055 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5056 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005057 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005058 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005059 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005060 TemplateSpecializationTypeLoc SpecTL
5061 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005062 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005063 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005064 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5065 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005066 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005067 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005068 }
5069 return Result;
5070}
5071
5072template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005073QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5074 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005075 QualType Pattern
5076 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005077 if (Pattern.isNull())
5078 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005079
5080 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005081 if (getDerived().AlwaysRebuild() ||
5082 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005083 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005084 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005085 TL.getEllipsisLoc(),
5086 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005087 if (Result.isNull())
5088 return QualType();
5089 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005090
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005091 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5092 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5093 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005094}
5095
5096template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005097QualType
5098TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005099 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005100 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005101 TLB.pushFullCopy(TL);
5102 return TL.getType();
5103}
5104
5105template<typename Derived>
5106QualType
5107TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005108 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005109 // ObjCObjectType is never dependent.
5110 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005111 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005112}
Mike Stump1eb44332009-09-09 15:08:12 +00005113
5114template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005115QualType
5116TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005117 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005118 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005119 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005120 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005121}
5122
Douglas Gregor577f75a2009-08-04 16:50:30 +00005123//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005124// Statement transformation
5125//===----------------------------------------------------------------------===//
5126template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005127StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005128TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005129 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005130}
5131
5132template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005133StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005134TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5135 return getDerived().TransformCompoundStmt(S, false);
5136}
5137
5138template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005139StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005140TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005141 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005142 Sema::CompoundScopeRAII CompoundScope(getSema());
5143
John McCall7114cba2010-08-27 19:56:05 +00005144 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005145 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005146 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005147 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5148 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005149 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005150 if (Result.isInvalid()) {
5151 // Immediately fail if this was a DeclStmt, since it's very
5152 // likely that this will cause problems for future statements.
5153 if (isa<DeclStmt>(*B))
5154 return StmtError();
5155
5156 // Otherwise, just keep processing substatements and fail later.
5157 SubStmtInvalid = true;
5158 continue;
5159 }
Mike Stump1eb44332009-09-09 15:08:12 +00005160
Douglas Gregor43959a92009-08-20 07:17:43 +00005161 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5162 Statements.push_back(Result.takeAs<Stmt>());
5163 }
Mike Stump1eb44332009-09-09 15:08:12 +00005164
John McCall7114cba2010-08-27 19:56:05 +00005165 if (SubStmtInvalid)
5166 return StmtError();
5167
Douglas Gregor43959a92009-08-20 07:17:43 +00005168 if (!getDerived().AlwaysRebuild() &&
5169 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005170 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005171
5172 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005173 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005174 S->getRBracLoc(),
5175 IsStmtExpr);
5176}
Mike Stump1eb44332009-09-09 15:08:12 +00005177
Douglas Gregor43959a92009-08-20 07:17:43 +00005178template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005179StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005180TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005181 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005182 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005183 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5184 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005185
Eli Friedman264c1f82009-11-19 03:14:00 +00005186 // Transform the left-hand case value.
5187 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005188 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005189 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005190 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005191
Eli Friedman264c1f82009-11-19 03:14:00 +00005192 // Transform the right-hand case value (for the GNU case-range extension).
5193 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005194 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005195 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005196 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005197 }
Mike Stump1eb44332009-09-09 15:08:12 +00005198
Douglas Gregor43959a92009-08-20 07:17:43 +00005199 // Build the case statement.
5200 // Case statements are always rebuilt so that they will attached to their
5201 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005202 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005203 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005204 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005205 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005206 S->getColonLoc());
5207 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005208 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005209
Douglas Gregor43959a92009-08-20 07:17:43 +00005210 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005211 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005212 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005213 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005214
Douglas Gregor43959a92009-08-20 07:17:43 +00005215 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005216 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005217}
5218
5219template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005220StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005221TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005222 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005223 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005224 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005225 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005226
Douglas Gregor43959a92009-08-20 07:17:43 +00005227 // Default statements are always rebuilt
5228 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005229 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005230}
Mike Stump1eb44332009-09-09 15:08:12 +00005231
Douglas Gregor43959a92009-08-20 07:17:43 +00005232template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005233StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005234TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005235 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005236 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005237 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005238
Chris Lattner57ad3782011-02-17 20:34:02 +00005239 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5240 S->getDecl());
5241 if (!LD)
5242 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005243
5244
Douglas Gregor43959a92009-08-20 07:17:43 +00005245 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005246 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005247 cast<LabelDecl>(LD), SourceLocation(),
5248 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005249}
Mike Stump1eb44332009-09-09 15:08:12 +00005250
Douglas Gregor43959a92009-08-20 07:17:43 +00005251template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005252StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005253TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5254 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5255 if (SubStmt.isInvalid())
5256 return StmtError();
5257
5258 // TODO: transform attributes
5259 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5260 return S;
5261
5262 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5263 S->getAttrs(),
5264 SubStmt.get());
5265}
5266
5267template<typename Derived>
5268StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005269TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005270 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005271 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005272 VarDecl *ConditionVar = 0;
5273 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005274 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005275 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005276 getDerived().TransformDefinition(
5277 S->getConditionVariable()->getLocation(),
5278 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005279 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005280 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005281 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005282 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005283
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005284 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005285 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005286
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005287 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005288 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005289 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005290 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005291 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005292 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005293
John McCall9ae2f072010-08-23 23:25:46 +00005294 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005295 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005296 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005297
John McCall9ae2f072010-08-23 23:25:46 +00005298 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5299 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005300 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005301
Douglas Gregor43959a92009-08-20 07:17:43 +00005302 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005303 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005304 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005305 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005306
Douglas Gregor43959a92009-08-20 07:17:43 +00005307 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005308 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005309 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005310 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005311
Douglas Gregor43959a92009-08-20 07:17:43 +00005312 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005313 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005314 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005315 Then.get() == S->getThen() &&
5316 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005317 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005318
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005319 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005320 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005321 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005322}
5323
5324template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005325StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005326TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005327 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005328 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005329 VarDecl *ConditionVar = 0;
5330 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005331 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005332 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005333 getDerived().TransformDefinition(
5334 S->getConditionVariable()->getLocation(),
5335 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005336 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005337 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005338 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005339 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005340
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005341 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005342 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005343 }
Mike Stump1eb44332009-09-09 15:08:12 +00005344
Douglas Gregor43959a92009-08-20 07:17:43 +00005345 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005346 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005347 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005348 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005349 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005350 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005351
Douglas Gregor43959a92009-08-20 07:17:43 +00005352 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005353 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005354 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005355 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005356
Douglas Gregor43959a92009-08-20 07:17:43 +00005357 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005358 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5359 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005360}
Mike Stump1eb44332009-09-09 15:08:12 +00005361
Douglas Gregor43959a92009-08-20 07:17:43 +00005362template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005363StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005364TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005365 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005366 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005367 VarDecl *ConditionVar = 0;
5368 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005369 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005370 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005371 getDerived().TransformDefinition(
5372 S->getConditionVariable()->getLocation(),
5373 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005374 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005375 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005376 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005377 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005378
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005379 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005380 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005381
5382 if (S->getCond()) {
5383 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005384 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005385 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005386 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005387 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005388 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005389 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005390 }
Mike Stump1eb44332009-09-09 15:08:12 +00005391
John McCall9ae2f072010-08-23 23:25:46 +00005392 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5393 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005394 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005395
Douglas Gregor43959a92009-08-20 07:17:43 +00005396 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005397 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005398 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005399 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005400
Douglas Gregor43959a92009-08-20 07:17:43 +00005401 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005402 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005403 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005404 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005405 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005406
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005407 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005408 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005409}
Mike Stump1eb44332009-09-09 15:08:12 +00005410
Douglas Gregor43959a92009-08-20 07:17:43 +00005411template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005412StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005413TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005414 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005415 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005416 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005417 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005418
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005419 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005420 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005421 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005422 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005423
Douglas Gregor43959a92009-08-20 07:17:43 +00005424 if (!getDerived().AlwaysRebuild() &&
5425 Cond.get() == S->getCond() &&
5426 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005427 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005428
John McCall9ae2f072010-08-23 23:25:46 +00005429 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5430 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005431 S->getRParenLoc());
5432}
Mike Stump1eb44332009-09-09 15:08:12 +00005433
Douglas Gregor43959a92009-08-20 07:17:43 +00005434template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005435StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005436TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005437 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005438 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005439 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005440 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005441
Douglas Gregor43959a92009-08-20 07:17:43 +00005442 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005443 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005444 VarDecl *ConditionVar = 0;
5445 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005446 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005447 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005448 getDerived().TransformDefinition(
5449 S->getConditionVariable()->getLocation(),
5450 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005451 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005452 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005453 } else {
5454 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005455
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005456 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005457 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005458
5459 if (S->getCond()) {
5460 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005461 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005462 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005463 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005464 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005465
John McCall9ae2f072010-08-23 23:25:46 +00005466 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005467 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005468 }
Mike Stump1eb44332009-09-09 15:08:12 +00005469
Chad Rosier4a9d7952012-08-08 18:46:20 +00005470 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005471 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005472 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005473
Douglas Gregor43959a92009-08-20 07:17:43 +00005474 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005475 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005476 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005477 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005478
Richard Smith41956372013-01-14 22:39:08 +00005479 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005480 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005481 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005482
Douglas Gregor43959a92009-08-20 07:17:43 +00005483 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005484 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005485 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005486 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005487
Douglas Gregor43959a92009-08-20 07:17:43 +00005488 if (!getDerived().AlwaysRebuild() &&
5489 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005490 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005491 Inc.get() == S->getInc() &&
5492 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005493 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005494
Douglas Gregor43959a92009-08-20 07:17:43 +00005495 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005496 Init.get(), FullCond, ConditionVar,
5497 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005498}
5499
5500template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005501StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005502TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005503 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5504 S->getLabel());
5505 if (!LD)
5506 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005507
Douglas Gregor43959a92009-08-20 07:17:43 +00005508 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005509 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005510 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005511}
5512
5513template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005514StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005515TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005516 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005517 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005518 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005519 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005520
Douglas Gregor43959a92009-08-20 07:17:43 +00005521 if (!getDerived().AlwaysRebuild() &&
5522 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005523 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005524
5525 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005526 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005527}
5528
5529template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005530StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005531TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005532 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005533}
Mike Stump1eb44332009-09-09 15:08:12 +00005534
Douglas Gregor43959a92009-08-20 07:17:43 +00005535template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005536StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005537TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005538 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005539}
Mike Stump1eb44332009-09-09 15:08:12 +00005540
Douglas Gregor43959a92009-08-20 07:17:43 +00005541template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005542StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005543TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005544 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005545 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005546 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005547
Mike Stump1eb44332009-09-09 15:08:12 +00005548 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005549 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005550 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005551}
Mike Stump1eb44332009-09-09 15:08:12 +00005552
Douglas Gregor43959a92009-08-20 07:17:43 +00005553template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005554StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005555TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005556 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005557 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005558 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5559 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005560 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5561 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005562 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005563 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005564
Douglas Gregor43959a92009-08-20 07:17:43 +00005565 if (Transformed != *D)
5566 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005567
Douglas Gregor43959a92009-08-20 07:17:43 +00005568 Decls.push_back(Transformed);
5569 }
Mike Stump1eb44332009-09-09 15:08:12 +00005570
Douglas Gregor43959a92009-08-20 07:17:43 +00005571 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005572 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005573
5574 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005575 S->getStartLoc(), S->getEndLoc());
5576}
Mike Stump1eb44332009-09-09 15:08:12 +00005577
Douglas Gregor43959a92009-08-20 07:17:43 +00005578template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005579StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005580TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005581
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005582 SmallVector<Expr*, 8> Constraints;
5583 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005584 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005585
John McCall60d7b3a2010-08-24 06:29:42 +00005586 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005587 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005588
5589 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005590
Anders Carlsson703e3942010-01-24 05:50:09 +00005591 // Go through the outputs.
5592 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005593 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005594
Anders Carlsson703e3942010-01-24 05:50:09 +00005595 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005596 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005597
Anders Carlsson703e3942010-01-24 05:50:09 +00005598 // Transform the output expr.
5599 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005600 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005601 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005602 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005603
Anders Carlsson703e3942010-01-24 05:50:09 +00005604 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005605
John McCall9ae2f072010-08-23 23:25:46 +00005606 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005607 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005608
Anders Carlsson703e3942010-01-24 05:50:09 +00005609 // Go through the inputs.
5610 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005611 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005612
Anders Carlsson703e3942010-01-24 05:50:09 +00005613 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005614 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005615
Anders Carlsson703e3942010-01-24 05:50:09 +00005616 // Transform the input expr.
5617 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005618 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005619 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005620 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005621
Anders Carlsson703e3942010-01-24 05:50:09 +00005622 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005623
John McCall9ae2f072010-08-23 23:25:46 +00005624 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005625 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005626
Anders Carlsson703e3942010-01-24 05:50:09 +00005627 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005628 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005629
5630 // Go through the clobbers.
5631 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005632 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005633
5634 // No need to transform the asm string literal.
5635 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005636 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5637 S->isVolatile(), S->getNumOutputs(),
5638 S->getNumInputs(), Names.data(),
5639 Constraints, Exprs, AsmString.get(),
5640 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005641}
5642
Chad Rosier8cd64b42012-06-11 20:47:18 +00005643template<typename Derived>
5644StmtResult
5645TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005646 ArrayRef<Token> AsmToks =
5647 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005648
Chad Rosier7bd092b2012-08-15 16:53:30 +00005649 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
5650 AsmToks, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005651}
Douglas Gregor43959a92009-08-20 07:17:43 +00005652
5653template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005654StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005655TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005656 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005657 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005658 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005659 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005660
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005661 // Transform the @catch statements (if present).
5662 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005663 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005664 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005665 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005666 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005667 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005668 if (Catch.get() != S->getCatchStmt(I))
5669 AnyCatchChanged = true;
5670 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005671 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005672
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005673 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005674 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005675 if (S->getFinallyStmt()) {
5676 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5677 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005678 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005679 }
5680
5681 // If nothing changed, just retain this statement.
5682 if (!getDerived().AlwaysRebuild() &&
5683 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005684 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005685 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005686 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005687
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005688 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005689 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005690 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005691}
Mike Stump1eb44332009-09-09 15:08:12 +00005692
Douglas Gregor43959a92009-08-20 07:17:43 +00005693template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005694StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005695TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005696 // Transform the @catch parameter, if there is one.
5697 VarDecl *Var = 0;
5698 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5699 TypeSourceInfo *TSInfo = 0;
5700 if (FromVar->getTypeSourceInfo()) {
5701 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5702 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005703 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005704 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005705
Douglas Gregorbe270a02010-04-26 17:57:08 +00005706 QualType T;
5707 if (TSInfo)
5708 T = TSInfo->getType();
5709 else {
5710 T = getDerived().TransformType(FromVar->getType());
5711 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005712 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005713 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005714
Douglas Gregorbe270a02010-04-26 17:57:08 +00005715 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5716 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005717 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005718 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005719
John McCall60d7b3a2010-08-24 06:29:42 +00005720 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005721 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005722 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005723
5724 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005725 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005726 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005727}
Mike Stump1eb44332009-09-09 15:08:12 +00005728
Douglas Gregor43959a92009-08-20 07:17:43 +00005729template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005730StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005731TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005732 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005733 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005734 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005735 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005736
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005737 // If nothing changed, just retain this statement.
5738 if (!getDerived().AlwaysRebuild() &&
5739 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005740 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005741
5742 // Build a new statement.
5743 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005744 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005745}
Mike Stump1eb44332009-09-09 15:08:12 +00005746
Douglas Gregor43959a92009-08-20 07:17:43 +00005747template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005748StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005749TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005750 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005751 if (S->getThrowExpr()) {
5752 Operand = getDerived().TransformExpr(S->getThrowExpr());
5753 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005754 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005755 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005756
Douglas Gregord1377b22010-04-22 21:44:01 +00005757 if (!getDerived().AlwaysRebuild() &&
5758 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005759 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005760
John McCall9ae2f072010-08-23 23:25:46 +00005761 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005762}
Mike Stump1eb44332009-09-09 15:08:12 +00005763
Douglas Gregor43959a92009-08-20 07:17:43 +00005764template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005765StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005766TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005767 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005768 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005769 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005770 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005771 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005772 Object =
5773 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5774 Object.get());
5775 if (Object.isInvalid())
5776 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005777
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005778 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005779 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005780 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005781 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005782
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005783 // If nothing change, just retain the current statement.
5784 if (!getDerived().AlwaysRebuild() &&
5785 Object.get() == S->getSynchExpr() &&
5786 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005787 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005788
5789 // Build a new statement.
5790 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005791 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005792}
5793
5794template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005795StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005796TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5797 ObjCAutoreleasePoolStmt *S) {
5798 // Transform the body.
5799 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5800 if (Body.isInvalid())
5801 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005802
John McCallf85e1932011-06-15 23:02:42 +00005803 // If nothing changed, just retain this statement.
5804 if (!getDerived().AlwaysRebuild() &&
5805 Body.get() == S->getSubStmt())
5806 return SemaRef.Owned(S);
5807
5808 // Build a new statement.
5809 return getDerived().RebuildObjCAutoreleasePoolStmt(
5810 S->getAtLoc(), Body.get());
5811}
5812
5813template<typename Derived>
5814StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005815TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005816 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005817 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005818 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005819 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005820 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005821
Douglas Gregorc3203e72010-04-22 23:10:45 +00005822 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005823 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005824 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005825 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005826
Douglas Gregorc3203e72010-04-22 23:10:45 +00005827 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005828 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005829 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005830 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005831
Douglas Gregorc3203e72010-04-22 23:10:45 +00005832 // If nothing changed, just retain this statement.
5833 if (!getDerived().AlwaysRebuild() &&
5834 Element.get() == S->getElement() &&
5835 Collection.get() == S->getCollection() &&
5836 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005837 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005838
Douglas Gregorc3203e72010-04-22 23:10:45 +00005839 // Build a new statement.
5840 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005841 Element.get(),
5842 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005843 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005844 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005845}
5846
5847
5848template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005849StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005850TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5851 // Transform the exception declaration, if any.
5852 VarDecl *Var = 0;
5853 if (S->getExceptionDecl()) {
5854 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005855 TypeSourceInfo *T = getDerived().TransformType(
5856 ExceptionDecl->getTypeSourceInfo());
5857 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005858 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005859
Douglas Gregor83cb9422010-09-09 17:09:21 +00005860 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005861 ExceptionDecl->getInnerLocStart(),
5862 ExceptionDecl->getLocation(),
5863 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005864 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005865 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005866 }
Mike Stump1eb44332009-09-09 15:08:12 +00005867
Douglas Gregor43959a92009-08-20 07:17:43 +00005868 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005869 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005870 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005871 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005872
Douglas Gregor43959a92009-08-20 07:17:43 +00005873 if (!getDerived().AlwaysRebuild() &&
5874 !Var &&
5875 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005876 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005877
5878 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5879 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005880 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005881}
Mike Stump1eb44332009-09-09 15:08:12 +00005882
Douglas Gregor43959a92009-08-20 07:17:43 +00005883template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005884StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005885TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5886 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005887 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005888 = getDerived().TransformCompoundStmt(S->getTryBlock());
5889 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005890 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005891
Douglas Gregor43959a92009-08-20 07:17:43 +00005892 // Transform the handlers.
5893 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005894 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00005895 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005896 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005897 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5898 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005899 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005900
Douglas Gregor43959a92009-08-20 07:17:43 +00005901 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5902 Handlers.push_back(Handler.takeAs<Stmt>());
5903 }
Mike Stump1eb44332009-09-09 15:08:12 +00005904
Douglas Gregor43959a92009-08-20 07:17:43 +00005905 if (!getDerived().AlwaysRebuild() &&
5906 TryBlock.get() == S->getTryBlock() &&
5907 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005908 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005909
John McCall9ae2f072010-08-23 23:25:46 +00005910 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005911 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00005912}
Mike Stump1eb44332009-09-09 15:08:12 +00005913
Richard Smithad762fc2011-04-14 22:09:26 +00005914template<typename Derived>
5915StmtResult
5916TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5917 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5918 if (Range.isInvalid())
5919 return StmtError();
5920
5921 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5922 if (BeginEnd.isInvalid())
5923 return StmtError();
5924
5925 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5926 if (Cond.isInvalid())
5927 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005928 if (Cond.get())
5929 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5930 if (Cond.isInvalid())
5931 return StmtError();
5932 if (Cond.get())
5933 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005934
5935 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5936 if (Inc.isInvalid())
5937 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005938 if (Inc.get())
5939 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005940
5941 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5942 if (LoopVar.isInvalid())
5943 return StmtError();
5944
5945 StmtResult NewStmt = S;
5946 if (getDerived().AlwaysRebuild() ||
5947 Range.get() != S->getRangeStmt() ||
5948 BeginEnd.get() != S->getBeginEndStmt() ||
5949 Cond.get() != S->getCond() ||
5950 Inc.get() != S->getInc() ||
5951 LoopVar.get() != S->getLoopVarStmt())
5952 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5953 S->getColonLoc(), Range.get(),
5954 BeginEnd.get(), Cond.get(),
5955 Inc.get(), LoopVar.get(),
5956 S->getRParenLoc());
5957
5958 StmtResult Body = getDerived().TransformStmt(S->getBody());
5959 if (Body.isInvalid())
5960 return StmtError();
5961
5962 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5963 // it now so we have a new statement to attach the body to.
5964 if (Body.get() != S->getBody() && NewStmt.get() == S)
5965 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5966 S->getColonLoc(), Range.get(),
5967 BeginEnd.get(), Cond.get(),
5968 Inc.get(), LoopVar.get(),
5969 S->getRParenLoc());
5970
5971 if (NewStmt.get() == S)
5972 return SemaRef.Owned(S);
5973
5974 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5975}
5976
John Wiegley28bbe4b2011-04-28 01:08:34 +00005977template<typename Derived>
5978StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005979TreeTransform<Derived>::TransformMSDependentExistsStmt(
5980 MSDependentExistsStmt *S) {
5981 // Transform the nested-name-specifier, if any.
5982 NestedNameSpecifierLoc QualifierLoc;
5983 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005984 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00005985 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5986 if (!QualifierLoc)
5987 return StmtError();
5988 }
5989
5990 // Transform the declaration name.
5991 DeclarationNameInfo NameInfo = S->getNameInfo();
5992 if (NameInfo.getName()) {
5993 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5994 if (!NameInfo.getName())
5995 return StmtError();
5996 }
5997
5998 // Check whether anything changed.
5999 if (!getDerived().AlwaysRebuild() &&
6000 QualifierLoc == S->getQualifierLoc() &&
6001 NameInfo.getName() == S->getNameInfo().getName())
6002 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006003
Douglas Gregorba0513d2011-10-25 01:33:02 +00006004 // Determine whether this name exists, if we can.
6005 CXXScopeSpec SS;
6006 SS.Adopt(QualifierLoc);
6007 bool Dependent = false;
6008 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
6009 case Sema::IER_Exists:
6010 if (S->isIfExists())
6011 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006012
Douglas Gregorba0513d2011-10-25 01:33:02 +00006013 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6014
6015 case Sema::IER_DoesNotExist:
6016 if (S->isIfNotExists())
6017 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006018
Douglas Gregorba0513d2011-10-25 01:33:02 +00006019 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006020
Douglas Gregorba0513d2011-10-25 01:33:02 +00006021 case Sema::IER_Dependent:
6022 Dependent = true;
6023 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006024
Douglas Gregor65019ac2011-10-25 03:44:56 +00006025 case Sema::IER_Error:
6026 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006027 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006028
Douglas Gregorba0513d2011-10-25 01:33:02 +00006029 // We need to continue with the instantiation, so do so now.
6030 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6031 if (SubStmt.isInvalid())
6032 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006033
Douglas Gregorba0513d2011-10-25 01:33:02 +00006034 // If we have resolved the name, just transform to the substatement.
6035 if (!Dependent)
6036 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006037
Douglas Gregorba0513d2011-10-25 01:33:02 +00006038 // The name is still dependent, so build a dependent expression again.
6039 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6040 S->isIfExists(),
6041 QualifierLoc,
6042 NameInfo,
6043 SubStmt.get());
6044}
6045
6046template<typename Derived>
John McCall76da55d2013-04-16 07:28:30 +00006047ExprResult
6048TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6049 NestedNameSpecifierLoc QualifierLoc;
6050 if (E->getQualifierLoc()) {
6051 QualifierLoc
6052 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6053 if (!QualifierLoc)
6054 return ExprError();
6055 }
6056
6057 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6058 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6059 if (!PD)
6060 return ExprError();
6061
6062 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6063 if (Base.isInvalid())
6064 return ExprError();
6065
6066 return new (SemaRef.getASTContext())
6067 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6068 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6069 QualifierLoc, E->getMemberLoc());
6070}
6071
6072template<typename Derived>
Douglas Gregorba0513d2011-10-25 01:33:02 +00006073StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006074TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6075 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6076 if(TryBlock.isInvalid()) return StmtError();
6077
6078 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6079 if(!getDerived().AlwaysRebuild() &&
6080 TryBlock.get() == S->getTryBlock() &&
6081 Handler.get() == S->getHandler())
6082 return SemaRef.Owned(S);
6083
6084 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6085 S->getTryLoc(),
6086 TryBlock.take(),
6087 Handler.take());
6088}
6089
6090template<typename Derived>
6091StmtResult
6092TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6093 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6094 if(Block.isInvalid()) return StmtError();
6095
6096 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6097 Block.take());
6098}
6099
6100template<typename Derived>
6101StmtResult
6102TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6103 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6104 if(FilterExpr.isInvalid()) return StmtError();
6105
6106 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6107 if(Block.isInvalid()) return StmtError();
6108
6109 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6110 FilterExpr.take(),
6111 Block.take());
6112}
6113
6114template<typename Derived>
6115StmtResult
6116TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6117 if(isa<SEHFinallyStmt>(Handler))
6118 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6119 else
6120 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6121}
6122
Douglas Gregor43959a92009-08-20 07:17:43 +00006123//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006124// Expression transformation
6125//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006126template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006127ExprResult
John McCall454feb92009-12-08 09:21:05 +00006128TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006129 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006130}
Mike Stump1eb44332009-09-09 15:08:12 +00006131
6132template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006133ExprResult
John McCall454feb92009-12-08 09:21:05 +00006134TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006135 NestedNameSpecifierLoc QualifierLoc;
6136 if (E->getQualifierLoc()) {
6137 QualifierLoc
6138 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6139 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006140 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006141 }
John McCalldbd872f2009-12-08 09:08:17 +00006142
6143 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006144 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6145 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006146 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006147 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006148
John McCallec8045d2010-08-17 21:27:17 +00006149 DeclarationNameInfo NameInfo = E->getNameInfo();
6150 if (NameInfo.getName()) {
6151 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6152 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006153 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006154 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006155
6156 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006157 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006158 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006159 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006160 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006161
6162 // Mark it referenced in the new context regardless.
6163 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006164 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006165
John McCall3fa5cae2010-10-26 07:05:15 +00006166 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006167 }
John McCalldbd872f2009-12-08 09:08:17 +00006168
6169 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006170 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006171 TemplateArgs = &TransArgs;
6172 TransArgs.setLAngleLoc(E->getLAngleLoc());
6173 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006174 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6175 E->getNumTemplateArgs(),
6176 TransArgs))
6177 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006178 }
6179
Chad Rosier4a9d7952012-08-08 18:46:20 +00006180 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006181 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006182}
Mike Stump1eb44332009-09-09 15:08:12 +00006183
Douglas Gregorb98b1992009-08-11 05:31:07 +00006184template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006185ExprResult
John McCall454feb92009-12-08 09:21:05 +00006186TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006187 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006188}
Mike Stump1eb44332009-09-09 15:08:12 +00006189
Douglas Gregorb98b1992009-08-11 05:31:07 +00006190template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006191ExprResult
John McCall454feb92009-12-08 09:21:05 +00006192TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006193 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006194}
Mike Stump1eb44332009-09-09 15:08:12 +00006195
Douglas Gregorb98b1992009-08-11 05:31:07 +00006196template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006197ExprResult
John McCall454feb92009-12-08 09:21:05 +00006198TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006199 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006200}
Mike Stump1eb44332009-09-09 15:08:12 +00006201
Douglas Gregorb98b1992009-08-11 05:31:07 +00006202template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006203ExprResult
John McCall454feb92009-12-08 09:21:05 +00006204TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006205 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006206}
Mike Stump1eb44332009-09-09 15:08:12 +00006207
Douglas Gregorb98b1992009-08-11 05:31:07 +00006208template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006209ExprResult
John McCall454feb92009-12-08 09:21:05 +00006210TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006211 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006212}
6213
6214template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006215ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006216TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis391ca9f2013-04-09 01:17:02 +00006217 if (FunctionDecl *FD = E->getDirectCallee())
6218 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smith9fcce652012-03-07 08:35:16 +00006219 return SemaRef.MaybeBindToTemporary(E);
6220}
6221
6222template<typename Derived>
6223ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006224TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6225 ExprResult ControllingExpr =
6226 getDerived().TransformExpr(E->getControllingExpr());
6227 if (ControllingExpr.isInvalid())
6228 return ExprError();
6229
Chris Lattner686775d2011-07-20 06:58:45 +00006230 SmallVector<Expr *, 4> AssocExprs;
6231 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006232 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6233 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6234 if (TS) {
6235 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6236 if (!AssocType)
6237 return ExprError();
6238 AssocTypes.push_back(AssocType);
6239 } else {
6240 AssocTypes.push_back(0);
6241 }
6242
6243 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6244 if (AssocExpr.isInvalid())
6245 return ExprError();
6246 AssocExprs.push_back(AssocExpr.release());
6247 }
6248
6249 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6250 E->getDefaultLoc(),
6251 E->getRParenLoc(),
6252 ControllingExpr.release(),
6253 AssocTypes.data(),
6254 AssocExprs.data(),
6255 E->getNumAssocs());
6256}
6257
6258template<typename Derived>
6259ExprResult
John McCall454feb92009-12-08 09:21:05 +00006260TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006261 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006262 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006263 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006264
Douglas Gregorb98b1992009-08-11 05:31:07 +00006265 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006266 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006267
John McCall9ae2f072010-08-23 23:25:46 +00006268 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006269 E->getRParen());
6270}
6271
Richard Smithefeeccf2012-10-21 03:28:35 +00006272/// \brief The operand of a unary address-of operator has special rules: it's
6273/// allowed to refer to a non-static member of a class even if there's no 'this'
6274/// object available.
6275template<typename Derived>
6276ExprResult
6277TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6278 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6279 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6280 else
6281 return getDerived().TransformExpr(E);
6282}
6283
Mike Stump1eb44332009-09-09 15:08:12 +00006284template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006285ExprResult
John McCall454feb92009-12-08 09:21:05 +00006286TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00006287 ExprResult SubExpr = TransformAddressOfOperand(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006288 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006289 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006290
Douglas Gregorb98b1992009-08-11 05:31:07 +00006291 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006292 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006293
Douglas Gregorb98b1992009-08-11 05:31:07 +00006294 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6295 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006296 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006297}
Mike Stump1eb44332009-09-09 15:08:12 +00006298
Douglas Gregorb98b1992009-08-11 05:31:07 +00006299template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006300ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006301TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6302 // Transform the type.
6303 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6304 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006305 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006306
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006307 // Transform all of the components into components similar to what the
6308 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006309 // FIXME: It would be slightly more efficient in the non-dependent case to
6310 // just map FieldDecls, rather than requiring the rebuilder to look for
6311 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006312 // template code that we don't care.
6313 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006314 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006315 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006316 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006317 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6318 const Node &ON = E->getComponent(I);
6319 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006320 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006321 Comp.LocStart = ON.getSourceRange().getBegin();
6322 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006323 switch (ON.getKind()) {
6324 case Node::Array: {
6325 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006326 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006327 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006328 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006329
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006330 ExprChanged = ExprChanged || Index.get() != FromIndex;
6331 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006332 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006333 break;
6334 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006335
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006336 case Node::Field:
6337 case Node::Identifier:
6338 Comp.isBrackets = false;
6339 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006340 if (!Comp.U.IdentInfo)
6341 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006342
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006343 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006344
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006345 case Node::Base:
6346 // Will be recomputed during the rebuild.
6347 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006348 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006349
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006350 Components.push_back(Comp);
6351 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006352
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006353 // If nothing changed, retain the existing expression.
6354 if (!getDerived().AlwaysRebuild() &&
6355 Type == E->getTypeSourceInfo() &&
6356 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006357 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006358
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006359 // Build a new offsetof expression.
6360 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6361 Components.data(), Components.size(),
6362 E->getRParenLoc());
6363}
6364
6365template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006366ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006367TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6368 assert(getDerived().AlreadyTransformed(E->getType()) &&
6369 "opaque value expression requires transformation");
6370 return SemaRef.Owned(E);
6371}
6372
6373template<typename Derived>
6374ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006375TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006376 // Rebuild the syntactic form. The original syntactic form has
6377 // opaque-value expressions in it, so strip those away and rebuild
6378 // the result. This is a really awful way of doing this, but the
6379 // better solution (rebuilding the semantic expressions and
6380 // rebinding OVEs as necessary) doesn't work; we'd need
6381 // TreeTransform to not strip away implicit conversions.
6382 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6383 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006384 if (result.isInvalid()) return ExprError();
6385
6386 // If that gives us a pseudo-object result back, the pseudo-object
6387 // expression must have been an lvalue-to-rvalue conversion which we
6388 // should reapply.
6389 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6390 result = SemaRef.checkPseudoObjectRValue(result.take());
6391
6392 return result;
6393}
6394
6395template<typename Derived>
6396ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006397TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6398 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006399 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006400 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006401
John McCalla93c9342009-12-07 02:54:59 +00006402 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006403 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006404 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006405
John McCall5ab75172009-11-04 07:28:41 +00006406 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006407 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006408
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006409 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6410 E->getKind(),
6411 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006412 }
Mike Stump1eb44332009-09-09 15:08:12 +00006413
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006414 // C++0x [expr.sizeof]p1:
6415 // The operand is either an expression, which is an unevaluated operand
6416 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006417 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6418 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006419
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006420 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6421 if (SubExpr.isInvalid())
6422 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006423
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006424 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6425 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006426
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006427 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6428 E->getOperatorLoc(),
6429 E->getKind(),
6430 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006431}
Mike Stump1eb44332009-09-09 15:08:12 +00006432
Douglas Gregorb98b1992009-08-11 05:31:07 +00006433template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006434ExprResult
John McCall454feb92009-12-08 09:21:05 +00006435TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006436 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006437 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006438 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006439
John McCall60d7b3a2010-08-24 06:29:42 +00006440 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006441 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006442 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006443
6444
Douglas Gregorb98b1992009-08-11 05:31:07 +00006445 if (!getDerived().AlwaysRebuild() &&
6446 LHS.get() == E->getLHS() &&
6447 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006448 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006449
John McCall9ae2f072010-08-23 23:25:46 +00006450 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006451 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006452 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006453 E->getRBracketLoc());
6454}
Mike Stump1eb44332009-09-09 15:08:12 +00006455
6456template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006457ExprResult
John McCall454feb92009-12-08 09:21:05 +00006458TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006459 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006460 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006461 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006462 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006463
6464 // Transform arguments.
6465 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006466 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006467 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006468 &ArgChanged))
6469 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006470
Douglas Gregorb98b1992009-08-11 05:31:07 +00006471 if (!getDerived().AlwaysRebuild() &&
6472 Callee.get() == E->getCallee() &&
6473 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006474 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006475
Douglas Gregorb98b1992009-08-11 05:31:07 +00006476 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006477 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006478 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006479 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006480 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006481 E->getRParenLoc());
6482}
Mike Stump1eb44332009-09-09 15:08:12 +00006483
6484template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006485ExprResult
John McCall454feb92009-12-08 09:21:05 +00006486TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006487 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006488 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006489 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006490
Douglas Gregor40d96a62011-02-28 21:54:11 +00006491 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006492 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006493 QualifierLoc
6494 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006495
Douglas Gregor40d96a62011-02-28 21:54:11 +00006496 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006497 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006498 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006499 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006500
Eli Friedmanf595cc42009-12-04 06:40:45 +00006501 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006502 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6503 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006504 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006505 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006506
John McCall6bb80172010-03-30 21:47:33 +00006507 NamedDecl *FoundDecl = E->getFoundDecl();
6508 if (FoundDecl == E->getMemberDecl()) {
6509 FoundDecl = Member;
6510 } else {
6511 FoundDecl = cast_or_null<NamedDecl>(
6512 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6513 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006514 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006515 }
6516
Douglas Gregorb98b1992009-08-11 05:31:07 +00006517 if (!getDerived().AlwaysRebuild() &&
6518 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006519 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006520 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006521 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006522 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006523
Anders Carlsson1f240322009-12-22 05:24:09 +00006524 // Mark it referenced in the new context regardless.
6525 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006526 SemaRef.MarkMemberReferenced(E);
6527
John McCall3fa5cae2010-10-26 07:05:15 +00006528 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006529 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006530
John McCalld5532b62009-11-23 01:53:49 +00006531 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006532 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006533 TransArgs.setLAngleLoc(E->getLAngleLoc());
6534 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006535 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6536 E->getNumTemplateArgs(),
6537 TransArgs))
6538 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006539 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006540
Douglas Gregorb98b1992009-08-11 05:31:07 +00006541 // FIXME: Bogus source location for the operator
6542 SourceLocation FakeOperatorLoc
6543 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6544
John McCallc2233c52010-01-15 08:34:02 +00006545 // FIXME: to do this check properly, we will need to preserve the
6546 // first-qualifier-in-scope here, just in case we had a dependent
6547 // base (and therefore couldn't do the check) and a
6548 // nested-name-qualifier (and therefore could do the lookup).
6549 NamedDecl *FirstQualifierInScope = 0;
6550
John McCall9ae2f072010-08-23 23:25:46 +00006551 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006552 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006553 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006554 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006555 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006556 Member,
John McCall6bb80172010-03-30 21:47:33 +00006557 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006558 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006559 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006560 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006561}
Mike Stump1eb44332009-09-09 15:08:12 +00006562
Douglas Gregorb98b1992009-08-11 05:31:07 +00006563template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006564ExprResult
John McCall454feb92009-12-08 09:21:05 +00006565TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006566 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006567 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006568 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006569
John McCall60d7b3a2010-08-24 06:29:42 +00006570 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006571 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006572 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006573
Douglas Gregorb98b1992009-08-11 05:31:07 +00006574 if (!getDerived().AlwaysRebuild() &&
6575 LHS.get() == E->getLHS() &&
6576 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006577 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006578
Lang Hamesbe9af122012-10-02 04:45:10 +00006579 Sema::FPContractStateRAII FPContractState(getSema());
6580 getSema().FPFeatures.fp_contract = E->isFPContractable();
6581
Douglas Gregorb98b1992009-08-11 05:31:07 +00006582 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006583 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006584}
6585
Mike Stump1eb44332009-09-09 15:08:12 +00006586template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006587ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006588TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006589 CompoundAssignOperator *E) {
6590 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006591}
Mike Stump1eb44332009-09-09 15:08:12 +00006592
Douglas Gregorb98b1992009-08-11 05:31:07 +00006593template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006594ExprResult TreeTransform<Derived>::
6595TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6596 // Just rebuild the common and RHS expressions and see whether we
6597 // get any changes.
6598
6599 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6600 if (commonExpr.isInvalid())
6601 return ExprError();
6602
6603 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6604 if (rhs.isInvalid())
6605 return ExprError();
6606
6607 if (!getDerived().AlwaysRebuild() &&
6608 commonExpr.get() == e->getCommon() &&
6609 rhs.get() == e->getFalseExpr())
6610 return SemaRef.Owned(e);
6611
6612 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6613 e->getQuestionLoc(),
6614 0,
6615 e->getColonLoc(),
6616 rhs.get());
6617}
6618
6619template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006620ExprResult
John McCall454feb92009-12-08 09:21:05 +00006621TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006622 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006623 if (Cond.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 LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006627 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006628 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006629
John McCall60d7b3a2010-08-24 06:29:42 +00006630 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006631 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006632 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006633
Douglas Gregorb98b1992009-08-11 05:31:07 +00006634 if (!getDerived().AlwaysRebuild() &&
6635 Cond.get() == E->getCond() &&
6636 LHS.get() == E->getLHS() &&
6637 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006638 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006639
John McCall9ae2f072010-08-23 23:25:46 +00006640 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006641 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006642 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006643 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006644 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006645}
Mike Stump1eb44332009-09-09 15:08:12 +00006646
6647template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006648ExprResult
John McCall454feb92009-12-08 09:21:05 +00006649TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006650 // Implicit casts are eliminated during transformation, since they
6651 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006652 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006653}
Mike Stump1eb44332009-09-09 15:08:12 +00006654
Douglas Gregorb98b1992009-08-11 05:31:07 +00006655template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006656ExprResult
John McCall454feb92009-12-08 09:21:05 +00006657TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006658 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6659 if (!Type)
6660 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006661
John McCall60d7b3a2010-08-24 06:29:42 +00006662 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006663 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006664 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006665 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006666
Douglas Gregorb98b1992009-08-11 05:31:07 +00006667 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006668 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006669 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006670 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006671
John McCall9d125032010-01-15 18:39:57 +00006672 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006673 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006674 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006675 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006676}
Mike Stump1eb44332009-09-09 15:08:12 +00006677
Douglas Gregorb98b1992009-08-11 05:31:07 +00006678template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006679ExprResult
John McCall454feb92009-12-08 09:21:05 +00006680TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006681 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6682 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6683 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006684 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006685
John McCall60d7b3a2010-08-24 06:29:42 +00006686 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006687 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006688 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006689
Douglas Gregorb98b1992009-08-11 05:31:07 +00006690 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006691 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006692 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006693 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006694
John McCall1d7d8d62010-01-19 22:33:45 +00006695 // Note: the expression type doesn't necessarily match the
6696 // type-as-written, but that's okay, because it should always be
6697 // derivable from the initializer.
6698
John McCall42f56b52010-01-18 19:35:47 +00006699 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006700 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006701 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006702}
Mike Stump1eb44332009-09-09 15:08:12 +00006703
Douglas Gregorb98b1992009-08-11 05:31:07 +00006704template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006705ExprResult
John McCall454feb92009-12-08 09:21:05 +00006706TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006707 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006708 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006709 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006710
Douglas Gregorb98b1992009-08-11 05:31:07 +00006711 if (!getDerived().AlwaysRebuild() &&
6712 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006713 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006714
Douglas Gregorb98b1992009-08-11 05:31:07 +00006715 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006716 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006717 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006718 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006719 E->getAccessorLoc(),
6720 E->getAccessor());
6721}
Mike Stump1eb44332009-09-09 15:08:12 +00006722
Douglas Gregorb98b1992009-08-11 05:31:07 +00006723template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006724ExprResult
John McCall454feb92009-12-08 09:21:05 +00006725TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006726 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006727
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006728 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006729 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006730 Inits, &InitChanged))
6731 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006732
Douglas Gregorb98b1992009-08-11 05:31:07 +00006733 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006734 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006735
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006736 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006737 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006738}
Mike Stump1eb44332009-09-09 15:08:12 +00006739
Douglas Gregorb98b1992009-08-11 05:31:07 +00006740template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006741ExprResult
John McCall454feb92009-12-08 09:21:05 +00006742TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006743 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006744
Douglas Gregor43959a92009-08-20 07:17:43 +00006745 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006746 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006747 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006748 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006749
Douglas Gregor43959a92009-08-20 07:17:43 +00006750 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006751 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006752 bool ExprChanged = false;
6753 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6754 DEnd = E->designators_end();
6755 D != DEnd; ++D) {
6756 if (D->isFieldDesignator()) {
6757 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6758 D->getDotLoc(),
6759 D->getFieldLoc()));
6760 continue;
6761 }
Mike Stump1eb44332009-09-09 15:08:12 +00006762
Douglas Gregorb98b1992009-08-11 05:31:07 +00006763 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006764 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006765 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006766 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006767
6768 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006769 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006770
Douglas Gregorb98b1992009-08-11 05:31:07 +00006771 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6772 ArrayExprs.push_back(Index.release());
6773 continue;
6774 }
Mike Stump1eb44332009-09-09 15:08:12 +00006775
Douglas Gregorb98b1992009-08-11 05:31:07 +00006776 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006777 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006778 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6779 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006780 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006781
John McCall60d7b3a2010-08-24 06:29:42 +00006782 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006783 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006784 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006785
6786 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006787 End.get(),
6788 D->getLBracketLoc(),
6789 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006790
Douglas Gregorb98b1992009-08-11 05:31:07 +00006791 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6792 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006793
Douglas Gregorb98b1992009-08-11 05:31:07 +00006794 ArrayExprs.push_back(Start.release());
6795 ArrayExprs.push_back(End.release());
6796 }
Mike Stump1eb44332009-09-09 15:08:12 +00006797
Douglas Gregorb98b1992009-08-11 05:31:07 +00006798 if (!getDerived().AlwaysRebuild() &&
6799 Init.get() == E->getInit() &&
6800 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006801 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006802
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006803 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006804 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006805 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006806}
Mike Stump1eb44332009-09-09 15:08:12 +00006807
Douglas Gregorb98b1992009-08-11 05:31:07 +00006808template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006809ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006810TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006811 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006812 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006813
Douglas Gregor5557b252009-10-28 00:29:27 +00006814 // FIXME: Will we ever have proper type location here? Will we actually
6815 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006816 QualType T = getDerived().TransformType(E->getType());
6817 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006818 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006819
Douglas Gregorb98b1992009-08-11 05:31:07 +00006820 if (!getDerived().AlwaysRebuild() &&
6821 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006822 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006823
Douglas Gregorb98b1992009-08-11 05:31:07 +00006824 return getDerived().RebuildImplicitValueInitExpr(T);
6825}
Mike Stump1eb44332009-09-09 15:08:12 +00006826
Douglas Gregorb98b1992009-08-11 05:31:07 +00006827template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006828ExprResult
John McCall454feb92009-12-08 09:21:05 +00006829TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006830 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6831 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006832 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006833
John McCall60d7b3a2010-08-24 06:29:42 +00006834 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006835 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006836 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006837
Douglas Gregorb98b1992009-08-11 05:31:07 +00006838 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006839 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006840 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006841 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006842
John McCall9ae2f072010-08-23 23:25:46 +00006843 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006844 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006845}
6846
6847template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006848ExprResult
John McCall454feb92009-12-08 09:21:05 +00006849TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006850 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006851 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00006852 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6853 &ArgumentChanged))
6854 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006855
Douglas Gregorb98b1992009-08-11 05:31:07 +00006856 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006857 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006858 E->getRParenLoc());
6859}
Mike Stump1eb44332009-09-09 15:08:12 +00006860
Douglas Gregorb98b1992009-08-11 05:31:07 +00006861/// \brief Transform an address-of-label expression.
6862///
6863/// By default, the transformation of an address-of-label expression always
6864/// rebuilds the expression, so that the label identifier can be resolved to
6865/// the corresponding label statement by semantic analysis.
6866template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006867ExprResult
John McCall454feb92009-12-08 09:21:05 +00006868TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006869 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6870 E->getLabel());
6871 if (!LD)
6872 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006873
Douglas Gregorb98b1992009-08-11 05:31:07 +00006874 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006875 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006876}
Mike Stump1eb44332009-09-09 15:08:12 +00006877
6878template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006879ExprResult
John McCall454feb92009-12-08 09:21:05 +00006880TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006881 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006882 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006883 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006884 if (SubStmt.isInvalid()) {
6885 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006886 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006887 }
Mike Stump1eb44332009-09-09 15:08:12 +00006888
Douglas Gregorb98b1992009-08-11 05:31:07 +00006889 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006890 SubStmt.get() == E->getSubStmt()) {
6891 // Calling this an 'error' is unintuitive, but it does the right thing.
6892 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006893 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006894 }
Mike Stump1eb44332009-09-09 15:08:12 +00006895
6896 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006897 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006898 E->getRParenLoc());
6899}
Mike Stump1eb44332009-09-09 15:08:12 +00006900
Douglas Gregorb98b1992009-08-11 05:31:07 +00006901template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006902ExprResult
John McCall454feb92009-12-08 09:21:05 +00006903TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006904 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006905 if (Cond.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 LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006909 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006910 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006911
John McCall60d7b3a2010-08-24 06:29:42 +00006912 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006913 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006914 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006915
Douglas Gregorb98b1992009-08-11 05:31:07 +00006916 if (!getDerived().AlwaysRebuild() &&
6917 Cond.get() == E->getCond() &&
6918 LHS.get() == E->getLHS() &&
6919 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006920 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006921
Douglas Gregorb98b1992009-08-11 05:31:07 +00006922 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006923 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006924 E->getRParenLoc());
6925}
Mike Stump1eb44332009-09-09 15:08:12 +00006926
Douglas Gregorb98b1992009-08-11 05:31:07 +00006927template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006928ExprResult
John McCall454feb92009-12-08 09:21:05 +00006929TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006930 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006931}
6932
6933template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006934ExprResult
John McCall454feb92009-12-08 09:21:05 +00006935TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006936 switch (E->getOperator()) {
6937 case OO_New:
6938 case OO_Delete:
6939 case OO_Array_New:
6940 case OO_Array_Delete:
6941 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006942
Douglas Gregor668d6d92009-12-13 20:44:55 +00006943 case OO_Call: {
6944 // This is a call to an object's operator().
6945 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6946
6947 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006948 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006949 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006950 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006951
6952 // FIXME: Poor location information
6953 SourceLocation FakeLParenLoc
6954 = SemaRef.PP.getLocForEndOfToken(
6955 static_cast<Expr *>(Object.get())->getLocEnd());
6956
6957 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006958 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006959 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006960 Args))
6961 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006962
John McCall9ae2f072010-08-23 23:25:46 +00006963 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006964 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006965 E->getLocEnd());
6966 }
6967
6968#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6969 case OO_##Name:
6970#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6971#include "clang/Basic/OperatorKinds.def"
6972 case OO_Subscript:
6973 // Handled below.
6974 break;
6975
6976 case OO_Conditional:
6977 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006978
6979 case OO_None:
6980 case NUM_OVERLOADED_OPERATORS:
6981 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006982 }
6983
John McCall60d7b3a2010-08-24 06:29:42 +00006984 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006985 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006986 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006987
Richard Smithefeeccf2012-10-21 03:28:35 +00006988 ExprResult First;
6989 if (E->getOperator() == OO_Amp)
6990 First = getDerived().TransformAddressOfOperand(E->getArg(0));
6991 else
6992 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006993 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006994 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006995
John McCall60d7b3a2010-08-24 06:29:42 +00006996 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006997 if (E->getNumArgs() == 2) {
6998 Second = getDerived().TransformExpr(E->getArg(1));
6999 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007000 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007001 }
Mike Stump1eb44332009-09-09 15:08:12 +00007002
Douglas Gregorb98b1992009-08-11 05:31:07 +00007003 if (!getDerived().AlwaysRebuild() &&
7004 Callee.get() == E->getCallee() &&
7005 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00007006 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00007007 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007008
Lang Hamesbe9af122012-10-02 04:45:10 +00007009 Sema::FPContractStateRAII FPContractState(getSema());
7010 getSema().FPFeatures.fp_contract = E->isFPContractable();
7011
Douglas Gregorb98b1992009-08-11 05:31:07 +00007012 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
7013 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00007014 Callee.get(),
7015 First.get(),
7016 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007017}
Mike Stump1eb44332009-09-09 15:08:12 +00007018
Douglas Gregorb98b1992009-08-11 05:31:07 +00007019template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007020ExprResult
John McCall454feb92009-12-08 09:21:05 +00007021TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
7022 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007023}
Mike Stump1eb44332009-09-09 15:08:12 +00007024
Douglas Gregorb98b1992009-08-11 05:31:07 +00007025template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007026ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00007027TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
7028 // Transform the callee.
7029 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
7030 if (Callee.isInvalid())
7031 return ExprError();
7032
7033 // Transform exec config.
7034 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
7035 if (EC.isInvalid())
7036 return ExprError();
7037
7038 // Transform arguments.
7039 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007040 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007041 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007042 &ArgChanged))
7043 return ExprError();
7044
7045 if (!getDerived().AlwaysRebuild() &&
7046 Callee.get() == E->getCallee() &&
7047 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007048 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00007049
7050 // FIXME: Wrong source location information for the '('.
7051 SourceLocation FakeLParenLoc
7052 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7053 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007054 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007055 E->getRParenLoc(), EC.get());
7056}
7057
7058template<typename Derived>
7059ExprResult
John McCall454feb92009-12-08 09:21:05 +00007060TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007061 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7062 if (!Type)
7063 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007064
John McCall60d7b3a2010-08-24 06:29:42 +00007065 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007066 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007067 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007068 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007069
Douglas Gregorb98b1992009-08-11 05:31:07 +00007070 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007071 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007072 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007073 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007074 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007075 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007076 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007077 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007078 E->getAngleBrackets().getEnd(),
7079 // FIXME. this should be '(' location
7080 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007081 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007082 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007083}
Mike Stump1eb44332009-09-09 15:08:12 +00007084
Douglas Gregorb98b1992009-08-11 05:31:07 +00007085template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007086ExprResult
John McCall454feb92009-12-08 09:21:05 +00007087TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7088 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007089}
Mike Stump1eb44332009-09-09 15:08:12 +00007090
7091template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007092ExprResult
John McCall454feb92009-12-08 09:21:05 +00007093TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7094 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007095}
7096
Douglas Gregorb98b1992009-08-11 05:31:07 +00007097template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007098ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007099TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007100 CXXReinterpretCastExpr *E) {
7101 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007102}
Mike Stump1eb44332009-09-09 15:08:12 +00007103
Douglas Gregorb98b1992009-08-11 05:31:07 +00007104template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007105ExprResult
John McCall454feb92009-12-08 09:21:05 +00007106TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7107 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007108}
Mike Stump1eb44332009-09-09 15:08:12 +00007109
Douglas Gregorb98b1992009-08-11 05:31:07 +00007110template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007111ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007112TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007113 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007114 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7115 if (!Type)
7116 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007117
John McCall60d7b3a2010-08-24 06:29:42 +00007118 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007119 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007120 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007121 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007122
Douglas Gregorb98b1992009-08-11 05:31:07 +00007123 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007124 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007125 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007126 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007127
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007128 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007129 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007130 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007131 E->getRParenLoc());
7132}
Mike Stump1eb44332009-09-09 15:08:12 +00007133
Douglas Gregorb98b1992009-08-11 05:31:07 +00007134template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007135ExprResult
John McCall454feb92009-12-08 09:21:05 +00007136TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007137 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007138 TypeSourceInfo *TInfo
7139 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7140 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007141 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007142
Douglas Gregorb98b1992009-08-11 05:31:07 +00007143 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007144 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007145 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007146
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007147 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7148 E->getLocStart(),
7149 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007150 E->getLocEnd());
7151 }
Mike Stump1eb44332009-09-09 15:08:12 +00007152
Eli Friedmanef331b72012-01-20 01:26:23 +00007153 // We don't know whether the subexpression is potentially evaluated until
7154 // after we perform semantic analysis. We speculatively assume it is
7155 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007156 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007157 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7158 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007159
John McCall60d7b3a2010-08-24 06:29:42 +00007160 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007161 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007162 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007163
Douglas Gregorb98b1992009-08-11 05:31:07 +00007164 if (!getDerived().AlwaysRebuild() &&
7165 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007166 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007167
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007168 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7169 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007170 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007171 E->getLocEnd());
7172}
7173
7174template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007175ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007176TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7177 if (E->isTypeOperand()) {
7178 TypeSourceInfo *TInfo
7179 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7180 if (!TInfo)
7181 return ExprError();
7182
7183 if (!getDerived().AlwaysRebuild() &&
7184 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007185 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007186
Douglas Gregor3c52a212011-03-06 17:40:41 +00007187 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007188 E->getLocStart(),
7189 TInfo,
7190 E->getLocEnd());
7191 }
7192
Francois Pichet01b7c302010-09-08 12:20:18 +00007193 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7194
7195 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7196 if (SubExpr.isInvalid())
7197 return ExprError();
7198
7199 if (!getDerived().AlwaysRebuild() &&
7200 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007201 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007202
7203 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7204 E->getLocStart(),
7205 SubExpr.get(),
7206 E->getLocEnd());
7207}
7208
7209template<typename Derived>
7210ExprResult
John McCall454feb92009-12-08 09:21:05 +00007211TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007212 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007213}
Mike Stump1eb44332009-09-09 15:08:12 +00007214
Douglas Gregorb98b1992009-08-11 05:31:07 +00007215template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007216ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007217TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007218 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007219 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007220}
Mike Stump1eb44332009-09-09 15:08:12 +00007221
Douglas Gregorb98b1992009-08-11 05:31:07 +00007222template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007223ExprResult
John McCall454feb92009-12-08 09:21:05 +00007224TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007225 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007226 QualType T;
7227 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7228 T = MD->getThisType(getSema().Context);
Douglas Gregore4743be2013-03-08 22:43:48 +00007229 else if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(DC)) {
Richard Smith7a614d82011-06-11 17:19:42 +00007230 T = getSema().Context.getPointerType(
Douglas Gregore4743be2013-03-08 22:43:48 +00007231 getSema().Context.getRecordType(Record));
7232 } else {
7233 assert(SemaRef.Context.getDiagnostics().hasErrorOccurred() &&
7234 "this in the wrong scope?");
7235 return ExprError();
7236 }
Mike Stump1eb44332009-09-09 15:08:12 +00007237
Douglas Gregorec79d872012-02-24 17:41:38 +00007238 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7239 // Make sure that we capture 'this'.
7240 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007241 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007242 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007243
Douglas Gregor828a1972010-01-07 23:12:05 +00007244 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007245}
Mike Stump1eb44332009-09-09 15:08:12 +00007246
Douglas Gregorb98b1992009-08-11 05:31:07 +00007247template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007248ExprResult
John McCall454feb92009-12-08 09:21:05 +00007249TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007250 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007251 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007252 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007253
Douglas Gregorb98b1992009-08-11 05:31:07 +00007254 if (!getDerived().AlwaysRebuild() &&
7255 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007256 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007257
Douglas Gregorbca01b42011-07-06 22:04:06 +00007258 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7259 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007260}
Mike Stump1eb44332009-09-09 15:08:12 +00007261
Douglas Gregorb98b1992009-08-11 05:31:07 +00007262template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007263ExprResult
John McCall454feb92009-12-08 09:21:05 +00007264TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007265 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007266 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7267 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007268 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007269 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007270
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007271 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007272 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007273 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007274
Douglas Gregor036aed12009-12-23 23:03:06 +00007275 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007276}
Mike Stump1eb44332009-09-09 15:08:12 +00007277
Douglas Gregorb98b1992009-08-11 05:31:07 +00007278template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007279ExprResult
Richard Smithc3bf52c2013-04-20 22:23:05 +00007280TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
7281 FieldDecl *Field
7282 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
7283 E->getField()));
7284 if (!Field)
7285 return ExprError();
7286
7287 if (!getDerived().AlwaysRebuild() && Field == E->getField())
7288 return SemaRef.Owned(E);
7289
7290 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
7291}
7292
7293template<typename Derived>
7294ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007295TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7296 CXXScalarValueInitExpr *E) {
7297 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7298 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007299 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007300
Douglas Gregorb98b1992009-08-11 05:31:07 +00007301 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007302 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007303 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007304
Chad Rosier4a9d7952012-08-08 18:46:20 +00007305 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007306 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007307 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007308}
Mike Stump1eb44332009-09-09 15:08:12 +00007309
Douglas Gregorb98b1992009-08-11 05:31:07 +00007310template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007311ExprResult
John McCall454feb92009-12-08 09:21:05 +00007312TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007313 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007314 TypeSourceInfo *AllocTypeInfo
7315 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7316 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007317 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007318
Douglas Gregorb98b1992009-08-11 05:31:07 +00007319 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007320 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007321 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007322 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007323
Douglas Gregorb98b1992009-08-11 05:31:07 +00007324 // Transform the placement arguments (if any).
7325 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007326 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007327 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007328 E->getNumPlacementArgs(), true,
7329 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007330 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007331
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007332 // Transform the initializer (if any).
7333 Expr *OldInit = E->getInitializer();
7334 ExprResult NewInit;
7335 if (OldInit)
7336 NewInit = getDerived().TransformExpr(OldInit);
7337 if (NewInit.isInvalid())
7338 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007339
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007340 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007341 FunctionDecl *OperatorNew = 0;
7342 if (E->getOperatorNew()) {
7343 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007344 getDerived().TransformDecl(E->getLocStart(),
7345 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007346 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007347 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007348 }
7349
7350 FunctionDecl *OperatorDelete = 0;
7351 if (E->getOperatorDelete()) {
7352 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007353 getDerived().TransformDecl(E->getLocStart(),
7354 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007355 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007356 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007357 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007358
Douglas Gregorb98b1992009-08-11 05:31:07 +00007359 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007360 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007361 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007362 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007363 OperatorNew == E->getOperatorNew() &&
7364 OperatorDelete == E->getOperatorDelete() &&
7365 !ArgumentChanged) {
7366 // Mark any declarations we need as referenced.
7367 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007368 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007369 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007370 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007371 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007372
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007373 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007374 QualType ElementType
7375 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7376 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7377 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7378 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007379 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007380 }
7381 }
7382 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007383
John McCall3fa5cae2010-10-26 07:05:15 +00007384 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007385 }
Mike Stump1eb44332009-09-09 15:08:12 +00007386
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007387 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007388 if (!ArraySize.get()) {
7389 // If no array size was specified, but the new expression was
7390 // instantiated with an array type (e.g., "new T" where T is
7391 // instantiated with "int[4]"), extract the outer bound from the
7392 // array type as our array size. We do this with constant and
7393 // dependently-sized array types.
7394 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7395 if (!ArrayT) {
7396 // Do nothing
7397 } else if (const ConstantArrayType *ConsArrayT
7398 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007399 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007400 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007401 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007402 SemaRef.Context.getSizeType(),
7403 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007404 AllocType = ConsArrayT->getElementType();
7405 } else if (const DependentSizedArrayType *DepArrayT
7406 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7407 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007408 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007409 AllocType = DepArrayT->getElementType();
7410 }
7411 }
7412 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007413
Douglas Gregorb98b1992009-08-11 05:31:07 +00007414 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7415 E->isGlobalNew(),
7416 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007417 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007418 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007419 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007420 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007421 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007422 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007423 E->getDirectInitRange(),
7424 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007425}
Mike Stump1eb44332009-09-09 15:08:12 +00007426
Douglas Gregorb98b1992009-08-11 05:31:07 +00007427template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007428ExprResult
John McCall454feb92009-12-08 09:21:05 +00007429TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007430 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007431 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007432 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007433
Douglas Gregor1af74512010-02-26 00:38:10 +00007434 // Transform the delete operator, if known.
7435 FunctionDecl *OperatorDelete = 0;
7436 if (E->getOperatorDelete()) {
7437 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007438 getDerived().TransformDecl(E->getLocStart(),
7439 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007440 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007441 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007442 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007443
Douglas Gregorb98b1992009-08-11 05:31:07 +00007444 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007445 Operand.get() == E->getArgument() &&
7446 OperatorDelete == E->getOperatorDelete()) {
7447 // Mark any declarations we need as referenced.
7448 // FIXME: instantiation-specific.
7449 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007450 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007451
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007452 if (!E->getArgument()->isTypeDependent()) {
7453 QualType Destroyed = SemaRef.Context.getBaseElementType(
7454 E->getDestroyedType());
7455 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7456 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007457 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007458 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007459 }
7460 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007461
John McCall3fa5cae2010-10-26 07:05:15 +00007462 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007463 }
Mike Stump1eb44332009-09-09 15:08:12 +00007464
Douglas Gregorb98b1992009-08-11 05:31:07 +00007465 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7466 E->isGlobalDelete(),
7467 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007468 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007469}
Mike Stump1eb44332009-09-09 15:08:12 +00007470
Douglas Gregorb98b1992009-08-11 05:31:07 +00007471template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007472ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007473TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007474 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007475 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007476 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007477 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007478
John McCallb3d87482010-08-24 05:47:05 +00007479 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007480 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007481 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007482 E->getOperatorLoc(),
7483 E->isArrow()? tok::arrow : tok::period,
7484 ObjectTypePtr,
7485 MayBePseudoDestructor);
7486 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007487 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007488
John McCallb3d87482010-08-24 05:47:05 +00007489 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007490 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7491 if (QualifierLoc) {
7492 QualifierLoc
7493 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7494 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007495 return ExprError();
7496 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007497 CXXScopeSpec SS;
7498 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007499
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007500 PseudoDestructorTypeStorage Destroyed;
7501 if (E->getDestroyedTypeInfo()) {
7502 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007503 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007504 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007505 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007506 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007507 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007508 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007509 // We aren't likely to be able to resolve the identifier down to a type
7510 // now anyway, so just retain the identifier.
7511 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7512 E->getDestroyedTypeLoc());
7513 } else {
7514 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007515 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007516 *E->getDestroyedTypeIdentifier(),
7517 E->getDestroyedTypeLoc(),
7518 /*Scope=*/0,
7519 SS, ObjectTypePtr,
7520 false);
7521 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007522 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007523
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007524 Destroyed
7525 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7526 E->getDestroyedTypeLoc());
7527 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007528
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007529 TypeSourceInfo *ScopeTypeInfo = 0;
7530 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007531 CXXScopeSpec EmptySS;
7532 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7533 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007534 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007535 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007536 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007537
John McCall9ae2f072010-08-23 23:25:46 +00007538 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007539 E->getOperatorLoc(),
7540 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007541 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007542 ScopeTypeInfo,
7543 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007544 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007545 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007546}
Mike Stump1eb44332009-09-09 15:08:12 +00007547
Douglas Gregora71d8192009-09-04 17:36:40 +00007548template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007549ExprResult
John McCallba135432009-11-21 08:51:07 +00007550TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007551 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007552 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7553 Sema::LookupOrdinaryName);
7554
7555 // Transform all the decls.
7556 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7557 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007558 NamedDecl *InstD = static_cast<NamedDecl*>(
7559 getDerived().TransformDecl(Old->getNameLoc(),
7560 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007561 if (!InstD) {
7562 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7563 // This can happen because of dependent hiding.
7564 if (isa<UsingShadowDecl>(*I))
7565 continue;
7566 else
John McCallf312b1e2010-08-26 23:41:50 +00007567 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007568 }
John McCallf7a1a742009-11-24 19:00:30 +00007569
7570 // Expand using declarations.
7571 if (isa<UsingDecl>(InstD)) {
7572 UsingDecl *UD = cast<UsingDecl>(InstD);
7573 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7574 E = UD->shadow_end(); I != E; ++I)
7575 R.addDecl(*I);
7576 continue;
7577 }
7578
7579 R.addDecl(InstD);
7580 }
7581
7582 // Resolve a kind, but don't do any further analysis. If it's
7583 // ambiguous, the callee needs to deal with it.
7584 R.resolveKind();
7585
7586 // Rebuild the nested-name qualifier, if present.
7587 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007588 if (Old->getQualifierLoc()) {
7589 NestedNameSpecifierLoc QualifierLoc
7590 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7591 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007592 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007593
Douglas Gregor4c9be892011-02-28 20:01:57 +00007594 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007595 }
7596
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007597 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007598 CXXRecordDecl *NamingClass
7599 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7600 Old->getNameLoc(),
7601 Old->getNamingClass()));
7602 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007603 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007604
Douglas Gregor66c45152010-04-27 16:10:10 +00007605 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007606 }
7607
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007608 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7609
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007610 // If we have neither explicit template arguments, nor the template keyword,
7611 // it's a normal declaration name.
7612 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007613 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7614
7615 // If we have template arguments, rebuild them, then rebuild the
7616 // templateid expression.
7617 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007618 if (Old->hasExplicitTemplateArgs() &&
7619 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007620 Old->getNumTemplateArgs(),
7621 TransArgs))
7622 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007623
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007624 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007625 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007626}
Mike Stump1eb44332009-09-09 15:08:12 +00007627
Douglas Gregorb98b1992009-08-11 05:31:07 +00007628template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007629ExprResult
John McCall454feb92009-12-08 09:21:05 +00007630TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007631 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7632 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007633 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007634
Douglas Gregorb98b1992009-08-11 05:31:07 +00007635 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007636 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007637 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007638
Mike Stump1eb44332009-09-09 15:08:12 +00007639 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007640 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007641 T,
7642 E->getLocEnd());
7643}
Mike Stump1eb44332009-09-09 15:08:12 +00007644
Douglas Gregorb98b1992009-08-11 05:31:07 +00007645template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007646ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007647TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7648 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7649 if (!LhsT)
7650 return ExprError();
7651
7652 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7653 if (!RhsT)
7654 return ExprError();
7655
7656 if (!getDerived().AlwaysRebuild() &&
7657 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7658 return SemaRef.Owned(E);
7659
7660 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7661 E->getLocStart(),
7662 LhsT, RhsT,
7663 E->getLocEnd());
7664}
7665
7666template<typename Derived>
7667ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007668TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7669 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007670 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007671 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7672 TypeSourceInfo *From = E->getArg(I);
7673 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007674 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007675 TypeLocBuilder TLB;
7676 TLB.reserve(FromTL.getFullDataSize());
7677 QualType To = getDerived().TransformType(TLB, FromTL);
7678 if (To.isNull())
7679 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007680
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007681 if (To == From->getType())
7682 Args.push_back(From);
7683 else {
7684 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7685 ArgChanged = true;
7686 }
7687 continue;
7688 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007689
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007690 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007691
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007692 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007693 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007694 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7695 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7696 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007697
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007698 // Determine whether the set of unexpanded parameter packs can and should
7699 // be expanded.
7700 bool Expand = true;
7701 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007702 Optional<unsigned> OrigNumExpansions =
7703 ExpansionTL.getTypePtr()->getNumExpansions();
7704 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007705 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7706 PatternTL.getSourceRange(),
7707 Unexpanded,
7708 Expand, RetainExpansion,
7709 NumExpansions))
7710 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007711
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007712 if (!Expand) {
7713 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007714 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007715 // expansion.
7716 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007717
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007718 TypeLocBuilder TLB;
7719 TLB.reserve(From->getTypeLoc().getFullDataSize());
7720
7721 QualType To = getDerived().TransformType(TLB, PatternTL);
7722 if (To.isNull())
7723 return ExprError();
7724
Chad Rosier4a9d7952012-08-08 18:46:20 +00007725 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007726 PatternTL.getSourceRange(),
7727 ExpansionTL.getEllipsisLoc(),
7728 NumExpansions);
7729 if (To.isNull())
7730 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007731
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007732 PackExpansionTypeLoc ToExpansionTL
7733 = TLB.push<PackExpansionTypeLoc>(To);
7734 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7735 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7736 continue;
7737 }
7738
7739 // Expand the pack expansion by substituting for each argument in the
7740 // pack(s).
7741 for (unsigned I = 0; I != *NumExpansions; ++I) {
7742 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7743 TypeLocBuilder TLB;
7744 TLB.reserve(PatternTL.getFullDataSize());
7745 QualType To = getDerived().TransformType(TLB, PatternTL);
7746 if (To.isNull())
7747 return ExprError();
7748
7749 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7750 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007751
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007752 if (!RetainExpansion)
7753 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007754
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007755 // If we're supposed to retain a pack expansion, do so by temporarily
7756 // forgetting the partially-substituted parameter pack.
7757 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7758
7759 TypeLocBuilder TLB;
7760 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007761
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007762 QualType To = getDerived().TransformType(TLB, PatternTL);
7763 if (To.isNull())
7764 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007765
7766 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007767 PatternTL.getSourceRange(),
7768 ExpansionTL.getEllipsisLoc(),
7769 NumExpansions);
7770 if (To.isNull())
7771 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007772
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007773 PackExpansionTypeLoc ToExpansionTL
7774 = TLB.push<PackExpansionTypeLoc>(To);
7775 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7776 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7777 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007778
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007779 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7780 return SemaRef.Owned(E);
7781
7782 return getDerived().RebuildTypeTrait(E->getTrait(),
7783 E->getLocStart(),
7784 Args,
7785 E->getLocEnd());
7786}
7787
7788template<typename Derived>
7789ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007790TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7791 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7792 if (!T)
7793 return ExprError();
7794
7795 if (!getDerived().AlwaysRebuild() &&
7796 T == E->getQueriedTypeSourceInfo())
7797 return SemaRef.Owned(E);
7798
7799 ExprResult SubExpr;
7800 {
7801 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7802 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7803 if (SubExpr.isInvalid())
7804 return ExprError();
7805
7806 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7807 return SemaRef.Owned(E);
7808 }
7809
7810 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7811 E->getLocStart(),
7812 T,
7813 SubExpr.get(),
7814 E->getLocEnd());
7815}
7816
7817template<typename Derived>
7818ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007819TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7820 ExprResult SubExpr;
7821 {
7822 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7823 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7824 if (SubExpr.isInvalid())
7825 return ExprError();
7826
7827 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7828 return SemaRef.Owned(E);
7829 }
7830
7831 return getDerived().RebuildExpressionTrait(
7832 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7833}
7834
7835template<typename Derived>
7836ExprResult
John McCall865d4472009-11-19 22:55:06 +00007837TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007838 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00007839 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
7840}
7841
7842template<typename Derived>
7843ExprResult
7844TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
7845 DependentScopeDeclRefExpr *E,
7846 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007847 NestedNameSpecifierLoc QualifierLoc
7848 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7849 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007850 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007851 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007852
John McCall43fed0d2010-11-12 08:19:04 +00007853 // TODO: If this is a conversion-function-id, verify that the
7854 // destination type name (if present) resolves the same way after
7855 // instantiation as it did in the local scope.
7856
Abramo Bagnara25777432010-08-11 22:01:17 +00007857 DeclarationNameInfo NameInfo
7858 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7859 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007860 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007861
John McCallf7a1a742009-11-24 19:00:30 +00007862 if (!E->hasExplicitTemplateArgs()) {
7863 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007864 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007865 // Note: it is sufficient to compare the Name component of NameInfo:
7866 // if name has not changed, DNLoc has not changed either.
7867 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007868 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007869
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007870 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007871 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007872 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007873 /*TemplateArgs*/ 0,
7874 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007875 }
John McCalld5532b62009-11-23 01:53:49 +00007876
7877 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007878 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7879 E->getNumTemplateArgs(),
7880 TransArgs))
7881 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007882
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007883 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007884 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007885 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007886 &TransArgs,
7887 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007888}
7889
7890template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007891ExprResult
John McCall454feb92009-12-08 09:21:05 +00007892TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00007893 // CXXConstructExprs other than for list-initialization and
7894 // CXXTemporaryObjectExpr are always implicit, so when we have
7895 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00007896 if ((E->getNumArgs() == 1 ||
7897 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00007898 (!getDerived().DropCallArgument(E->getArg(0))) &&
7899 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00007900 return getDerived().TransformExpr(E->getArg(0));
7901
Douglas Gregorb98b1992009-08-11 05:31:07 +00007902 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7903
7904 QualType T = getDerived().TransformType(E->getType());
7905 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007906 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007907
7908 CXXConstructorDecl *Constructor
7909 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007910 getDerived().TransformDecl(E->getLocStart(),
7911 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007912 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007913 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007914
Douglas Gregorb98b1992009-08-11 05:31:07 +00007915 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007916 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007917 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007918 &ArgumentChanged))
7919 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007920
Douglas Gregorb98b1992009-08-11 05:31:07 +00007921 if (!getDerived().AlwaysRebuild() &&
7922 T == E->getType() &&
7923 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007924 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007925 // Mark the constructor as referenced.
7926 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007927 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007928 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007929 }
Mike Stump1eb44332009-09-09 15:08:12 +00007930
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007931 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7932 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007933 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007934 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00007935 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007936 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007937 E->getConstructionKind(),
7938 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007939}
Mike Stump1eb44332009-09-09 15:08:12 +00007940
Douglas Gregorb98b1992009-08-11 05:31:07 +00007941/// \brief Transform a C++ temporary-binding expression.
7942///
Douglas Gregor51326552009-12-24 18:51:59 +00007943/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7944/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007945template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007946ExprResult
John McCall454feb92009-12-08 09:21:05 +00007947TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007948 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007949}
Mike Stump1eb44332009-09-09 15:08:12 +00007950
John McCall4765fa02010-12-06 08:20:24 +00007951/// \brief Transform a C++ expression that contains cleanups that should
7952/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007953///
John McCall4765fa02010-12-06 08:20:24 +00007954/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007955/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007956template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007957ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007958TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007959 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007960}
Mike Stump1eb44332009-09-09 15:08:12 +00007961
Douglas Gregorb98b1992009-08-11 05:31:07 +00007962template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007963ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007964TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007965 CXXTemporaryObjectExpr *E) {
7966 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7967 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007968 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007969
Douglas Gregorb98b1992009-08-11 05:31:07 +00007970 CXXConstructorDecl *Constructor
7971 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00007972 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007973 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007974 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007975 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007976
Douglas Gregorb98b1992009-08-11 05:31:07 +00007977 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007978 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007979 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007980 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007981 &ArgumentChanged))
7982 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007983
Douglas Gregorb98b1992009-08-11 05:31:07 +00007984 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007985 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007986 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007987 !ArgumentChanged) {
7988 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007989 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007990 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007991 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007992
Richard Smithc83c2302012-12-19 01:39:02 +00007993 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00007994 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7995 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007996 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007997 E->getLocEnd());
7998}
Mike Stump1eb44332009-09-09 15:08:12 +00007999
Douglas Gregorb98b1992009-08-11 05:31:07 +00008000template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008001ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00008002TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00008003 // Transform the type of the lambda parameters and start the definition of
8004 // the lambda itself.
8005 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00008006 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00008007 if (!MethodTy)
8008 return ExprError();
8009
Eli Friedman8da8a662012-09-19 01:18:11 +00008010 // Create the local class that will describe the lambda.
8011 CXXRecordDecl *Class
8012 = getSema().createLambdaClosureType(E->getIntroducerRange(),
8013 MethodTy,
8014 /*KnownDependent=*/false);
8015 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
8016
Douglas Gregorc6889e72012-02-14 22:28:59 +00008017 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008018 SmallVector<QualType, 4> ParamTypes;
8019 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00008020 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
8021 E->getCallOperator()->param_begin(),
8022 E->getCallOperator()->param_size(),
8023 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00008024 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00008025
Douglas Gregordfca6f52012-02-13 22:00:16 +00008026 // Build the call operator.
8027 CXXMethodDecl *CallOperator
8028 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008029 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00008030 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00008031 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008032 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00008033
Richard Smith612409e2012-07-25 03:56:55 +00008034 return getDerived().TransformLambdaScope(E, CallOperator);
8035}
8036
8037template<typename Derived>
8038ExprResult
8039TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
8040 CXXMethodDecl *CallOperator) {
Douglas Gregord5387e82012-02-14 00:00:48 +00008041 // Introduce the context of the call operator.
8042 Sema::ContextRAII SavedContext(getSema(), CallOperator);
8043
Douglas Gregordfca6f52012-02-13 22:00:16 +00008044 // Enter the scope of the lambda.
8045 sema::LambdaScopeInfo *LSI
8046 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
8047 E->getCaptureDefault(),
8048 E->hasExplicitParameters(),
8049 E->hasExplicitResultType(),
8050 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008051
Douglas Gregordfca6f52012-02-13 22:00:16 +00008052 // Transform captures.
Richard Smith612409e2012-07-25 03:56:55 +00008053 bool Invalid = false;
Douglas Gregordfca6f52012-02-13 22:00:16 +00008054 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008055 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008056 CEnd = E->capture_end();
8057 C != CEnd; ++C) {
8058 // When we hit the first implicit capture, tell Sema that we've finished
8059 // the list of explicit captures.
8060 if (!FinishedExplicitCaptures && C->isImplicit()) {
8061 getSema().finishLambdaExplicitCaptures(LSI);
8062 FinishedExplicitCaptures = true;
8063 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008064
Douglas Gregordfca6f52012-02-13 22:00:16 +00008065 // Capturing 'this' is trivial.
8066 if (C->capturesThis()) {
8067 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
8068 continue;
8069 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008070
Douglas Gregora7365242012-02-14 19:27:52 +00008071 // Determine the capture kind for Sema.
8072 Sema::TryCaptureKind Kind
8073 = C->isImplicit()? Sema::TryCapture_Implicit
8074 : C->getCaptureKind() == LCK_ByCopy
8075 ? Sema::TryCapture_ExplicitByVal
8076 : Sema::TryCapture_ExplicitByRef;
8077 SourceLocation EllipsisLoc;
8078 if (C->isPackExpansion()) {
8079 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8080 bool ShouldExpand = false;
8081 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008082 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008083 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8084 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008085 Unexpanded,
8086 ShouldExpand, RetainExpansion,
8087 NumExpansions))
8088 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008089
Douglas Gregora7365242012-02-14 19:27:52 +00008090 if (ShouldExpand) {
8091 // The transform has determined that we should perform an expansion;
8092 // transform and capture each of the arguments.
8093 // expansion of the pattern. Do so.
8094 VarDecl *Pack = C->getCapturedVar();
8095 for (unsigned I = 0; I != *NumExpansions; ++I) {
8096 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8097 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008098 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008099 Pack));
8100 if (!CapturedVar) {
8101 Invalid = true;
8102 continue;
8103 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008104
Douglas Gregora7365242012-02-14 19:27:52 +00008105 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008106 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8107 }
Douglas Gregora7365242012-02-14 19:27:52 +00008108 continue;
8109 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008110
Douglas Gregora7365242012-02-14 19:27:52 +00008111 EllipsisLoc = C->getEllipsisLoc();
8112 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008113
Douglas Gregordfca6f52012-02-13 22:00:16 +00008114 // Transform the captured variable.
8115 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008116 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008117 C->getCapturedVar()));
8118 if (!CapturedVar) {
8119 Invalid = true;
8120 continue;
8121 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008122
Douglas Gregordfca6f52012-02-13 22:00:16 +00008123 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008124 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008125 }
8126 if (!FinishedExplicitCaptures)
8127 getSema().finishLambdaExplicitCaptures(LSI);
8128
Douglas Gregordfca6f52012-02-13 22:00:16 +00008129
8130 // Enter a new evaluation context to insulate the lambda from any
8131 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008132 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008133
8134 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008135 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008136 /*IsInstantiation=*/true);
8137 return ExprError();
8138 }
8139
8140 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008141 StmtResult Body = getDerived().TransformStmt(E->getBody());
8142 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008143 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008144 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008145 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008146 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008147
Chad Rosier4a9d7952012-08-08 18:46:20 +00008148 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008149 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008150}
8151
8152template<typename Derived>
8153ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008154TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008155 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008156 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8157 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008158 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008159
Douglas Gregorb98b1992009-08-11 05:31:07 +00008160 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008161 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008162 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008163 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008164 &ArgumentChanged))
8165 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008166
Douglas Gregorb98b1992009-08-11 05:31:07 +00008167 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008168 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008169 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008170 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008171
Douglas Gregorb98b1992009-08-11 05:31:07 +00008172 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008173 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008174 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008175 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008176 E->getRParenLoc());
8177}
Mike Stump1eb44332009-09-09 15:08:12 +00008178
Douglas Gregorb98b1992009-08-11 05:31:07 +00008179template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008180ExprResult
John McCall865d4472009-11-19 22:55:06 +00008181TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008182 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008183 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008184 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008185 Expr *OldBase;
8186 QualType BaseType;
8187 QualType ObjectType;
8188 if (!E->isImplicitAccess()) {
8189 OldBase = E->getBase();
8190 Base = getDerived().TransformExpr(OldBase);
8191 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008192 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008193
John McCallaa81e162009-12-01 22:10:20 +00008194 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008195 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008196 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008197 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008198 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008199 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008200 ObjectTy,
8201 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008202 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008203 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008204
John McCallb3d87482010-08-24 05:47:05 +00008205 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008206 BaseType = ((Expr*) Base.get())->getType();
8207 } else {
8208 OldBase = 0;
8209 BaseType = getDerived().TransformType(E->getBaseType());
8210 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8211 }
Mike Stump1eb44332009-09-09 15:08:12 +00008212
Douglas Gregor6cd21982009-10-20 05:58:46 +00008213 // Transform the first part of the nested-name-specifier that qualifies
8214 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008215 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008216 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008217 E->getFirstQualifierFoundInScope(),
8218 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008219
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008220 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008221 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008222 QualifierLoc
8223 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8224 ObjectType,
8225 FirstQualifierInScope);
8226 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008227 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008228 }
Mike Stump1eb44332009-09-09 15:08:12 +00008229
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008230 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8231
John McCall43fed0d2010-11-12 08:19:04 +00008232 // TODO: If this is a conversion-function-id, verify that the
8233 // destination type name (if present) resolves the same way after
8234 // instantiation as it did in the local scope.
8235
Abramo Bagnara25777432010-08-11 22:01:17 +00008236 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008237 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008238 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008239 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008240
John McCallaa81e162009-12-01 22:10:20 +00008241 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008242 // This is a reference to a member without an explicitly-specified
8243 // template argument list. Optimize for this common case.
8244 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008245 Base.get() == OldBase &&
8246 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008247 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008248 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008249 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008250 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008251
John McCall9ae2f072010-08-23 23:25:46 +00008252 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008253 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008254 E->isArrow(),
8255 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008256 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008257 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008258 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008259 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008260 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008261 }
8262
John McCalld5532b62009-11-23 01:53:49 +00008263 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008264 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8265 E->getNumTemplateArgs(),
8266 TransArgs))
8267 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008268
John McCall9ae2f072010-08-23 23:25:46 +00008269 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008270 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008271 E->isArrow(),
8272 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008273 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008274 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008275 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008276 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008277 &TransArgs);
8278}
8279
8280template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008281ExprResult
John McCall454feb92009-12-08 09:21:05 +00008282TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008283 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008284 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008285 QualType BaseType;
8286 if (!Old->isImplicitAccess()) {
8287 Base = getDerived().TransformExpr(Old->getBase());
8288 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008289 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008290 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8291 Old->isArrow());
8292 if (Base.isInvalid())
8293 return ExprError();
8294 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008295 } else {
8296 BaseType = getDerived().TransformType(Old->getBaseType());
8297 }
John McCall129e2df2009-11-30 22:42:35 +00008298
Douglas Gregor4c9be892011-02-28 20:01:57 +00008299 NestedNameSpecifierLoc QualifierLoc;
8300 if (Old->getQualifierLoc()) {
8301 QualifierLoc
8302 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8303 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008304 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008305 }
8306
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008307 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8308
Abramo Bagnara25777432010-08-11 22:01:17 +00008309 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008310 Sema::LookupOrdinaryName);
8311
8312 // Transform all the decls.
8313 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8314 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008315 NamedDecl *InstD = static_cast<NamedDecl*>(
8316 getDerived().TransformDecl(Old->getMemberLoc(),
8317 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008318 if (!InstD) {
8319 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8320 // This can happen because of dependent hiding.
8321 if (isa<UsingShadowDecl>(*I))
8322 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008323 else {
8324 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008325 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008326 }
John McCall9f54ad42009-12-10 09:41:52 +00008327 }
John McCall129e2df2009-11-30 22:42:35 +00008328
8329 // Expand using declarations.
8330 if (isa<UsingDecl>(InstD)) {
8331 UsingDecl *UD = cast<UsingDecl>(InstD);
8332 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8333 E = UD->shadow_end(); I != E; ++I)
8334 R.addDecl(*I);
8335 continue;
8336 }
8337
8338 R.addDecl(InstD);
8339 }
8340
8341 R.resolveKind();
8342
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008343 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008344 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008345 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008346 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008347 Old->getMemberLoc(),
8348 Old->getNamingClass()));
8349 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008350 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008351
Douglas Gregor66c45152010-04-27 16:10:10 +00008352 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008353 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008354
John McCall129e2df2009-11-30 22:42:35 +00008355 TemplateArgumentListInfo TransArgs;
8356 if (Old->hasExplicitTemplateArgs()) {
8357 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8358 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008359 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8360 Old->getNumTemplateArgs(),
8361 TransArgs))
8362 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008363 }
John McCallc2233c52010-01-15 08:34:02 +00008364
8365 // FIXME: to do this check properly, we will need to preserve the
8366 // first-qualifier-in-scope here, just in case we had a dependent
8367 // base (and therefore couldn't do the check) and a
8368 // nested-name-qualifier (and therefore could do the lookup).
8369 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008370
John McCall9ae2f072010-08-23 23:25:46 +00008371 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008372 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008373 Old->getOperatorLoc(),
8374 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008375 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008376 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008377 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008378 R,
8379 (Old->hasExplicitTemplateArgs()
8380 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008381}
8382
8383template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008384ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008385TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008386 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008387 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8388 if (SubExpr.isInvalid())
8389 return ExprError();
8390
8391 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008392 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008393
8394 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8395}
8396
8397template<typename Derived>
8398ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008399TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008400 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8401 if (Pattern.isInvalid())
8402 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008403
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008404 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8405 return SemaRef.Owned(E);
8406
Douglas Gregor67fd1252011-01-14 21:20:45 +00008407 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8408 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008409}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008410
8411template<typename Derived>
8412ExprResult
8413TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8414 // If E is not value-dependent, then nothing will change when we transform it.
8415 // Note: This is an instantiation-centric view.
8416 if (!E->isValueDependent())
8417 return SemaRef.Owned(E);
8418
8419 // Note: None of the implementations of TryExpandParameterPacks can ever
8420 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008421 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008422 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8423 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008424 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008425 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008426 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008427 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008428 ShouldExpand, RetainExpansion,
8429 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008430 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008431
Douglas Gregor089e8932011-10-10 18:59:29 +00008432 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008433 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008434
Douglas Gregor089e8932011-10-10 18:59:29 +00008435 NamedDecl *Pack = E->getPack();
8436 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008437 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008438 Pack));
8439 if (!Pack)
8440 return ExprError();
8441 }
8442
Chad Rosier4a9d7952012-08-08 18:46:20 +00008443
Douglas Gregoree8aff02011-01-04 17:33:58 +00008444 // We now know the length of the parameter pack, so build a new expression
8445 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008446 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8447 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008448 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008449}
8450
Douglas Gregorbe230c32011-01-03 17:17:50 +00008451template<typename Derived>
8452ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008453TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8454 SubstNonTypeTemplateParmPackExpr *E) {
8455 // Default behavior is to do nothing with this transformation.
8456 return SemaRef.Owned(E);
8457}
8458
8459template<typename Derived>
8460ExprResult
John McCall91a57552011-07-15 05:09:51 +00008461TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8462 SubstNonTypeTemplateParmExpr *E) {
8463 // Default behavior is to do nothing with this transformation.
8464 return SemaRef.Owned(E);
8465}
8466
8467template<typename Derived>
8468ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008469TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8470 // Default behavior is to do nothing with this transformation.
8471 return SemaRef.Owned(E);
8472}
8473
8474template<typename Derived>
8475ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008476TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8477 MaterializeTemporaryExpr *E) {
8478 return getDerived().TransformExpr(E->GetTemporaryExpr());
8479}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008480
Douglas Gregor03e80032011-06-21 17:03:29 +00008481template<typename Derived>
8482ExprResult
John McCall454feb92009-12-08 09:21:05 +00008483TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008484 return SemaRef.MaybeBindToTemporary(E);
8485}
8486
8487template<typename Derived>
8488ExprResult
8489TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008490 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008491}
8492
8493template<typename Derived>
8494ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008495TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8496 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8497 if (SubExpr.isInvalid())
8498 return ExprError();
8499
8500 if (!getDerived().AlwaysRebuild() &&
8501 SubExpr.get() == E->getSubExpr())
8502 return SemaRef.Owned(E);
8503
8504 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008505}
8506
8507template<typename Derived>
8508ExprResult
8509TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8510 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008511 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008512 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008513 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008514 /*IsCall=*/false, Elements, &ArgChanged))
8515 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008516
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008517 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8518 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008519
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008520 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8521 Elements.data(),
8522 Elements.size());
8523}
8524
8525template<typename Derived>
8526ExprResult
8527TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008528 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008529 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008530 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008531 bool ArgChanged = false;
8532 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8533 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008534
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008535 if (OrigElement.isPackExpansion()) {
8536 // This key/value element is a pack expansion.
8537 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8538 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8539 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8540 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8541
8542 // Determine whether the set of unexpanded parameter packs can
8543 // and should be expanded.
8544 bool Expand = true;
8545 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008546 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8547 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008548 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8549 OrigElement.Value->getLocEnd());
8550 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8551 PatternRange,
8552 Unexpanded,
8553 Expand, RetainExpansion,
8554 NumExpansions))
8555 return ExprError();
8556
8557 if (!Expand) {
8558 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008559 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008560 // expansion.
8561 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8562 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8563 if (Key.isInvalid())
8564 return ExprError();
8565
8566 if (Key.get() != OrigElement.Key)
8567 ArgChanged = true;
8568
8569 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8570 if (Value.isInvalid())
8571 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008572
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008573 if (Value.get() != OrigElement.Value)
8574 ArgChanged = true;
8575
Chad Rosier4a9d7952012-08-08 18:46:20 +00008576 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008577 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8578 };
8579 Elements.push_back(Expansion);
8580 continue;
8581 }
8582
8583 // Record right away that the argument was changed. This needs
8584 // to happen even if the array expands to nothing.
8585 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008586
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008587 // The transform has determined that we should perform an elementwise
8588 // expansion of the pattern. Do so.
8589 for (unsigned I = 0; I != *NumExpansions; ++I) {
8590 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8591 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8592 if (Key.isInvalid())
8593 return ExprError();
8594
8595 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8596 if (Value.isInvalid())
8597 return ExprError();
8598
Chad Rosier4a9d7952012-08-08 18:46:20 +00008599 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008600 Key.get(), Value.get(), SourceLocation(), NumExpansions
8601 };
8602
8603 // If any unexpanded parameter packs remain, we still have a
8604 // pack expansion.
8605 if (Key.get()->containsUnexpandedParameterPack() ||
8606 Value.get()->containsUnexpandedParameterPack())
8607 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008608
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008609 Elements.push_back(Element);
8610 }
8611
8612 // We've finished with this pack expansion.
8613 continue;
8614 }
8615
8616 // Transform and check key.
8617 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8618 if (Key.isInvalid())
8619 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008620
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008621 if (Key.get() != OrigElement.Key)
8622 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008623
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008624 // Transform and check value.
8625 ExprResult Value
8626 = getDerived().TransformExpr(OrigElement.Value);
8627 if (Value.isInvalid())
8628 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008629
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008630 if (Value.get() != OrigElement.Value)
8631 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008632
8633 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00008634 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008635 };
8636 Elements.push_back(Element);
8637 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008638
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008639 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8640 return SemaRef.MaybeBindToTemporary(E);
8641
8642 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8643 Elements.data(),
8644 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008645}
8646
Mike Stump1eb44332009-09-09 15:08:12 +00008647template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008648ExprResult
John McCall454feb92009-12-08 09:21:05 +00008649TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008650 TypeSourceInfo *EncodedTypeInfo
8651 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8652 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008653 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008654
Douglas Gregorb98b1992009-08-11 05:31:07 +00008655 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008656 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008657 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008658
8659 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008660 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008661 E->getRParenLoc());
8662}
Mike Stump1eb44332009-09-09 15:08:12 +00008663
Douglas Gregorb98b1992009-08-11 05:31:07 +00008664template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008665ExprResult TreeTransform<Derived>::
8666TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCall93b64572013-04-11 02:14:26 +00008667 // This is a kind of implicit conversion, and it needs to get dropped
8668 // and recomputed for the same general reasons that ImplicitCastExprs
8669 // do, as well a more specific one: this expression is only valid when
8670 // it appears *immediately* as an argument expression.
8671 return getDerived().TransformExpr(E->getSubExpr());
John McCallf85e1932011-06-15 23:02:42 +00008672}
8673
8674template<typename Derived>
8675ExprResult TreeTransform<Derived>::
8676TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008677 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008678 = getDerived().TransformType(E->getTypeInfoAsWritten());
8679 if (!TSInfo)
8680 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008681
John McCallf85e1932011-06-15 23:02:42 +00008682 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008683 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008684 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008685
John McCallf85e1932011-06-15 23:02:42 +00008686 if (!getDerived().AlwaysRebuild() &&
8687 TSInfo == E->getTypeInfoAsWritten() &&
8688 Result.get() == E->getSubExpr())
8689 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008690
John McCallf85e1932011-06-15 23:02:42 +00008691 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008692 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008693 Result.get());
8694}
8695
8696template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008697ExprResult
John McCall454feb92009-12-08 09:21:05 +00008698TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008699 // Transform arguments.
8700 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008701 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008702 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008703 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008704 &ArgChanged))
8705 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008706
Douglas Gregor92e986e2010-04-22 16:44:27 +00008707 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8708 // Class message: transform the receiver type.
8709 TypeSourceInfo *ReceiverTypeInfo
8710 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8711 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008712 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008713
Douglas Gregor92e986e2010-04-22 16:44:27 +00008714 // If nothing changed, just retain the existing message send.
8715 if (!getDerived().AlwaysRebuild() &&
8716 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008717 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008718
8719 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008720 SmallVector<SourceLocation, 16> SelLocs;
8721 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008722 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8723 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008724 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008725 E->getMethodDecl(),
8726 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008727 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008728 E->getRightLoc());
8729 }
8730
8731 // Instance message: transform the receiver
8732 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8733 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008734 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008735 = getDerived().TransformExpr(E->getInstanceReceiver());
8736 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008737 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008738
8739 // If nothing changed, just retain the existing message send.
8740 if (!getDerived().AlwaysRebuild() &&
8741 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008742 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008743
Douglas Gregor92e986e2010-04-22 16:44:27 +00008744 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008745 SmallVector<SourceLocation, 16> SelLocs;
8746 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008747 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008748 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008749 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008750 E->getMethodDecl(),
8751 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008752 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008753 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008754}
8755
Mike Stump1eb44332009-09-09 15:08:12 +00008756template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008757ExprResult
John McCall454feb92009-12-08 09:21:05 +00008758TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008759 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008760}
8761
Mike Stump1eb44332009-09-09 15:08:12 +00008762template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008763ExprResult
John McCall454feb92009-12-08 09:21:05 +00008764TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008765 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008766}
8767
Mike Stump1eb44332009-09-09 15:08:12 +00008768template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008769ExprResult
John McCall454feb92009-12-08 09:21:05 +00008770TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008771 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008772 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008773 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008774 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008775
8776 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008777
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008778 // If nothing changed, just retain the existing expression.
8779 if (!getDerived().AlwaysRebuild() &&
8780 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008781 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008782
John McCall9ae2f072010-08-23 23:25:46 +00008783 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008784 E->getLocation(),
8785 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008786}
8787
Mike Stump1eb44332009-09-09 15:08:12 +00008788template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008789ExprResult
John McCall454feb92009-12-08 09:21:05 +00008790TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008791 // 'super' and types never change. Property never changes. Just
8792 // retain the existing expression.
8793 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008794 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008795
Douglas Gregore3303542010-04-26 20:47:02 +00008796 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008797 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008798 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008799 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008800
Douglas Gregore3303542010-04-26 20:47:02 +00008801 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008802
Douglas Gregore3303542010-04-26 20:47:02 +00008803 // If nothing changed, just retain the existing expression.
8804 if (!getDerived().AlwaysRebuild() &&
8805 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008806 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008807
John McCall12f78a62010-12-02 01:19:52 +00008808 if (E->isExplicitProperty())
8809 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8810 E->getExplicitProperty(),
8811 E->getLocation());
8812
8813 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008814 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008815 E->getImplicitPropertyGetter(),
8816 E->getImplicitPropertySetter(),
8817 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008818}
8819
Mike Stump1eb44332009-09-09 15:08:12 +00008820template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008821ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008822TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8823 // Transform the base expression.
8824 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8825 if (Base.isInvalid())
8826 return ExprError();
8827
8828 // Transform the key expression.
8829 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8830 if (Key.isInvalid())
8831 return ExprError();
8832
8833 // If nothing changed, just retain the existing expression.
8834 if (!getDerived().AlwaysRebuild() &&
8835 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8836 return SemaRef.Owned(E);
8837
Chad Rosier4a9d7952012-08-08 18:46:20 +00008838 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008839 Base.get(), Key.get(),
8840 E->getAtIndexMethodDecl(),
8841 E->setAtIndexMethodDecl());
8842}
8843
8844template<typename Derived>
8845ExprResult
John McCall454feb92009-12-08 09:21:05 +00008846TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008847 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008848 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008849 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008850 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008851
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008852 // If nothing changed, just retain the existing expression.
8853 if (!getDerived().AlwaysRebuild() &&
8854 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008855 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008856
John McCall9ae2f072010-08-23 23:25:46 +00008857 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00008858 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008859 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008860}
8861
Mike Stump1eb44332009-09-09 15:08:12 +00008862template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008863ExprResult
John McCall454feb92009-12-08 09:21:05 +00008864TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008865 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008866 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008867 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008868 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008869 SubExprs, &ArgumentChanged))
8870 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008871
Douglas Gregorb98b1992009-08-11 05:31:07 +00008872 if (!getDerived().AlwaysRebuild() &&
8873 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008874 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008875
Douglas Gregorb98b1992009-08-11 05:31:07 +00008876 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008877 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008878 E->getRParenLoc());
8879}
8880
Mike Stump1eb44332009-09-09 15:08:12 +00008881template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008882ExprResult
John McCall454feb92009-12-08 09:21:05 +00008883TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008884 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008885
John McCallc6ac9c32011-02-04 18:33:18 +00008886 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8887 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8888
8889 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008890 blockScope->TheDecl->setBlockMissingReturnType(
8891 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008892
Chris Lattner686775d2011-07-20 06:58:45 +00008893 SmallVector<ParmVarDecl*, 4> params;
8894 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008895
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008896 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008897 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8898 oldBlock->param_begin(),
8899 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008900 0, paramTypes, &params)) {
8901 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008902 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008903 }
John McCallc6ac9c32011-02-04 18:33:18 +00008904
Jordan Rose09189892013-03-08 22:25:36 +00008905 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008906 QualType exprResultType =
8907 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008908
8909 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008910 if (exprResultType->isObjCObjectType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008911 getSema().Diag(E->getCaretLocation(),
8912 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008913 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008914 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008915 return ExprError();
8916 }
John McCall711c52b2011-01-05 12:14:39 +00008917
Jordan Rosebea522f2013-03-08 21:51:21 +00008918 QualType functionType =
8919 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00008920 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00008921 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008922
8923 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008924 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008925 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008926
8927 if (!oldBlock->blockMissingReturnType()) {
8928 blockScope->HasImplicitReturnType = false;
8929 blockScope->ReturnType = exprResultType;
8930 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008931
John McCall711c52b2011-01-05 12:14:39 +00008932 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008933 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008934 if (body.isInvalid()) {
8935 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008936 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008937 }
John McCall711c52b2011-01-05 12:14:39 +00008938
John McCallc6ac9c32011-02-04 18:33:18 +00008939#ifndef NDEBUG
8940 // In builds with assertions, make sure that we captured everything we
8941 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008942 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8943 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8944 e = oldBlock->capture_end(); i != e; ++i) {
8945 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008946
Douglas Gregorfc921372011-05-20 15:32:55 +00008947 // Ignore parameter packs.
8948 if (isa<ParmVarDecl>(oldCapture) &&
8949 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8950 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008951
Douglas Gregorfc921372011-05-20 15:32:55 +00008952 VarDecl *newCapture =
8953 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8954 oldCapture));
8955 assert(blockScope->CaptureMap.count(newCapture));
8956 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008957 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008958 }
8959#endif
8960
8961 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8962 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008963}
8964
Mike Stump1eb44332009-09-09 15:08:12 +00008965template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008966ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008967TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008968 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008969}
Eli Friedman276b0612011-10-11 02:20:01 +00008970
8971template<typename Derived>
8972ExprResult
8973TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008974 QualType RetTy = getDerived().TransformType(E->getType());
8975 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008976 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008977 SubExprs.reserve(E->getNumSubExprs());
8978 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8979 SubExprs, &ArgumentChanged))
8980 return ExprError();
8981
8982 if (!getDerived().AlwaysRebuild() &&
8983 !ArgumentChanged)
8984 return SemaRef.Owned(E);
8985
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008986 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008987 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008988}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008989
Douglas Gregorb98b1992009-08-11 05:31:07 +00008990//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008991// Type reconstruction
8992//===----------------------------------------------------------------------===//
8993
Mike Stump1eb44332009-09-09 15:08:12 +00008994template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008995QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8996 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008997 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008998 getDerived().getBaseEntity());
8999}
9000
Mike Stump1eb44332009-09-09 15:08:12 +00009001template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00009002QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
9003 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00009004 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009005 getDerived().getBaseEntity());
9006}
9007
Mike Stump1eb44332009-09-09 15:08:12 +00009008template<typename Derived>
9009QualType
John McCall85737a72009-10-30 00:06:24 +00009010TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
9011 bool WrittenAsLValue,
9012 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009013 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00009014 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009015}
9016
9017template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009018QualType
John McCall85737a72009-10-30 00:06:24 +00009019TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
9020 QualType ClassType,
9021 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00009022 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00009023 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009024}
9025
9026template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009027QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00009028TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
9029 ArrayType::ArraySizeModifier SizeMod,
9030 const llvm::APInt *Size,
9031 Expr *SizeExpr,
9032 unsigned IndexTypeQuals,
9033 SourceRange BracketsRange) {
9034 if (SizeExpr || !Size)
9035 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
9036 IndexTypeQuals, BracketsRange,
9037 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00009038
9039 QualType Types[] = {
9040 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
9041 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
9042 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00009043 };
9044 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
9045 QualType SizeType;
9046 for (unsigned I = 0; I != NumTypes; ++I)
9047 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
9048 SizeType = Types[I];
9049 break;
9050 }
Mike Stump1eb44332009-09-09 15:08:12 +00009051
Eli Friedman01f276d2012-01-25 23:20:27 +00009052 // Note that we can return a VariableArrayType here in the case where
9053 // the element type was a dependent VariableArrayType.
9054 IntegerLiteral *ArraySize
9055 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
9056 /*FIXME*/BracketsRange.getBegin());
9057 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009058 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00009059 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00009060}
Mike Stump1eb44332009-09-09 15:08:12 +00009061
Douglas Gregor577f75a2009-08-04 16:50:30 +00009062template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009063QualType
9064TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009065 ArrayType::ArraySizeModifier SizeMod,
9066 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009067 unsigned IndexTypeQuals,
9068 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009069 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009070 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009071}
9072
9073template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009074QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009075TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009076 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009077 unsigned IndexTypeQuals,
9078 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009079 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009080 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009081}
Mike Stump1eb44332009-09-09 15:08:12 +00009082
Douglas Gregor577f75a2009-08-04 16:50:30 +00009083template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009084QualType
9085TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009086 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009087 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009088 unsigned IndexTypeQuals,
9089 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009090 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009091 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009092 IndexTypeQuals, BracketsRange);
9093}
9094
9095template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009096QualType
9097TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009098 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009099 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009100 unsigned IndexTypeQuals,
9101 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009102 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009103 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009104 IndexTypeQuals, BracketsRange);
9105}
9106
9107template<typename Derived>
9108QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009109 unsigned NumElements,
9110 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009111 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009112 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009113}
Mike Stump1eb44332009-09-09 15:08:12 +00009114
Douglas Gregor577f75a2009-08-04 16:50:30 +00009115template<typename Derived>
9116QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9117 unsigned NumElements,
9118 SourceLocation AttributeLoc) {
9119 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9120 NumElements, true);
9121 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009122 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9123 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009124 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009125}
Mike Stump1eb44332009-09-09 15:08:12 +00009126
Douglas Gregor577f75a2009-08-04 16:50:30 +00009127template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009128QualType
9129TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009130 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009131 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009132 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009133}
Mike Stump1eb44332009-09-09 15:08:12 +00009134
Douglas Gregor577f75a2009-08-04 16:50:30 +00009135template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009136QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9137 QualType T,
9138 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009139 const FunctionProtoType::ExtProtoInfo &EPI) {
9140 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009141 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009142 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009143 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009144}
Mike Stump1eb44332009-09-09 15:08:12 +00009145
Douglas Gregor577f75a2009-08-04 16:50:30 +00009146template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009147QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9148 return SemaRef.Context.getFunctionNoProtoType(T);
9149}
9150
9151template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009152QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9153 assert(D && "no decl found");
9154 if (D->isInvalidDecl()) return QualType();
9155
Douglas Gregor92e986e2010-04-22 16:44:27 +00009156 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009157 TypeDecl *Ty;
9158 if (isa<UsingDecl>(D)) {
9159 UsingDecl *Using = cast<UsingDecl>(D);
9160 assert(Using->isTypeName() &&
9161 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9162
9163 // A valid resolved using typename decl points to exactly one type decl.
9164 assert(++Using->shadow_begin() == Using->shadow_end());
9165 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009166
John McCalled976492009-12-04 22:46:56 +00009167 } else {
9168 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9169 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9170 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9171 }
9172
9173 return SemaRef.Context.getTypeDeclType(Ty);
9174}
9175
9176template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009177QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9178 SourceLocation Loc) {
9179 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009180}
9181
9182template<typename Derived>
9183QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9184 return SemaRef.Context.getTypeOfType(Underlying);
9185}
9186
9187template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009188QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9189 SourceLocation Loc) {
9190 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009191}
9192
9193template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009194QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9195 UnaryTransformType::UTTKind UKind,
9196 SourceLocation Loc) {
9197 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9198}
9199
9200template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009201QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009202 TemplateName Template,
9203 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009204 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009205 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009206}
Mike Stump1eb44332009-09-09 15:08:12 +00009207
Douglas Gregordcee1a12009-08-06 05:28:30 +00009208template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009209QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9210 SourceLocation KWLoc) {
9211 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9212}
9213
9214template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009215TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009216TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009217 bool TemplateKW,
9218 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009219 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009220 Template);
9221}
9222
9223template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009224TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009225TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9226 const IdentifierInfo &Name,
9227 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009228 QualType ObjectType,
9229 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009230 UnqualifiedId TemplateName;
9231 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009232 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009233 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009234 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009235 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009236 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009237 /*EnteringContext=*/false,
9238 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009239 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009240}
Mike Stump1eb44332009-09-09 15:08:12 +00009241
Douglas Gregorb98b1992009-08-11 05:31:07 +00009242template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009243TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009244TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009245 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009246 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009247 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009248 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009249 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009250 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009251 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009252 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009253 Sema::TemplateTy Template;
9254 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009255 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009256 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009257 /*EnteringContext=*/false,
9258 Template);
9259 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009260}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009261
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009262template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009263ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009264TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9265 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009266 Expr *OrigCallee,
9267 Expr *First,
9268 Expr *Second) {
9269 Expr *Callee = OrigCallee->IgnoreParenCasts();
9270 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009271
Douglas Gregorb98b1992009-08-11 05:31:07 +00009272 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009273 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009274 if (!First->getType()->isOverloadableType() &&
9275 !Second->getType()->isOverloadableType())
9276 return getSema().CreateBuiltinArraySubscriptExpr(First,
9277 Callee->getLocStart(),
9278 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009279 } else if (Op == OO_Arrow) {
9280 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009281 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9282 } else if (Second == 0 || isPostIncDec) {
9283 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009284 // The argument is not of overloadable type, so try to create a
9285 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009286 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009287 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009288
John McCall9ae2f072010-08-23 23:25:46 +00009289 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009290 }
9291 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009292 if (!First->getType()->isOverloadableType() &&
9293 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009294 // Neither of the arguments is an overloadable type, so try to
9295 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009296 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009297 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009298 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009299 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009300 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009301
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009302 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009303 }
9304 }
Mike Stump1eb44332009-09-09 15:08:12 +00009305
9306 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009307 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009308 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009309
John McCall9ae2f072010-08-23 23:25:46 +00009310 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009311 assert(ULE->requiresADL());
9312
9313 // FIXME: Do we have to check
9314 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009315 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009316 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009317 // If we've resolved this to a particular non-member function, just call
9318 // that function. If we resolved it to a member function,
9319 // CreateOverloaded* will find that function for us.
9320 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9321 if (!isa<CXXMethodDecl>(ND))
9322 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009323 }
Mike Stump1eb44332009-09-09 15:08:12 +00009324
Douglas Gregorb98b1992009-08-11 05:31:07 +00009325 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009326 Expr *Args[2] = { First, Second };
9327 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009328
Douglas Gregorb98b1992009-08-11 05:31:07 +00009329 // Create the overloaded operator invocation for unary operators.
9330 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009331 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009332 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009333 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009334 }
Mike Stump1eb44332009-09-09 15:08:12 +00009335
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009336 if (Op == OO_Subscript) {
9337 SourceLocation LBrace;
9338 SourceLocation RBrace;
9339
9340 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9341 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9342 LBrace = SourceLocation::getFromRawEncoding(
9343 NameLoc.CXXOperatorName.BeginOpNameLoc);
9344 RBrace = SourceLocation::getFromRawEncoding(
9345 NameLoc.CXXOperatorName.EndOpNameLoc);
9346 } else {
9347 LBrace = Callee->getLocStart();
9348 RBrace = OpLoc;
9349 }
9350
9351 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9352 First, Second);
9353 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009354
Douglas Gregorb98b1992009-08-11 05:31:07 +00009355 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009356 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009357 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009358 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9359 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009360 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009361
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009362 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009363}
Mike Stump1eb44332009-09-09 15:08:12 +00009364
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009365template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009366ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009367TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009368 SourceLocation OperatorLoc,
9369 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009370 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009371 TypeSourceInfo *ScopeType,
9372 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009373 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009374 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009375 QualType BaseType = Base->getType();
9376 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009377 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009378 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009379 !BaseType->getAs<PointerType>()->getPointeeType()
9380 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009381 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009382 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009383 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009384 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009385 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009386 /*FIXME?*/true);
9387 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009388
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009389 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009390 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9391 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9392 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9393 NameInfo.setNamedTypeInfo(DestroyedType);
9394
Richard Smith6314db92012-05-15 06:15:11 +00009395 // The scope type is now known to be a valid nested name specifier
9396 // component. Tack it on to the end of the nested name specifier.
9397 if (ScopeType)
9398 SS.Extend(SemaRef.Context, SourceLocation(),
9399 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009400
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009401 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009402 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009403 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009404 SS, TemplateKWLoc,
9405 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009406 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009407 /*TemplateArgs*/ 0);
9408}
9409
Tareq A. Siraj051303c2013-04-16 18:53:08 +00009410template<typename Derived>
9411StmtResult
9412TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
9413 llvm_unreachable("not implement yet");
9414}
9415
Douglas Gregor577f75a2009-08-04 16:50:30 +00009416} // end namespace clang
9417
9418#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H