blob: c161d8cfcb2b0b06d375cc0aa2cf42c3bc0ae618 [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,
David Blaikiea71f9d02011-09-22 02:34:54 +0000250 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000251 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000252 bool &RetainExpansion,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000253 llvm::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,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000575 llvm::Optional<unsigned> NumExpansions,
576 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000577
John McCall43fed0d2010-11-12 08:19:04 +0000578 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000579
John McCall60d7b3a2010-08-24 06:29:42 +0000580 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
581 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000582
Richard Smith612409e2012-07-25 03:56:55 +0000583 /// \brief Transform the captures and body of a lambda expression.
584 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator);
585
Richard Smithefeeccf2012-10-21 03:28:35 +0000586 ExprResult TransformAddressOfOperand(Expr *E);
587 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
588 bool IsAddressOfOperand);
589
Douglas Gregor43959a92009-08-20 07:17:43 +0000590#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000591 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000592#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000593 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000594#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000595#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000596
Douglas Gregor577f75a2009-08-04 16:50:30 +0000597 /// \brief Build a new pointer type given its pointee type.
598 ///
599 /// By default, performs semantic analysis when building the pointer type.
600 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000601 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000602
603 /// \brief Build a new block pointer type given its pointee type.
604 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000605 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000606 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000607 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000608
John McCall85737a72009-10-30 00:06:24 +0000609 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000610 ///
John McCall85737a72009-10-30 00:06:24 +0000611 /// By default, performs semantic analysis when building the
612 /// reference type. Subclasses may override this routine to provide
613 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000614 ///
John McCall85737a72009-10-30 00:06:24 +0000615 /// \param LValue whether the type was written with an lvalue sigil
616 /// or an rvalue sigil.
617 QualType RebuildReferenceType(QualType ReferentType,
618 bool LValue,
619 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000620
Douglas Gregor577f75a2009-08-04 16:50:30 +0000621 /// \brief Build a new member pointer type given the pointee type and the
622 /// class type it refers into.
623 ///
624 /// By default, performs semantic analysis when building the member pointer
625 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000626 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
627 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000628
Douglas Gregor577f75a2009-08-04 16:50:30 +0000629 /// \brief Build a new array type given the element type, size
630 /// modifier, size of the array (if known), size expression, and index type
631 /// qualifiers.
632 ///
633 /// By default, performs semantic analysis when building the array type.
634 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000635 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000636 QualType RebuildArrayType(QualType ElementType,
637 ArrayType::ArraySizeModifier SizeMod,
638 const llvm::APInt *Size,
639 Expr *SizeExpr,
640 unsigned IndexTypeQuals,
641 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000642
Douglas Gregor577f75a2009-08-04 16:50:30 +0000643 /// \brief Build a new constant array type given the element type, size
644 /// modifier, (known) size of the array, and index type qualifiers.
645 ///
646 /// By default, performs semantic analysis when building the array type.
647 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000648 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000649 ArrayType::ArraySizeModifier SizeMod,
650 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000651 unsigned IndexTypeQuals,
652 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000653
Douglas Gregor577f75a2009-08-04 16:50:30 +0000654 /// \brief Build a new incomplete array type given the element type, size
655 /// modifier, and index type qualifiers.
656 ///
657 /// By default, performs semantic analysis when building the array type.
658 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000659 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000660 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000661 unsigned IndexTypeQuals,
662 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000663
Mike Stump1eb44332009-09-09 15:08:12 +0000664 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000665 /// size modifier, size expression, and index type qualifiers.
666 ///
667 /// By default, performs semantic analysis when building the array type.
668 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000669 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000670 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000671 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000672 unsigned IndexTypeQuals,
673 SourceRange BracketsRange);
674
Mike Stump1eb44332009-09-09 15:08:12 +0000675 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000676 /// size modifier, size expression, and index type qualifiers.
677 ///
678 /// By default, performs semantic analysis when building the array type.
679 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000680 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000681 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000682 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000683 unsigned IndexTypeQuals,
684 SourceRange BracketsRange);
685
686 /// \brief Build a new vector type given the element type and
687 /// number of elements.
688 ///
689 /// By default, performs semantic analysis when building the vector type.
690 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000691 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000692 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000693
Douglas Gregor577f75a2009-08-04 16:50:30 +0000694 /// \brief Build a new extended vector type given the element type and
695 /// number of elements.
696 ///
697 /// By default, performs semantic analysis when building the vector type.
698 /// Subclasses may override this routine to provide different behavior.
699 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
700 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000701
702 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000703 /// given the element type and number of elements.
704 ///
705 /// By default, performs semantic analysis when building the vector type.
706 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000707 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000708 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000709 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000710
Douglas Gregor577f75a2009-08-04 16:50:30 +0000711 /// \brief Build a new function type.
712 ///
713 /// By default, performs semantic analysis when building the function type.
714 /// Subclasses may override this routine to provide different behavior.
715 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000716 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000717 unsigned NumParamTypes,
Richard Smitheefb3d52012-02-10 09:58:53 +0000718 bool Variadic, bool HasTrailingReturn,
719 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000720 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000721 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000722
John McCalla2becad2009-10-21 00:40:46 +0000723 /// \brief Build a new unprototyped function type.
724 QualType RebuildFunctionNoProtoType(QualType ResultType);
725
John McCalled976492009-12-04 22:46:56 +0000726 /// \brief Rebuild an unresolved typename type, given the decl that
727 /// the UnresolvedUsingTypenameDecl was transformed to.
728 QualType RebuildUnresolvedUsingType(Decl *D);
729
Douglas Gregor577f75a2009-08-04 16:50:30 +0000730 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000731 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000732 return SemaRef.Context.getTypeDeclType(Typedef);
733 }
734
735 /// \brief Build a new class/struct/union type.
736 QualType RebuildRecordType(RecordDecl *Record) {
737 return SemaRef.Context.getTypeDeclType(Record);
738 }
739
740 /// \brief Build a new Enum type.
741 QualType RebuildEnumType(EnumDecl *Enum) {
742 return SemaRef.Context.getTypeDeclType(Enum);
743 }
John McCall7da24312009-09-05 00:15:47 +0000744
Mike Stump1eb44332009-09-09 15:08:12 +0000745 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000746 ///
747 /// By default, performs semantic analysis when building the typeof type.
748 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000749 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000750
Mike Stump1eb44332009-09-09 15:08:12 +0000751 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000752 ///
753 /// By default, builds a new TypeOfType with the given underlying type.
754 QualType RebuildTypeOfType(QualType Underlying);
755
Sean Huntca63c202011-05-24 22:41:36 +0000756 /// \brief Build a new unary transform type.
757 QualType RebuildUnaryTransformType(QualType BaseType,
758 UnaryTransformType::UTTKind UKind,
759 SourceLocation Loc);
760
Mike Stump1eb44332009-09-09 15:08:12 +0000761 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000762 ///
763 /// By default, performs semantic analysis when building the decltype type.
764 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000765 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000766
Richard Smith34b41d92011-02-20 03:19:35 +0000767 /// \brief Build a new C++0x auto type.
768 ///
769 /// By default, builds a new AutoType with the given deduced type.
770 QualType RebuildAutoType(QualType Deduced) {
771 return SemaRef.Context.getAutoType(Deduced);
772 }
773
Douglas Gregor577f75a2009-08-04 16:50:30 +0000774 /// \brief Build a new template specialization type.
775 ///
776 /// By default, performs semantic analysis when building the template
777 /// specialization type. Subclasses may override this routine to provide
778 /// different behavior.
779 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000780 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000781 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000782
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000783 /// \brief Build a new parenthesized type.
784 ///
785 /// By default, builds a new ParenType type from the inner type.
786 /// Subclasses may override this routine to provide different behavior.
787 QualType RebuildParenType(QualType InnerType) {
788 return SemaRef.Context.getParenType(InnerType);
789 }
790
Douglas Gregor577f75a2009-08-04 16:50:30 +0000791 /// \brief Build a new qualified name type.
792 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000793 /// By default, builds a new ElaboratedType type from the keyword,
794 /// the nested-name-specifier and the named type.
795 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000796 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
797 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000798 NestedNameSpecifierLoc QualifierLoc,
799 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000800 return SemaRef.Context.getElaboratedType(Keyword,
801 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000802 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000803 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000804
805 /// \brief Build a new typename type that refers to a template-id.
806 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000807 /// By default, builds a new DependentNameType type from the
808 /// nested-name-specifier and the given type. Subclasses may override
809 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000810 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000811 ElaboratedTypeKeyword Keyword,
812 NestedNameSpecifierLoc QualifierLoc,
813 const IdentifierInfo *Name,
814 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000815 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000816 // Rebuild the template name.
817 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000818 CXXScopeSpec SS;
819 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000820 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000821 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000822
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000823 if (InstName.isNull())
824 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000825
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000826 // If it's still dependent, make a dependent specialization.
827 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000828 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
829 QualifierLoc.getNestedNameSpecifier(),
830 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000831 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000832
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000833 // Otherwise, make an elaborated type wrapping a non-dependent
834 // specialization.
835 QualType T =
836 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
837 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000838
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000839 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
840 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000841
842 return SemaRef.Context.getElaboratedType(Keyword,
843 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000844 T);
845 }
846
Douglas Gregor577f75a2009-08-04 16:50:30 +0000847 /// \brief Build a new typename type that refers to an identifier.
848 ///
849 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000850 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000851 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000852 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000853 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000854 NestedNameSpecifierLoc QualifierLoc,
855 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000856 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000857 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000858 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000859
Douglas Gregor2494dd02011-03-01 01:34:45 +0000860 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000861 // If the name is still dependent, just build a new dependent name type.
862 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000863 return SemaRef.Context.getDependentNameType(Keyword,
864 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000865 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000866 }
867
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000868 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000869 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000870 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000871
872 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
873
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000874 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000875 // into a non-dependent elaborated-type-specifier. Find the tag we're
876 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000877 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000878 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
879 if (!DC)
880 return QualType();
881
John McCall56138762010-05-27 06:40:31 +0000882 if (SemaRef.RequireCompleteDeclContext(SS, DC))
883 return QualType();
884
Douglas Gregor40336422010-03-31 22:19:08 +0000885 TagDecl *Tag = 0;
886 SemaRef.LookupQualifiedName(Result, DC);
887 switch (Result.getResultKind()) {
888 case LookupResult::NotFound:
889 case LookupResult::NotFoundInCurrentInstantiation:
890 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000891
Douglas Gregor40336422010-03-31 22:19:08 +0000892 case LookupResult::Found:
893 Tag = Result.getAsSingle<TagDecl>();
894 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000895
Douglas Gregor40336422010-03-31 22:19:08 +0000896 case LookupResult::FoundOverloaded:
897 case LookupResult::FoundUnresolvedValue:
898 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000899
Douglas Gregor40336422010-03-31 22:19:08 +0000900 case LookupResult::Ambiguous:
901 // Let the LookupResult structure handle ambiguities.
902 return QualType();
903 }
904
905 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000906 // Check where the name exists but isn't a tag type and use that to emit
907 // better diagnostics.
908 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
909 SemaRef.LookupQualifiedName(Result, DC);
910 switch (Result.getResultKind()) {
911 case LookupResult::Found:
912 case LookupResult::FoundOverloaded:
913 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000914 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000915 unsigned Kind = 0;
916 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000917 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
918 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000919 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
920 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
921 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000922 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000923 default:
924 // FIXME: Would be nice to highlight just the source range.
925 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
926 << Kind << Id << DC;
927 break;
928 }
Douglas Gregor40336422010-03-31 22:19:08 +0000929 return QualType();
930 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000931
Richard Trieubbf34c02011-06-10 03:11:26 +0000932 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
933 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000934 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000935 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
936 return QualType();
937 }
938
939 // Build the elaborated-type-specifier type.
940 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000941 return SemaRef.Context.getElaboratedType(Keyword,
942 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000943 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000944 }
Mike Stump1eb44332009-09-09 15:08:12 +0000945
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000946 /// \brief Build a new pack expansion type.
947 ///
948 /// By default, builds a new PackExpansionType type from the given pattern.
949 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000950 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000951 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000952 SourceLocation EllipsisLoc,
953 llvm::Optional<unsigned> NumExpansions) {
954 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
955 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000956 }
957
Eli Friedmanb001de72011-10-06 23:00:33 +0000958 /// \brief Build a new atomic type given its value type.
959 ///
960 /// By default, performs semantic analysis when building the atomic type.
961 /// Subclasses may override this routine to provide different behavior.
962 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
963
Douglas Gregord1067e52009-08-06 06:41:21 +0000964 /// \brief Build a new template name given a nested name specifier, a flag
965 /// indicating whether the "template" keyword was provided, and the template
966 /// that the template name refers to.
967 ///
968 /// By default, builds the new template name directly. Subclasses may override
969 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000970 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000971 bool TemplateKW,
972 TemplateDecl *Template);
973
Douglas Gregord1067e52009-08-06 06:41:21 +0000974 /// \brief Build a new template name given a nested name specifier and the
975 /// name that is referred to as a template.
976 ///
977 /// By default, performs semantic analysis to determine whether the name can
978 /// be resolved to a specific template, then builds the appropriate kind of
979 /// template name. Subclasses may override this routine to provide different
980 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000981 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
982 const IdentifierInfo &Name,
983 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000984 QualType ObjectType,
985 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000986
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000987 /// \brief Build a new template name given a nested name specifier and the
988 /// overloaded operator name that is referred to as a template.
989 ///
990 /// By default, performs semantic analysis to determine whether the name can
991 /// be resolved to a specific template, then builds the appropriate kind of
992 /// template name. Subclasses may override this routine to provide different
993 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000994 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000995 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000996 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000997 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000998
999 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +00001000 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001001 ///
1002 /// By default, performs semantic analysis to determine whether the name can
1003 /// be resolved to a specific template, then builds the appropriate kind of
1004 /// template name. Subclasses may override this routine to provide different
1005 /// behavior.
1006 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1007 const TemplateArgument &ArgPack) {
1008 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1009 }
1010
Douglas Gregor43959a92009-08-20 07:17:43 +00001011 /// \brief Build a new compound statement.
1012 ///
1013 /// By default, performs semantic analysis to build the new statement.
1014 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001015 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001016 MultiStmtArg Statements,
1017 SourceLocation RBraceLoc,
1018 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001019 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001020 IsStmtExpr);
1021 }
1022
1023 /// \brief Build a new case statement.
1024 ///
1025 /// By default, performs semantic analysis to build the new statement.
1026 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001027 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001028 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001029 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001030 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001031 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001032 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001033 ColonLoc);
1034 }
Mike Stump1eb44332009-09-09 15:08:12 +00001035
Douglas Gregor43959a92009-08-20 07:17:43 +00001036 /// \brief Attach the body to a new case statement.
1037 ///
1038 /// By default, performs semantic analysis to build the new statement.
1039 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001040 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001041 getSema().ActOnCaseStmtBody(S, Body);
1042 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001043 }
Mike Stump1eb44332009-09-09 15:08:12 +00001044
Douglas Gregor43959a92009-08-20 07:17:43 +00001045 /// \brief Build a new default statement.
1046 ///
1047 /// By default, performs semantic analysis to build the new statement.
1048 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001049 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001050 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001051 Stmt *SubStmt) {
1052 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001053 /*CurScope=*/0);
1054 }
Mike Stump1eb44332009-09-09 15:08:12 +00001055
Douglas Gregor43959a92009-08-20 07:17:43 +00001056 /// \brief Build a new label statement.
1057 ///
1058 /// By default, performs semantic analysis to build the new statement.
1059 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001060 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1061 SourceLocation ColonLoc, Stmt *SubStmt) {
1062 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001063 }
Mike Stump1eb44332009-09-09 15:08:12 +00001064
Richard Smith534986f2012-04-14 00:33:13 +00001065 /// \brief Build a new label statement.
1066 ///
1067 /// By default, performs semantic analysis to build the new statement.
1068 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001069 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1070 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001071 Stmt *SubStmt) {
1072 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1073 }
1074
Douglas Gregor43959a92009-08-20 07:17:43 +00001075 /// \brief Build a new "if" statement.
1076 ///
1077 /// By default, performs semantic analysis to build the new statement.
1078 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001079 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001080 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001081 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001082 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001083 }
Mike Stump1eb44332009-09-09 15:08:12 +00001084
Douglas Gregor43959a92009-08-20 07:17:43 +00001085 /// \brief Start building a new switch statement.
1086 ///
1087 /// By default, performs semantic analysis to build the new statement.
1088 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001089 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001090 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001091 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001092 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001093 }
Mike Stump1eb44332009-09-09 15:08:12 +00001094
Douglas Gregor43959a92009-08-20 07:17:43 +00001095 /// \brief Attach the body to the switch statement.
1096 ///
1097 /// By default, performs semantic analysis to build the new statement.
1098 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001099 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001100 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001101 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001102 }
1103
1104 /// \brief Build a new while statement.
1105 ///
1106 /// By default, performs semantic analysis to build the new statement.
1107 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001108 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1109 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001110 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001111 }
Mike Stump1eb44332009-09-09 15:08:12 +00001112
Douglas Gregor43959a92009-08-20 07:17:43 +00001113 /// \brief Build a new do-while statement.
1114 ///
1115 /// By default, performs semantic analysis to build the new statement.
1116 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001117 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001118 SourceLocation WhileLoc, SourceLocation LParenLoc,
1119 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001120 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1121 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001122 }
1123
1124 /// \brief Build a new for statement.
1125 ///
1126 /// By default, performs semantic analysis to build the new statement.
1127 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001128 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001129 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001130 VarDecl *CondVar, Sema::FullExprArg Inc,
1131 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001132 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001133 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001134 }
Mike Stump1eb44332009-09-09 15:08:12 +00001135
Douglas Gregor43959a92009-08-20 07:17:43 +00001136 /// \brief Build a new goto statement.
1137 ///
1138 /// By default, performs semantic analysis to build the new statement.
1139 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001140 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1141 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001142 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001143 }
1144
1145 /// \brief Build a new indirect goto statement.
1146 ///
1147 /// By default, performs semantic analysis to build the new statement.
1148 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001149 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001150 SourceLocation StarLoc,
1151 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001152 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001153 }
Mike Stump1eb44332009-09-09 15:08:12 +00001154
Douglas Gregor43959a92009-08-20 07:17:43 +00001155 /// \brief Build a new return statement.
1156 ///
1157 /// By default, performs semantic analysis to build the new statement.
1158 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001159 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001160 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001161 }
Mike Stump1eb44332009-09-09 15:08:12 +00001162
Douglas Gregor43959a92009-08-20 07:17:43 +00001163 /// \brief Build a new declaration statement.
1164 ///
1165 /// By default, performs semantic analysis to build the new statement.
1166 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001167 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001168 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001169 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001170 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1171 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001172 }
Mike Stump1eb44332009-09-09 15:08:12 +00001173
Anders Carlsson703e3942010-01-24 05:50:09 +00001174 /// \brief Build a new inline asm statement.
1175 ///
1176 /// By default, performs semantic analysis to build the new statement.
1177 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001178 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1179 bool IsVolatile, unsigned NumOutputs,
1180 unsigned NumInputs, IdentifierInfo **Names,
1181 MultiExprArg Constraints, MultiExprArg Exprs,
1182 Expr *AsmString, MultiExprArg Clobbers,
1183 SourceLocation RParenLoc) {
1184 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1185 NumInputs, Names, Constraints, Exprs,
1186 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001187 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001188
Chad Rosier8cd64b42012-06-11 20:47:18 +00001189 /// \brief Build a new MS style inline asm statement.
1190 ///
1191 /// By default, performs semantic analysis to build the new statement.
1192 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001193 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
1194 ArrayRef<Token> AsmToks, SourceLocation EndLoc) {
Chad Rosier7bd092b2012-08-15 16:53:30 +00001195 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001196 }
1197
James Dennett699c9042012-06-15 07:13:21 +00001198 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001199 ///
1200 /// By default, performs semantic analysis to build the new statement.
1201 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001202 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001203 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001204 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001205 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001206 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001207 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001208 }
1209
Douglas Gregorbe270a02010-04-26 17:57:08 +00001210 /// \brief Rebuild an Objective-C exception declaration.
1211 ///
1212 /// By default, performs semantic analysis to build the new declaration.
1213 /// Subclasses may override this routine to provide different behavior.
1214 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1215 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001216 return getSema().BuildObjCExceptionDecl(TInfo, T,
1217 ExceptionDecl->getInnerLocStart(),
1218 ExceptionDecl->getLocation(),
1219 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001220 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001221
James Dennett699c9042012-06-15 07:13:21 +00001222 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001223 ///
1224 /// By default, performs semantic analysis to build the new statement.
1225 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001226 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001227 SourceLocation RParenLoc,
1228 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001229 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001230 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001231 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001232 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001233
James Dennett699c9042012-06-15 07:13:21 +00001234 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001235 ///
1236 /// By default, performs semantic analysis to build the new statement.
1237 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001238 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001239 Stmt *Body) {
1240 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001241 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001242
James Dennett699c9042012-06-15 07:13:21 +00001243 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001244 ///
1245 /// By default, performs semantic analysis to build the new statement.
1246 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001247 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001248 Expr *Operand) {
1249 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001250 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001251
James Dennett699c9042012-06-15 07:13:21 +00001252 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001253 ///
1254 /// By default, performs semantic analysis to build the new statement.
1255 /// Subclasses may override this routine to provide different behavior.
1256 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1257 Expr *object) {
1258 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1259 }
1260
James Dennett699c9042012-06-15 07:13:21 +00001261 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001262 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001263 /// By default, performs semantic analysis to build the new statement.
1264 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001265 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001266 Expr *Object, Stmt *Body) {
1267 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001268 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001269
James Dennett699c9042012-06-15 07:13:21 +00001270 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001271 ///
1272 /// By default, performs semantic analysis to build the new statement.
1273 /// Subclasses may override this routine to provide different behavior.
1274 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1275 Stmt *Body) {
1276 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1277 }
John McCall990567c2011-07-27 01:07:15 +00001278
Douglas Gregorc3203e72010-04-22 23:10:45 +00001279 /// \brief Build a new Objective-C fast enumeration statement.
1280 ///
1281 /// By default, performs semantic analysis to build the new statement.
1282 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001283 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001284 Stmt *Element,
1285 Expr *Collection,
1286 SourceLocation RParenLoc,
1287 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001288 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001289 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001290 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001291 RParenLoc);
1292 if (ForEachStmt.isInvalid())
1293 return StmtError();
1294
1295 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001296 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001297
Douglas Gregor43959a92009-08-20 07:17:43 +00001298 /// \brief Build a new C++ exception declaration.
1299 ///
1300 /// By default, performs semantic analysis to build the new decaration.
1301 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001302 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001303 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001304 SourceLocation StartLoc,
1305 SourceLocation IdLoc,
1306 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001307 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1308 StartLoc, IdLoc, Id);
1309 if (Var)
1310 getSema().CurContext->addDecl(Var);
1311 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001312 }
1313
1314 /// \brief Build a new C++ catch statement.
1315 ///
1316 /// By default, performs semantic analysis to build the new statement.
1317 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001318 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001319 VarDecl *ExceptionDecl,
1320 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001321 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1322 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001323 }
Mike Stump1eb44332009-09-09 15:08:12 +00001324
Douglas Gregor43959a92009-08-20 07:17:43 +00001325 /// \brief Build a new C++ try statement.
1326 ///
1327 /// By default, performs semantic analysis to build the new statement.
1328 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001329 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001330 Stmt *TryBlock,
1331 MultiStmtArg Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001332 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001333 }
Mike Stump1eb44332009-09-09 15:08:12 +00001334
Richard Smithad762fc2011-04-14 22:09:26 +00001335 /// \brief Build a new C++0x range-based for statement.
1336 ///
1337 /// By default, performs semantic analysis to build the new statement.
1338 /// Subclasses may override this routine to provide different behavior.
1339 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1340 SourceLocation ColonLoc,
1341 Stmt *Range, Stmt *BeginEnd,
1342 Expr *Cond, Expr *Inc,
1343 Stmt *LoopVar,
1344 SourceLocation RParenLoc) {
1345 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001346 Cond, Inc, LoopVar, RParenLoc,
1347 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001348 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001349
1350 /// \brief Build a new C++0x range-based for statement.
1351 ///
1352 /// By default, performs semantic analysis to build the new statement.
1353 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001354 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001355 bool IsIfExists,
1356 NestedNameSpecifierLoc QualifierLoc,
1357 DeclarationNameInfo NameInfo,
1358 Stmt *Nested) {
1359 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1360 QualifierLoc, NameInfo, Nested);
1361 }
1362
Richard Smithad762fc2011-04-14 22:09:26 +00001363 /// \brief Attach body to a C++0x range-based for statement.
1364 ///
1365 /// By default, performs semantic analysis to finish the new statement.
1366 /// Subclasses may override this routine to provide different behavior.
1367 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1368 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1369 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001370
John Wiegley28bbe4b2011-04-28 01:08:34 +00001371 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1372 SourceLocation TryLoc,
1373 Stmt *TryBlock,
1374 Stmt *Handler) {
1375 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1376 }
1377
1378 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1379 Expr *FilterExpr,
1380 Stmt *Block) {
1381 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1382 }
1383
1384 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1385 Stmt *Block) {
1386 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1387 }
1388
Douglas Gregorb98b1992009-08-11 05:31:07 +00001389 /// \brief Build a new expression that references a declaration.
1390 ///
1391 /// By default, performs semantic analysis to build the new expression.
1392 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001393 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001394 LookupResult &R,
1395 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001396 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1397 }
1398
1399
1400 /// \brief Build a new expression that references a declaration.
1401 ///
1402 /// By default, performs semantic analysis to build the new expression.
1403 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001404 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001405 ValueDecl *VD,
1406 const DeclarationNameInfo &NameInfo,
1407 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001408 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001409 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001410
1411 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001412
1413 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001414 }
Mike Stump1eb44332009-09-09 15:08:12 +00001415
Douglas Gregorb98b1992009-08-11 05:31:07 +00001416 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001417 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001418 /// By default, performs semantic analysis to build the new expression.
1419 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001420 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001421 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001422 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001423 }
1424
Douglas Gregora71d8192009-09-04 17:36:40 +00001425 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001426 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001427 /// By default, performs semantic analysis to build the new expression.
1428 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001429 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001430 SourceLocation OperatorLoc,
1431 bool isArrow,
1432 CXXScopeSpec &SS,
1433 TypeSourceInfo *ScopeType,
1434 SourceLocation CCLoc,
1435 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001436 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001437
Douglas Gregorb98b1992009-08-11 05:31:07 +00001438 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001439 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001440 /// By default, performs semantic analysis to build the new expression.
1441 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001442 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001443 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001444 Expr *SubExpr) {
1445 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001446 }
Mike Stump1eb44332009-09-09 15:08:12 +00001447
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001448 /// \brief Build a new builtin offsetof expression.
1449 ///
1450 /// By default, performs semantic analysis to build the new expression.
1451 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001452 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001453 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001454 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001455 unsigned NumComponents,
1456 SourceLocation RParenLoc) {
1457 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1458 NumComponents, RParenLoc);
1459 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001460
1461 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001462 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001463 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001464 /// By default, performs semantic analysis to build the new expression.
1465 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001466 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1467 SourceLocation OpLoc,
1468 UnaryExprOrTypeTrait ExprKind,
1469 SourceRange R) {
1470 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001471 }
1472
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001473 /// \brief Build a new sizeof, alignof or vec step expression with an
1474 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001475 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001476 /// By default, performs semantic analysis to build the new expression.
1477 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001478 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1479 UnaryExprOrTypeTrait ExprKind,
1480 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001481 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001482 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001483 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001484 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001485
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001486 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001487 }
Mike Stump1eb44332009-09-09 15:08:12 +00001488
Douglas Gregorb98b1992009-08-11 05:31:07 +00001489 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001490 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001491 /// By default, performs semantic analysis to build the new expression.
1492 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001493 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001494 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001495 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001496 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001497 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1498 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001499 RBracketLoc);
1500 }
1501
1502 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001503 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001504 /// By default, performs semantic analysis to build the new expression.
1505 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001506 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001507 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001508 SourceLocation RParenLoc,
1509 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001510 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001511 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001512 }
1513
1514 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001515 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001516 /// By default, performs semantic analysis to build the new expression.
1517 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001518 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001519 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001520 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001521 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001522 const DeclarationNameInfo &MemberNameInfo,
1523 ValueDecl *Member,
1524 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001525 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001526 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001527 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1528 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001529 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001530 // We have a reference to an unnamed field. This is always the
1531 // base of an anonymous struct/union member access, i.e. the
1532 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001533 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001534 assert(Member->getType()->isRecordType() &&
1535 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001536
Richard Smith9138b4e2011-10-26 19:06:56 +00001537 BaseResult =
1538 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001539 QualifierLoc.getNestedNameSpecifier(),
1540 FoundDecl, Member);
1541 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001542 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001543 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001544 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001545 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001546 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001547 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001548 cast<FieldDecl>(Member)->getType(),
1549 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001550 return getSema().Owned(ME);
1551 }
Mike Stump1eb44332009-09-09 15:08:12 +00001552
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001553 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001554 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001555
John Wiegley429bb272011-04-08 18:41:53 +00001556 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001557 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001558
John McCall6bb80172010-03-30 21:47:33 +00001559 // FIXME: this involves duplicating earlier analysis in a lot of
1560 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001561 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001562 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001563 R.resolveKind();
1564
John McCall9ae2f072010-08-23 23:25:46 +00001565 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001566 SS, TemplateKWLoc,
1567 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001568 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001569 }
Mike Stump1eb44332009-09-09 15:08:12 +00001570
Douglas Gregorb98b1992009-08-11 05:31:07 +00001571 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001572 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001573 /// By default, performs semantic analysis to build the new expression.
1574 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001575 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001576 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001577 Expr *LHS, Expr *RHS) {
1578 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001579 }
1580
1581 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001582 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001583 /// By default, performs semantic analysis to build the new expression.
1584 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001585 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001586 SourceLocation QuestionLoc,
1587 Expr *LHS,
1588 SourceLocation ColonLoc,
1589 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001590 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1591 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001592 }
1593
Douglas Gregorb98b1992009-08-11 05:31:07 +00001594 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001595 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001596 /// By default, performs semantic analysis to build the new expression.
1597 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001598 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001599 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001600 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001601 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001602 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001603 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001604 }
Mike Stump1eb44332009-09-09 15:08:12 +00001605
Douglas Gregorb98b1992009-08-11 05:31:07 +00001606 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001607 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001608 /// By default, performs semantic analysis to build the new expression.
1609 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001610 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001611 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001612 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001613 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001614 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001615 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001616 }
Mike Stump1eb44332009-09-09 15:08:12 +00001617
Douglas Gregorb98b1992009-08-11 05:31:07 +00001618 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001619 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001620 /// By default, performs semantic analysis to build the new expression.
1621 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001622 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001623 SourceLocation OpLoc,
1624 SourceLocation AccessorLoc,
1625 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001626
John McCall129e2df2009-11-30 22:42:35 +00001627 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001628 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001629 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001630 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001631 SS, SourceLocation(),
1632 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001633 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001634 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001635 }
Mike Stump1eb44332009-09-09 15:08:12 +00001636
Douglas Gregorb98b1992009-08-11 05:31:07 +00001637 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001638 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001639 /// By default, performs semantic analysis to build the new expression.
1640 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001641 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001642 MultiExprArg Inits,
1643 SourceLocation RBraceLoc,
1644 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001645 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001646 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001647 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001648 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001649
Douglas Gregore48319a2009-11-09 17:16:50 +00001650 // Patch in the result type we were given, which may have been computed
1651 // when the initial InitListExpr was built.
1652 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1653 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001654 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001655 }
Mike Stump1eb44332009-09-09 15:08:12 +00001656
Douglas Gregorb98b1992009-08-11 05:31:07 +00001657 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001658 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001659 /// By default, performs semantic analysis to build the new expression.
1660 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001661 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001662 MultiExprArg ArrayExprs,
1663 SourceLocation EqualOrColonLoc,
1664 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001665 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001666 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001667 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001668 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001669 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001670 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001671
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001672 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001673 }
Mike Stump1eb44332009-09-09 15:08:12 +00001674
Douglas Gregorb98b1992009-08-11 05:31:07 +00001675 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001676 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001677 /// By default, builds the implicit value initialization without performing
1678 /// any semantic analysis. Subclasses may override this routine to provide
1679 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001680 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001681 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1682 }
Mike Stump1eb44332009-09-09 15:08:12 +00001683
Douglas Gregorb98b1992009-08-11 05:31:07 +00001684 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001685 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001686 /// By default, performs semantic analysis to build the new expression.
1687 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001688 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001689 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001690 SourceLocation RParenLoc) {
1691 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001692 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001693 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001694 }
1695
1696 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001697 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001698 /// By default, performs semantic analysis to build the new expression.
1699 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001700 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001701 MultiExprArg SubExprs,
1702 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001703 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001704 }
Mike Stump1eb44332009-09-09 15:08:12 +00001705
Douglas Gregorb98b1992009-08-11 05:31:07 +00001706 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001707 ///
1708 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001709 /// rather than attempting to map the label statement itself.
1710 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001711 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001712 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001713 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001714 }
Mike Stump1eb44332009-09-09 15:08:12 +00001715
Douglas Gregorb98b1992009-08-11 05:31:07 +00001716 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001717 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 /// By default, performs semantic analysis to build the new expression.
1719 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001720 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001721 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001722 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001723 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001724 }
Mike Stump1eb44332009-09-09 15:08:12 +00001725
Douglas Gregorb98b1992009-08-11 05:31:07 +00001726 /// \brief Build a new __builtin_choose_expr expression.
1727 ///
1728 /// By default, performs semantic analysis to build the new expression.
1729 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001730 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001731 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001732 SourceLocation RParenLoc) {
1733 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001734 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001735 RParenLoc);
1736 }
Mike Stump1eb44332009-09-09 15:08:12 +00001737
Peter Collingbournef111d932011-04-15 00:35:48 +00001738 /// \brief Build a new generic selection expression.
1739 ///
1740 /// By default, performs semantic analysis to build the new expression.
1741 /// Subclasses may override this routine to provide different behavior.
1742 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1743 SourceLocation DefaultLoc,
1744 SourceLocation RParenLoc,
1745 Expr *ControllingExpr,
1746 TypeSourceInfo **Types,
1747 Expr **Exprs,
1748 unsigned NumAssocs) {
1749 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1750 ControllingExpr, Types, Exprs,
1751 NumAssocs);
1752 }
1753
Douglas Gregorb98b1992009-08-11 05:31:07 +00001754 /// \brief Build a new overloaded operator call expression.
1755 ///
1756 /// By default, performs semantic analysis to build the new expression.
1757 /// The semantic analysis provides the behavior of template instantiation,
1758 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001759 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001760 /// argument-dependent lookup, etc. Subclasses may override this routine to
1761 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001762 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001763 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001764 Expr *Callee,
1765 Expr *First,
1766 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001767
1768 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001769 /// reinterpret_cast.
1770 ///
1771 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001772 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001773 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001774 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001775 Stmt::StmtClass Class,
1776 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001777 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001778 SourceLocation RAngleLoc,
1779 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001780 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001781 SourceLocation RParenLoc) {
1782 switch (Class) {
1783 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001784 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001785 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001786 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001787
1788 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001789 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001790 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001791 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001792
Douglas Gregorb98b1992009-08-11 05:31:07 +00001793 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001794 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001795 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001796 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001797 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001798
Douglas Gregorb98b1992009-08-11 05:31:07 +00001799 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001800 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001801 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001802 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001803
Douglas Gregorb98b1992009-08-11 05:31:07 +00001804 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001805 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001806 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001807 }
Mike Stump1eb44332009-09-09 15:08:12 +00001808
Douglas Gregorb98b1992009-08-11 05:31:07 +00001809 /// \brief Build a new C++ static_cast expression.
1810 ///
1811 /// By default, performs semantic analysis to build the new expression.
1812 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001813 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001814 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001815 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001816 SourceLocation RAngleLoc,
1817 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001818 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001819 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001820 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001821 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001822 SourceRange(LAngleLoc, RAngleLoc),
1823 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001824 }
1825
1826 /// \brief Build a new C++ dynamic_cast expression.
1827 ///
1828 /// By default, performs semantic analysis to build the new expression.
1829 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001830 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001831 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001832 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001833 SourceLocation RAngleLoc,
1834 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001835 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001836 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001837 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001838 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001839 SourceRange(LAngleLoc, RAngleLoc),
1840 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001841 }
1842
1843 /// \brief Build a new C++ reinterpret_cast expression.
1844 ///
1845 /// By default, performs semantic analysis to build the new expression.
1846 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001847 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001848 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001849 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001850 SourceLocation RAngleLoc,
1851 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001852 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001853 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001854 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001855 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001856 SourceRange(LAngleLoc, RAngleLoc),
1857 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001858 }
1859
1860 /// \brief Build a new C++ const_cast expression.
1861 ///
1862 /// By default, performs semantic analysis to build the new expression.
1863 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001864 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001865 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001866 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001867 SourceLocation RAngleLoc,
1868 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001869 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001870 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001871 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001872 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001873 SourceRange(LAngleLoc, RAngleLoc),
1874 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001875 }
Mike Stump1eb44332009-09-09 15:08:12 +00001876
Douglas Gregorb98b1992009-08-11 05:31:07 +00001877 /// \brief Build a new C++ functional-style cast expression.
1878 ///
1879 /// By default, performs semantic analysis to build the new expression.
1880 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001881 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1882 SourceLocation LParenLoc,
1883 Expr *Sub,
1884 SourceLocation RParenLoc) {
1885 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001886 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001887 RParenLoc);
1888 }
Mike Stump1eb44332009-09-09 15:08:12 +00001889
Douglas Gregorb98b1992009-08-11 05:31:07 +00001890 /// \brief Build a new C++ typeid(type) expression.
1891 ///
1892 /// By default, performs semantic analysis to build the new expression.
1893 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001894 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001895 SourceLocation TypeidLoc,
1896 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001897 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001898 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001899 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001900 }
Mike Stump1eb44332009-09-09 15:08:12 +00001901
Francois Pichet01b7c302010-09-08 12:20:18 +00001902
Douglas Gregorb98b1992009-08-11 05:31:07 +00001903 /// \brief Build a new C++ typeid(expr) expression.
1904 ///
1905 /// By default, performs semantic analysis to build the new expression.
1906 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001907 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001908 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001909 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001910 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001911 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001912 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001913 }
1914
Francois Pichet01b7c302010-09-08 12:20:18 +00001915 /// \brief Build a new C++ __uuidof(type) expression.
1916 ///
1917 /// By default, performs semantic analysis to build the new expression.
1918 /// Subclasses may override this routine to provide different behavior.
1919 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1920 SourceLocation TypeidLoc,
1921 TypeSourceInfo *Operand,
1922 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001923 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00001924 RParenLoc);
1925 }
1926
1927 /// \brief Build a new C++ __uuidof(expr) expression.
1928 ///
1929 /// By default, performs semantic analysis to build the new expression.
1930 /// Subclasses may override this routine to provide different behavior.
1931 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1932 SourceLocation TypeidLoc,
1933 Expr *Operand,
1934 SourceLocation RParenLoc) {
1935 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1936 RParenLoc);
1937 }
1938
Douglas Gregorb98b1992009-08-11 05:31:07 +00001939 /// \brief Build a new C++ "this" expression.
1940 ///
1941 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001942 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001943 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001944 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001945 QualType ThisType,
1946 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001947 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001948 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001949 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1950 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001951 }
1952
1953 /// \brief Build a new C++ throw expression.
1954 ///
1955 /// By default, performs semantic analysis to build the new expression.
1956 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001957 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1958 bool IsThrownVariableInScope) {
1959 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001960 }
1961
1962 /// \brief Build a new C++ default-argument expression.
1963 ///
1964 /// By default, builds a new default-argument expression, which does not
1965 /// require any semantic analysis. Subclasses may override this routine to
1966 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001967 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001968 ParmVarDecl *Param) {
1969 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1970 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001971 }
1972
1973 /// \brief Build a new C++ zero-initialization expression.
1974 ///
1975 /// By default, performs semantic analysis to build the new expression.
1976 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001977 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1978 SourceLocation LParenLoc,
1979 SourceLocation RParenLoc) {
1980 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Benjamin Kramer5354e772012-08-23 23:38:35 +00001981 MultiExprArg(), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001982 }
Mike Stump1eb44332009-09-09 15:08:12 +00001983
Douglas Gregorb98b1992009-08-11 05:31:07 +00001984 /// \brief Build a new C++ "new" expression.
1985 ///
1986 /// By default, performs semantic analysis to build the new expression.
1987 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001988 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001989 bool UseGlobal,
1990 SourceLocation PlacementLParen,
1991 MultiExprArg PlacementArgs,
1992 SourceLocation PlacementRParen,
1993 SourceRange TypeIdParens,
1994 QualType AllocatedType,
1995 TypeSourceInfo *AllocatedTypeInfo,
1996 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001997 SourceRange DirectInitRange,
1998 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00001999 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002000 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002001 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002002 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002003 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002004 AllocatedType,
2005 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002006 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002007 DirectInitRange,
2008 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002009 }
Mike Stump1eb44332009-09-09 15:08:12 +00002010
Douglas Gregorb98b1992009-08-11 05:31:07 +00002011 /// \brief Build a new C++ "delete" expression.
2012 ///
2013 /// By default, performs semantic analysis to build the new expression.
2014 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002015 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002016 bool IsGlobalDelete,
2017 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002018 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002019 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002020 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002021 }
Mike Stump1eb44332009-09-09 15:08:12 +00002022
Douglas Gregorb98b1992009-08-11 05:31:07 +00002023 /// \brief Build a new unary type trait expression.
2024 ///
2025 /// By default, performs semantic analysis to build the new expression.
2026 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002027 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002028 SourceLocation StartLoc,
2029 TypeSourceInfo *T,
2030 SourceLocation RParenLoc) {
2031 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002032 }
2033
Francois Pichet6ad6f282010-12-07 00:08:36 +00002034 /// \brief Build a new binary type trait expression.
2035 ///
2036 /// By default, performs semantic analysis to build the new expression.
2037 /// Subclasses may override this routine to provide different behavior.
2038 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2039 SourceLocation StartLoc,
2040 TypeSourceInfo *LhsT,
2041 TypeSourceInfo *RhsT,
2042 SourceLocation RParenLoc) {
2043 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2044 }
2045
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002046 /// \brief Build a new type trait expression.
2047 ///
2048 /// By default, performs semantic analysis to build the new expression.
2049 /// Subclasses may override this routine to provide different behavior.
2050 ExprResult RebuildTypeTrait(TypeTrait Trait,
2051 SourceLocation StartLoc,
2052 ArrayRef<TypeSourceInfo *> Args,
2053 SourceLocation RParenLoc) {
2054 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2055 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002056
John Wiegley21ff2e52011-04-28 00:16:57 +00002057 /// \brief Build a new array type trait expression.
2058 ///
2059 /// By default, performs semantic analysis to build the new expression.
2060 /// Subclasses may override this routine to provide different behavior.
2061 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2062 SourceLocation StartLoc,
2063 TypeSourceInfo *TSInfo,
2064 Expr *DimExpr,
2065 SourceLocation RParenLoc) {
2066 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2067 }
2068
John Wiegley55262202011-04-25 06:54:41 +00002069 /// \brief Build a new expression trait expression.
2070 ///
2071 /// By default, performs semantic analysis to build the new expression.
2072 /// Subclasses may override this routine to provide different behavior.
2073 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2074 SourceLocation StartLoc,
2075 Expr *Queried,
2076 SourceLocation RParenLoc) {
2077 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2078 }
2079
Mike Stump1eb44332009-09-09 15:08:12 +00002080 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002081 /// expression.
2082 ///
2083 /// By default, performs semantic analysis to build the new expression.
2084 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002085 ExprResult RebuildDependentScopeDeclRefExpr(
2086 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002087 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002088 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002089 const TemplateArgumentListInfo *TemplateArgs,
2090 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002091 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002092 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002093
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002094 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002095 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002096 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002097
Richard Smithefeeccf2012-10-21 03:28:35 +00002098 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2099 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002100 }
2101
2102 /// \brief Build a new template-id expression.
2103 ///
2104 /// By default, performs semantic analysis to build the new expression.
2105 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002106 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002107 SourceLocation TemplateKWLoc,
2108 LookupResult &R,
2109 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002110 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002111 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2112 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002113 }
2114
2115 /// \brief Build a new object-construction expression.
2116 ///
2117 /// By default, performs semantic analysis to build the new expression.
2118 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002119 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002120 SourceLocation Loc,
2121 CXXConstructorDecl *Constructor,
2122 bool IsElidable,
2123 MultiExprArg Args,
2124 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002125 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002126 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002127 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002128 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002129 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002130 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002131 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002132 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002133
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002134 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002135 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002136 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002137 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002138 RequiresZeroInit, ConstructKind,
2139 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002140 }
2141
2142 /// \brief Build a new object-construction expression.
2143 ///
2144 /// By default, performs semantic analysis to build the new expression.
2145 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002146 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2147 SourceLocation LParenLoc,
2148 MultiExprArg Args,
2149 SourceLocation RParenLoc) {
2150 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002151 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002152 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002153 RParenLoc);
2154 }
2155
2156 /// \brief Build a new object-construction expression.
2157 ///
2158 /// By default, performs semantic analysis to build the new expression.
2159 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002160 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2161 SourceLocation LParenLoc,
2162 MultiExprArg Args,
2163 SourceLocation RParenLoc) {
2164 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002165 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002166 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002167 RParenLoc);
2168 }
Mike Stump1eb44332009-09-09 15:08:12 +00002169
Douglas Gregorb98b1992009-08-11 05:31:07 +00002170 /// \brief Build a new member reference expression.
2171 ///
2172 /// By default, performs semantic analysis to build the new expression.
2173 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002174 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002175 QualType BaseType,
2176 bool IsArrow,
2177 SourceLocation OperatorLoc,
2178 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002179 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002180 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002181 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002182 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002183 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002184 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002185
John McCall9ae2f072010-08-23 23:25:46 +00002186 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002187 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002188 SS, TemplateKWLoc,
2189 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002190 MemberNameInfo,
2191 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002192 }
2193
John McCall129e2df2009-11-30 22:42:35 +00002194 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002195 ///
2196 /// By default, performs semantic analysis to build the new expression.
2197 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002198 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2199 SourceLocation OperatorLoc,
2200 bool IsArrow,
2201 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002202 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002203 NamedDecl *FirstQualifierInScope,
2204 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002205 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002206 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002207 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002208
John McCall9ae2f072010-08-23 23:25:46 +00002209 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002210 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002211 SS, TemplateKWLoc,
2212 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002213 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002214 }
Mike Stump1eb44332009-09-09 15:08:12 +00002215
Sebastian Redl2e156222010-09-10 20:55:43 +00002216 /// \brief Build a new noexcept expression.
2217 ///
2218 /// By default, performs semantic analysis to build the new expression.
2219 /// Subclasses may override this routine to provide different behavior.
2220 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2221 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2222 }
2223
Douglas Gregoree8aff02011-01-04 17:33:58 +00002224 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002225 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2226 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002227 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002228 llvm::Optional<unsigned> Length) {
2229 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002230 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2231 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002232 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002233
2234 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2235 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002236 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002237 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002238
Patrick Beardeb382ec2012-04-19 00:25:12 +00002239 /// \brief Build a new Objective-C boxed expression.
2240 ///
2241 /// By default, performs semantic analysis to build the new expression.
2242 /// Subclasses may override this routine to provide different behavior.
2243 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2244 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2245 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002246
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002247 /// \brief Build a new Objective-C array literal.
2248 ///
2249 /// By default, performs semantic analysis to build the new expression.
2250 /// Subclasses may override this routine to provide different behavior.
2251 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2252 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002253 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002254 MultiExprArg(Elements, NumElements));
2255 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002256
2257 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002258 Expr *Base, Expr *Key,
2259 ObjCMethodDecl *getterMethod,
2260 ObjCMethodDecl *setterMethod) {
2261 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2262 getterMethod, setterMethod);
2263 }
2264
2265 /// \brief Build a new Objective-C dictionary literal.
2266 ///
2267 /// By default, performs semantic analysis to build the new expression.
2268 /// Subclasses may override this routine to provide different behavior.
2269 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2270 ObjCDictionaryElement *Elements,
2271 unsigned NumElements) {
2272 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2273 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002274
James Dennett699c9042012-06-15 07:13:21 +00002275 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002276 ///
2277 /// By default, performs semantic analysis to build the new expression.
2278 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002279 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002280 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002281 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002282 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002283 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002284 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002285
Douglas Gregor92e986e2010-04-22 16:44:27 +00002286 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002287 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002288 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002289 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002290 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002291 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002292 MultiExprArg Args,
2293 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002294 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2295 ReceiverTypeInfo->getType(),
2296 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002297 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002298 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002299 }
2300
2301 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002302 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002303 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002304 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002305 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002306 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002307 MultiExprArg Args,
2308 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002309 return SemaRef.BuildInstanceMessage(Receiver,
2310 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002311 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002312 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002313 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002314 }
2315
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002316 /// \brief Build a new Objective-C ivar reference expression.
2317 ///
2318 /// By default, performs semantic analysis to build the new expression.
2319 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002320 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002321 SourceLocation IvarLoc,
2322 bool IsArrow, bool IsFreeIvar) {
2323 // FIXME: We lose track of the IsFreeIvar bit.
2324 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002325 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002326 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2327 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002328 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002329 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002330 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002331 false);
John Wiegley429bb272011-04-08 18:41:53 +00002332 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002333 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002334
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002335 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002336 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002337
John Wiegley429bb272011-04-08 18:41:53 +00002338 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002339 /*FIXME:*/IvarLoc, IsArrow,
2340 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002341 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002342 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002343 /*TemplateArgs=*/0);
2344 }
Douglas Gregore3303542010-04-26 20:47:02 +00002345
2346 /// \brief Build a new Objective-C property reference expression.
2347 ///
2348 /// By default, performs semantic analysis to build the new expression.
2349 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002350 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002351 ObjCPropertyDecl *Property,
2352 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002353 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002354 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002355 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2356 Sema::LookupMemberName);
2357 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002358 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002359 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002360 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002361 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002362 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002363
Douglas Gregore3303542010-04-26 20:47:02 +00002364 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002365 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002366
John Wiegley429bb272011-04-08 18:41:53 +00002367 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002368 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002369 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002370 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002371 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002372 /*TemplateArgs=*/0);
2373 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002374
John McCall12f78a62010-12-02 01:19:52 +00002375 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002376 ///
2377 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002378 /// Subclasses may override this routine to provide different behavior.
2379 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2380 ObjCMethodDecl *Getter,
2381 ObjCMethodDecl *Setter,
2382 SourceLocation PropertyLoc) {
2383 // Since these expressions can only be value-dependent, we do not
2384 // need to perform semantic analysis again.
2385 return Owned(
2386 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2387 VK_LValue, OK_ObjCProperty,
2388 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002389 }
2390
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002391 /// \brief Build a new Objective-C "isa" expression.
2392 ///
2393 /// By default, performs semantic analysis to build the new expression.
2394 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002395 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002396 bool IsArrow) {
2397 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002398 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002399 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2400 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002401 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002402 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002403 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002404 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002405 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002406
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002407 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002408 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002409
John Wiegley429bb272011-04-08 18:41:53 +00002410 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002411 /*FIXME:*/IsaLoc, IsArrow,
2412 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002413 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002414 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002415 /*TemplateArgs=*/0);
2416 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002417
Douglas Gregorb98b1992009-08-11 05:31:07 +00002418 /// \brief Build a new shuffle vector expression.
2419 ///
2420 /// By default, performs semantic analysis to build the new expression.
2421 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002422 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002423 MultiExprArg SubExprs,
2424 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002425 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002426 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002427 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2428 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2429 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002430 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002431
Douglas Gregorb98b1992009-08-11 05:31:07 +00002432 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002433 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002434 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2435 SemaRef.Context.BuiltinFnTy,
2436 VK_RValue, BuiltinLoc);
2437 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2438 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2439 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002440
2441 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002442 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002443 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002444 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002445 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002446 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002447
Douglas Gregorb98b1992009-08-11 05:31:07 +00002448 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002449 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002450 }
John McCall43fed0d2010-11-12 08:19:04 +00002451
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002452 /// \brief Build a new template argument pack expansion.
2453 ///
2454 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002455 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002456 /// different behavior.
2457 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002458 SourceLocation EllipsisLoc,
2459 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002460 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002461 case TemplateArgument::Expression: {
2462 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002463 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2464 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002465 if (Result.isInvalid())
2466 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002467
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002468 return TemplateArgumentLoc(Result.get(), Result.get());
2469 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002470
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002471 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002472 return TemplateArgumentLoc(TemplateArgument(
2473 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002474 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002475 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002476 Pattern.getTemplateNameLoc(),
2477 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002478
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002479 case TemplateArgument::Null:
2480 case TemplateArgument::Integral:
2481 case TemplateArgument::Declaration:
2482 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002483 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002484 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002485 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002486
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002487 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002488 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002489 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002490 EllipsisLoc,
2491 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002492 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2493 Expansion);
2494 break;
2495 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002496
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002497 return TemplateArgumentLoc();
2498 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002499
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002500 /// \brief Build a new expression pack expansion.
2501 ///
2502 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002503 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002504 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002505 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2506 llvm::Optional<unsigned> NumExpansions) {
2507 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002508 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002509
2510 /// \brief Build a new atomic operation expression.
2511 ///
2512 /// By default, performs semantic analysis to build the new expression.
2513 /// Subclasses may override this routine to provide different behavior.
2514 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2515 MultiExprArg SubExprs,
2516 QualType RetTy,
2517 AtomicExpr::AtomicOp Op,
2518 SourceLocation RParenLoc) {
2519 // Just create the expression; there is not any interesting semantic
2520 // analysis here because we can't actually build an AtomicExpr until
2521 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002522 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002523 RParenLoc);
2524 }
2525
John McCall43fed0d2010-11-12 08:19:04 +00002526private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002527 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2528 QualType ObjectType,
2529 NamedDecl *FirstQualifierInScope,
2530 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002531
2532 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2533 QualType ObjectType,
2534 NamedDecl *FirstQualifierInScope,
2535 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002536};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002537
Douglas Gregor43959a92009-08-20 07:17:43 +00002538template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002539StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002540 if (!S)
2541 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002542
Douglas Gregor43959a92009-08-20 07:17:43 +00002543 switch (S->getStmtClass()) {
2544 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002545
Douglas Gregor43959a92009-08-20 07:17:43 +00002546 // Transform individual statement nodes
2547#define STMT(Node, Parent) \
2548 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002549#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002550#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002551#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002552
Douglas Gregor43959a92009-08-20 07:17:43 +00002553 // Transform expressions by calling TransformExpr.
2554#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002555#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002556#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002557#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002558 {
John McCall60d7b3a2010-08-24 06:29:42 +00002559 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002560 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002561 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002562
John McCall9ae2f072010-08-23 23:25:46 +00002563 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002564 }
Mike Stump1eb44332009-09-09 15:08:12 +00002565 }
2566
John McCall3fa5cae2010-10-26 07:05:15 +00002567 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002568}
Mike Stump1eb44332009-09-09 15:08:12 +00002569
2570
Douglas Gregor670444e2009-08-04 22:27:00 +00002571template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002572ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002573 if (!E)
2574 return SemaRef.Owned(E);
2575
2576 switch (E->getStmtClass()) {
2577 case Stmt::NoStmtClass: break;
2578#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002579#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002580#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002581 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002582#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002583 }
2584
John McCall3fa5cae2010-10-26 07:05:15 +00002585 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002586}
2587
2588template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002589ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2590 bool CXXDirectInit) {
2591 // Initializers are instantiated like expressions, except that various outer
2592 // layers are stripped.
2593 if (!Init)
2594 return SemaRef.Owned(Init);
2595
2596 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2597 Init = ExprTemp->getSubExpr();
2598
2599 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2600 Init = Binder->getSubExpr();
2601
2602 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2603 Init = ICE->getSubExprAsWritten();
2604
2605 // If this is a direct-initializer, we take apart CXXConstructExprs.
2606 // Everything else is passed through.
2607 CXXConstructExpr *Construct;
2608 if (!(Construct = dyn_cast<CXXConstructExpr>(Init)) ||
2609 isa<CXXTemporaryObjectExpr>(Construct) ||
2610 (!CXXDirectInit && !Construct->isListInitialization()))
2611 return getDerived().TransformExpr(Init);
2612
2613 SmallVector<Expr*, 8> NewArgs;
2614 bool ArgChanged = false;
2615 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2616 /*IsCall*/true, NewArgs, &ArgChanged))
2617 return ExprError();
2618
2619 // If this was list initialization, revert to list form.
2620 if (Construct->isListInitialization())
2621 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2622 Construct->getLocEnd(),
2623 Construct->getType());
2624
Richard Smithc83c2302012-12-19 01:39:02 +00002625 // Build a ParenListExpr to represent anything else.
2626 SourceRange Parens = Construct->getParenRange();
2627 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2628 Parens.getEnd());
2629}
2630
2631template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002632bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2633 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002634 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002635 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002636 bool *ArgChanged) {
2637 for (unsigned I = 0; I != NumInputs; ++I) {
2638 // If requested, drop call arguments that need to be dropped.
2639 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2640 if (ArgChanged)
2641 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002642
Douglas Gregoraa165f82011-01-03 19:04:46 +00002643 break;
2644 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002645
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002646 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2647 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002648
Chris Lattner686775d2011-07-20 06:58:45 +00002649 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002650 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2651 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002652
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002653 // Determine whether the set of unexpanded parameter packs can and should
2654 // be expanded.
2655 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002656 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002657 llvm::Optional<unsigned> OrigNumExpansions
2658 = Expansion->getNumExpansions();
2659 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002660 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2661 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002662 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002663 Expand, RetainExpansion,
2664 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002665 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002666
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002667 if (!Expand) {
2668 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002669 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002670 // expansion.
2671 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2672 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2673 if (OutPattern.isInvalid())
2674 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002675
2676 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002677 Expansion->getEllipsisLoc(),
2678 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002679 if (Out.isInvalid())
2680 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002681
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002682 if (ArgChanged)
2683 *ArgChanged = true;
2684 Outputs.push_back(Out.get());
2685 continue;
2686 }
John McCallc8fc90a2011-07-06 07:30:07 +00002687
2688 // Record right away that the argument was changed. This needs
2689 // to happen even if the array expands to nothing.
2690 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002691
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002692 // The transform has determined that we should perform an elementwise
2693 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002694 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002695 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2696 ExprResult Out = getDerived().TransformExpr(Pattern);
2697 if (Out.isInvalid())
2698 return true;
2699
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002700 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002701 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2702 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002703 if (Out.isInvalid())
2704 return true;
2705 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002706
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002707 Outputs.push_back(Out.get());
2708 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002709
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002710 continue;
2711 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002712
Richard Smithc83c2302012-12-19 01:39:02 +00002713 ExprResult Result =
2714 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2715 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002716 if (Result.isInvalid())
2717 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002718
Douglas Gregoraa165f82011-01-03 19:04:46 +00002719 if (Result.get() != Inputs[I] && ArgChanged)
2720 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002721
2722 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002723 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002724
Douglas Gregoraa165f82011-01-03 19:04:46 +00002725 return false;
2726}
2727
2728template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002729NestedNameSpecifierLoc
2730TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2731 NestedNameSpecifierLoc NNS,
2732 QualType ObjectType,
2733 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002734 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002735 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002736 Qualifier = Qualifier.getPrefix())
2737 Qualifiers.push_back(Qualifier);
2738
2739 CXXScopeSpec SS;
2740 while (!Qualifiers.empty()) {
2741 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2742 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002743
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002744 switch (QNNS->getKind()) {
2745 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002746 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002747 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002748 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002749 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002750 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002751 FirstQualifierInScope, false))
2752 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002753
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002754 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002755
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002756 case NestedNameSpecifier::Namespace: {
2757 NamespaceDecl *NS
2758 = cast_or_null<NamespaceDecl>(
2759 getDerived().TransformDecl(
2760 Q.getLocalBeginLoc(),
2761 QNNS->getAsNamespace()));
2762 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2763 break;
2764 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002765
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002766 case NestedNameSpecifier::NamespaceAlias: {
2767 NamespaceAliasDecl *Alias
2768 = cast_or_null<NamespaceAliasDecl>(
2769 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2770 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002771 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002772 Q.getLocalEndLoc());
2773 break;
2774 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002775
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002776 case NestedNameSpecifier::Global:
2777 // There is no meaningful transformation that one could perform on the
2778 // global scope.
2779 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2780 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002781
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002782 case NestedNameSpecifier::TypeSpecWithTemplate:
2783 case NestedNameSpecifier::TypeSpec: {
2784 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2785 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002786
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002787 if (!TL)
2788 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002789
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002790 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00002791 (SemaRef.getLangOpts().CPlusPlus0x &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002792 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002793 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002794 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002795 if (TL.getType()->isEnumeralType())
2796 SemaRef.Diag(TL.getBeginLoc(),
2797 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002798 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2799 Q.getLocalEndLoc());
2800 break;
2801 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002802 // If the nested-name-specifier is an invalid type def, don't emit an
2803 // error because a previous error should have already been emitted.
2804 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2805 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002806 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002807 << TL.getType() << SS.getRange();
2808 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002809 return NestedNameSpecifierLoc();
2810 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002811 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002812
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002813 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002814 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002815 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002816 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002817
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002818 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002819 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002820 !getDerived().AlwaysRebuild())
2821 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002822
2823 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002824 // nested-name-specifier, do so.
2825 if (SS.location_size() == NNS.getDataLength() &&
2826 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2827 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2828
2829 // Allocate new nested-name-specifier location information.
2830 return SS.getWithLocInContext(SemaRef.Context);
2831}
2832
2833template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002834DeclarationNameInfo
2835TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002836::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002837 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002838 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002839 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002840
2841 switch (Name.getNameKind()) {
2842 case DeclarationName::Identifier:
2843 case DeclarationName::ObjCZeroArgSelector:
2844 case DeclarationName::ObjCOneArgSelector:
2845 case DeclarationName::ObjCMultiArgSelector:
2846 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002847 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002848 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002849 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002850
Douglas Gregor81499bb2009-09-03 22:13:48 +00002851 case DeclarationName::CXXConstructorName:
2852 case DeclarationName::CXXDestructorName:
2853 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002854 TypeSourceInfo *NewTInfo;
2855 CanQualType NewCanTy;
2856 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002857 NewTInfo = getDerived().TransformType(OldTInfo);
2858 if (!NewTInfo)
2859 return DeclarationNameInfo();
2860 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002861 }
2862 else {
2863 NewTInfo = 0;
2864 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002865 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002866 if (NewT.isNull())
2867 return DeclarationNameInfo();
2868 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2869 }
Mike Stump1eb44332009-09-09 15:08:12 +00002870
Abramo Bagnara25777432010-08-11 22:01:17 +00002871 DeclarationName NewName
2872 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2873 NewCanTy);
2874 DeclarationNameInfo NewNameInfo(NameInfo);
2875 NewNameInfo.setName(NewName);
2876 NewNameInfo.setNamedTypeInfo(NewTInfo);
2877 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002878 }
Mike Stump1eb44332009-09-09 15:08:12 +00002879 }
2880
David Blaikieb219cfc2011-09-23 05:06:16 +00002881 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002882}
2883
2884template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002885TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002886TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2887 TemplateName Name,
2888 SourceLocation NameLoc,
2889 QualType ObjectType,
2890 NamedDecl *FirstQualifierInScope) {
2891 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2892 TemplateDecl *Template = QTN->getTemplateDecl();
2893 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002894
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002895 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002896 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002897 Template));
2898 if (!TransTemplate)
2899 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002900
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002901 if (!getDerived().AlwaysRebuild() &&
2902 SS.getScopeRep() == QTN->getQualifier() &&
2903 TransTemplate == Template)
2904 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002905
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002906 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2907 TransTemplate);
2908 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002909
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002910 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2911 if (SS.getScopeRep()) {
2912 // These apply to the scope specifier, not the template.
2913 ObjectType = QualType();
2914 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002915 }
2916
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002917 if (!getDerived().AlwaysRebuild() &&
2918 SS.getScopeRep() == DTN->getQualifier() &&
2919 ObjectType.isNull())
2920 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002921
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002922 if (DTN->isIdentifier()) {
2923 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002924 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002925 NameLoc,
2926 ObjectType,
2927 FirstQualifierInScope);
2928 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002929
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002930 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2931 ObjectType);
2932 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002933
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002934 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2935 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 TransTemplate == Template)
2943 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002944
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002945 return TemplateName(TransTemplate);
2946 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002947
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002948 if (SubstTemplateTemplateParmPackStorage *SubstPack
2949 = Name.getAsSubstTemplateTemplateParmPack()) {
2950 TemplateTemplateParmDecl *TransParam
2951 = cast_or_null<TemplateTemplateParmDecl>(
2952 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2953 if (!TransParam)
2954 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002955
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002956 if (!getDerived().AlwaysRebuild() &&
2957 TransParam == SubstPack->getParameterPack())
2958 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002959
2960 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002961 SubstPack->getArgumentPack());
2962 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002963
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002964 // These should be getting filtered out before they reach the AST.
2965 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002966}
2967
2968template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002969void TreeTransform<Derived>::InventTemplateArgumentLoc(
2970 const TemplateArgument &Arg,
2971 TemplateArgumentLoc &Output) {
2972 SourceLocation Loc = getDerived().getBaseLocation();
2973 switch (Arg.getKind()) {
2974 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002975 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002976 break;
2977
2978 case TemplateArgument::Type:
2979 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002980 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002981
John McCall833ca992009-10-29 08:12:44 +00002982 break;
2983
Douglas Gregor788cd062009-11-11 01:00:40 +00002984 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002985 case TemplateArgument::TemplateExpansion: {
2986 NestedNameSpecifierLocBuilder Builder;
2987 TemplateName Template = Arg.getAsTemplate();
2988 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2989 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2990 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2991 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002992
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002993 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002994 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002995 Builder.getWithLocInContext(SemaRef.Context),
2996 Loc);
2997 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00002998 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002999 Builder.getWithLocInContext(SemaRef.Context),
3000 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003001
Douglas Gregor788cd062009-11-11 01:00:40 +00003002 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003003 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003004
John McCall833ca992009-10-29 08:12:44 +00003005 case TemplateArgument::Expression:
3006 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3007 break;
3008
3009 case TemplateArgument::Declaration:
3010 case TemplateArgument::Integral:
3011 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003012 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003013 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003014 break;
3015 }
3016}
3017
3018template<typename Derived>
3019bool TreeTransform<Derived>::TransformTemplateArgument(
3020 const TemplateArgumentLoc &Input,
3021 TemplateArgumentLoc &Output) {
3022 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003023 switch (Arg.getKind()) {
3024 case TemplateArgument::Null:
3025 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003026 case TemplateArgument::Pack:
3027 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003028 case TemplateArgument::NullPtr:
3029 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003030
Douglas Gregor670444e2009-08-04 22:27:00 +00003031 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003032 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003033 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003034 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003035
3036 DI = getDerived().TransformType(DI);
3037 if (!DI) return true;
3038
3039 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3040 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003041 }
Mike Stump1eb44332009-09-09 15:08:12 +00003042
Douglas Gregor788cd062009-11-11 01:00:40 +00003043 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003044 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3045 if (QualifierLoc) {
3046 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3047 if (!QualifierLoc)
3048 return true;
3049 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003050
Douglas Gregor1d752d72011-03-02 18:46:51 +00003051 CXXScopeSpec SS;
3052 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003053 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003054 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3055 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003056 if (Template.isNull())
3057 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003058
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003059 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003060 Input.getTemplateNameLoc());
3061 return false;
3062 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003063
3064 case TemplateArgument::TemplateExpansion:
3065 llvm_unreachable("Caller should expand pack expansions");
3066
Douglas Gregor670444e2009-08-04 22:27:00 +00003067 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003068 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003069 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003070 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003071
John McCall833ca992009-10-29 08:12:44 +00003072 Expr *InputExpr = Input.getSourceExpression();
3073 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3074
Chris Lattner223de242011-04-25 20:37:58 +00003075 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003076 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003077 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003078 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003079 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003080 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003081 }
Mike Stump1eb44332009-09-09 15:08:12 +00003082
Douglas Gregor670444e2009-08-04 22:27:00 +00003083 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003084 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003085}
3086
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003087/// \brief Iterator adaptor that invents template argument location information
3088/// for each of the template arguments in its underlying iterator.
3089template<typename Derived, typename InputIterator>
3090class TemplateArgumentLocInventIterator {
3091 TreeTransform<Derived> &Self;
3092 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003093
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003094public:
3095 typedef TemplateArgumentLoc value_type;
3096 typedef TemplateArgumentLoc reference;
3097 typedef typename std::iterator_traits<InputIterator>::difference_type
3098 difference_type;
3099 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003100
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003101 class pointer {
3102 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003103
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003104 public:
3105 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003106
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003107 const TemplateArgumentLoc *operator->() const { return &Arg; }
3108 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003109
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003110 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003111
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003112 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3113 InputIterator Iter)
3114 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003115
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003116 TemplateArgumentLocInventIterator &operator++() {
3117 ++Iter;
3118 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003119 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003120
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003121 TemplateArgumentLocInventIterator operator++(int) {
3122 TemplateArgumentLocInventIterator Old(*this);
3123 ++(*this);
3124 return Old;
3125 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003126
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003127 reference operator*() const {
3128 TemplateArgumentLoc Result;
3129 Self.InventTemplateArgumentLoc(*Iter, Result);
3130 return Result;
3131 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003132
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003133 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003134
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003135 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3136 const TemplateArgumentLocInventIterator &Y) {
3137 return X.Iter == Y.Iter;
3138 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003139
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003140 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3141 const TemplateArgumentLocInventIterator &Y) {
3142 return X.Iter != Y.Iter;
3143 }
3144};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003145
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003146template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003147template<typename InputIterator>
3148bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3149 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003150 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003151 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003152 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003153 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003154
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003155 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3156 // Unpack argument packs, which we translate them into separate
3157 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003158 // FIXME: We could do much better if we could guarantee that the
3159 // TemplateArgumentLocInfo for the pack expansion would be usable for
3160 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003161 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003162 TemplateArgument::pack_iterator>
3163 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003164 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003165 In.getArgument().pack_begin()),
3166 PackLocIterator(*this,
3167 In.getArgument().pack_end()),
3168 Outputs))
3169 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003170
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003171 continue;
3172 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003173
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003174 if (In.getArgument().isPackExpansion()) {
3175 // We have a pack expansion, for which we will be substituting into
3176 // the pattern.
3177 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003178 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003179 TemplateArgumentLoc Pattern
Chad Rosier4a9d7952012-08-08 18:46:20 +00003180 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
Douglas Gregorcded4f62011-01-14 17:04:44 +00003181 getSema().Context);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003182
Chris Lattner686775d2011-07-20 06:58:45 +00003183 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003184 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3185 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003186
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003187 // Determine whether the set of unexpanded parameter packs can and should
3188 // be expanded.
3189 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003190 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003191 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003192 if (getDerived().TryExpandParameterPacks(Ellipsis,
3193 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003194 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003195 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003196 RetainExpansion,
3197 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003198 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003199
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003200 if (!Expand) {
3201 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003202 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003203 // expansion.
3204 TemplateArgumentLoc OutPattern;
3205 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3206 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3207 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003208
Douglas Gregorcded4f62011-01-14 17:04:44 +00003209 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3210 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003211 if (Out.getArgument().isNull())
3212 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003213
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003214 Outputs.addArgument(Out);
3215 continue;
3216 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003217
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003218 // The transform has determined that we should perform an elementwise
3219 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003220 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003221 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3222
3223 if (getDerived().TransformTemplateArgument(Pattern, Out))
3224 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003225
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003226 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003227 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3228 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003229 if (Out.getArgument().isNull())
3230 return true;
3231 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003232
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003233 Outputs.addArgument(Out);
3234 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003235
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003236 // If we're supposed to retain a pack expansion, do so by temporarily
3237 // forgetting the partially-substituted parameter pack.
3238 if (RetainExpansion) {
3239 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003240
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003241 if (getDerived().TransformTemplateArgument(Pattern, Out))
3242 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003243
Douglas Gregorcded4f62011-01-14 17:04:44 +00003244 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3245 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003246 if (Out.getArgument().isNull())
3247 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003248
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003249 Outputs.addArgument(Out);
3250 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003251
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003252 continue;
3253 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003254
3255 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003256 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003257 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003258
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003259 Outputs.addArgument(Out);
3260 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003261
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003262 return false;
3263
3264}
3265
Douglas Gregor577f75a2009-08-04 16:50:30 +00003266//===----------------------------------------------------------------------===//
3267// Type transformation
3268//===----------------------------------------------------------------------===//
3269
3270template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003271QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003272 if (getDerived().AlreadyTransformed(T))
3273 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003274
John McCalla2becad2009-10-21 00:40:46 +00003275 // Temporary workaround. All of these transformations should
3276 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003277 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3278 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003279
John McCall43fed0d2010-11-12 08:19:04 +00003280 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003281
John McCalla2becad2009-10-21 00:40:46 +00003282 if (!NewDI)
3283 return QualType();
3284
3285 return NewDI->getType();
3286}
3287
3288template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003289TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003290 // Refine the base location to the type's location.
3291 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3292 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003293 if (getDerived().AlreadyTransformed(DI->getType()))
3294 return DI;
3295
3296 TypeLocBuilder TLB;
3297
3298 TypeLoc TL = DI->getTypeLoc();
3299 TLB.reserve(TL.getFullDataSize());
3300
John McCall43fed0d2010-11-12 08:19:04 +00003301 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003302 if (Result.isNull())
3303 return 0;
3304
John McCalla93c9342009-12-07 02:54:59 +00003305 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003306}
3307
3308template<typename Derived>
3309QualType
John McCall43fed0d2010-11-12 08:19:04 +00003310TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003311 switch (T.getTypeLocClass()) {
3312#define ABSTRACT_TYPELOC(CLASS, PARENT)
3313#define TYPELOC(CLASS, PARENT) \
3314 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003315 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003316#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003317 }
Mike Stump1eb44332009-09-09 15:08:12 +00003318
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003319 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003320}
3321
3322/// FIXME: By default, this routine adds type qualifiers only to types
3323/// that can have qualifiers, and silently suppresses those qualifiers
3324/// that are not permitted (e.g., qualifiers on reference or function
3325/// types). This is the right thing for template instantiation, but
3326/// probably not for other clients.
3327template<typename Derived>
3328QualType
3329TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003330 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003331 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003332
John McCall43fed0d2010-11-12 08:19:04 +00003333 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003334 if (Result.isNull())
3335 return QualType();
3336
3337 // Silently suppress qualifiers if the result type can't be qualified.
3338 // FIXME: this is the right thing for template instantiation, but
3339 // probably not for other clients.
3340 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003341 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003342
John McCallf85e1932011-06-15 23:02:42 +00003343 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003344 // resulting type.
3345 if (Quals.hasObjCLifetime()) {
3346 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3347 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003348 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003349 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003350 // A lifetime qualifier applied to a substituted template parameter
3351 // overrides the lifetime qualifier from the template argument.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003352 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003353 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3354 QualType Replacement = SubstTypeParam->getReplacementType();
3355 Qualifiers Qs = Replacement.getQualifiers();
3356 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003357 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003358 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3359 Qs);
3360 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003361 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003362 Replacement);
3363 TLB.TypeWasModifiedSafely(Result);
3364 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003365 // Otherwise, complain about the addition of a qualifier to an
3366 // already-qualified type.
3367 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003368 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003369 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003370
Douglas Gregore559ca12011-06-17 22:11:49 +00003371 Quals.removeObjCLifetime();
3372 }
3373 }
3374 }
John McCall28654742010-06-05 06:41:15 +00003375 if (!Quals.empty()) {
3376 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3377 TLB.push<QualifiedTypeLoc>(Result);
3378 // No location information to preserve.
3379 }
John McCalla2becad2009-10-21 00:40:46 +00003380
3381 return Result;
3382}
3383
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003384template<typename Derived>
3385TypeLoc
3386TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3387 QualType ObjectType,
3388 NamedDecl *UnqualLookup,
3389 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003390 QualType T = TL.getType();
3391 if (getDerived().AlreadyTransformed(T))
3392 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003393
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003394 TypeLocBuilder TLB;
3395 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003396
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003397 if (isa<TemplateSpecializationType>(T)) {
3398 TemplateSpecializationTypeLoc SpecTL
3399 = cast<TemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003400
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003401 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003402 getDerived().TransformTemplateName(SS,
3403 SpecTL.getTypePtr()->getTemplateName(),
3404 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003405 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003406 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003407 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003408
3409 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003410 Template);
3411 } else if (isa<DependentTemplateSpecializationType>(T)) {
3412 DependentTemplateSpecializationTypeLoc SpecTL
3413 = cast<DependentTemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003414
Douglas Gregora88f09f2011-02-28 17:23:35 +00003415 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003416 = getDerived().RebuildTemplateName(SS,
3417 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003418 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003419 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003420 if (Template.isNull())
3421 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003422
3423 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003424 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003425 Template,
3426 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003427 } else {
3428 // Nothing special needs to be done for these.
3429 Result = getDerived().TransformType(TLB, TL);
3430 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003431
3432 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003433 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003434
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003435 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3436}
3437
Douglas Gregorb71d8212011-03-02 18:32:08 +00003438template<typename Derived>
3439TypeSourceInfo *
3440TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3441 QualType ObjectType,
3442 NamedDecl *UnqualLookup,
3443 CXXScopeSpec &SS) {
3444 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003445
Douglas Gregorb71d8212011-03-02 18:32:08 +00003446 QualType T = TSInfo->getType();
3447 if (getDerived().AlreadyTransformed(T))
3448 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003449
Douglas Gregorb71d8212011-03-02 18:32:08 +00003450 TypeLocBuilder TLB;
3451 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003452
Douglas Gregorb71d8212011-03-02 18:32:08 +00003453 TypeLoc TL = TSInfo->getTypeLoc();
3454 if (isa<TemplateSpecializationType>(T)) {
3455 TemplateSpecializationTypeLoc SpecTL
3456 = cast<TemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003457
Douglas Gregorb71d8212011-03-02 18:32:08 +00003458 TemplateName Template
3459 = getDerived().TransformTemplateName(SS,
3460 SpecTL.getTypePtr()->getTemplateName(),
3461 SpecTL.getTemplateNameLoc(),
3462 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003463 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003464 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003465
3466 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003467 Template);
3468 } else if (isa<DependentTemplateSpecializationType>(T)) {
3469 DependentTemplateSpecializationTypeLoc SpecTL
3470 = cast<DependentTemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003471
Douglas Gregorb71d8212011-03-02 18:32:08 +00003472 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003473 = getDerived().RebuildTemplateName(SS,
3474 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003475 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003476 ObjectType, UnqualLookup);
3477 if (Template.isNull())
3478 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003479
3480 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003481 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003482 Template,
3483 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003484 } else {
3485 // Nothing special needs to be done for these.
3486 Result = getDerived().TransformType(TLB, TL);
3487 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003488
3489 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003490 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003491
Douglas Gregorb71d8212011-03-02 18:32:08 +00003492 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3493}
3494
John McCalla2becad2009-10-21 00:40:46 +00003495template <class TyLoc> static inline
3496QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3497 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3498 NewT.setNameLoc(T.getNameLoc());
3499 return T.getType();
3500}
3501
John McCalla2becad2009-10-21 00:40:46 +00003502template<typename Derived>
3503QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003504 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003505 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3506 NewT.setBuiltinLoc(T.getBuiltinLoc());
3507 if (T.needsExtraLocalData())
3508 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3509 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003510}
Mike Stump1eb44332009-09-09 15:08:12 +00003511
Douglas Gregor577f75a2009-08-04 16:50:30 +00003512template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003513QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003514 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003515 // FIXME: recurse?
3516 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003517}
Mike Stump1eb44332009-09-09 15:08:12 +00003518
Douglas Gregor577f75a2009-08-04 16:50:30 +00003519template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003520QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003521 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003522 QualType PointeeType
3523 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003524 if (PointeeType.isNull())
3525 return QualType();
3526
3527 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003528 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003529 // A dependent pointer type 'T *' has is being transformed such
3530 // that an Objective-C class type is being replaced for 'T'. The
3531 // resulting pointer type is an ObjCObjectPointerType, not a
3532 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003533 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003534
John McCallc12c5bb2010-05-15 11:32:37 +00003535 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3536 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003537 return Result;
3538 }
John McCall43fed0d2010-11-12 08:19:04 +00003539
Douglas Gregor92e986e2010-04-22 16:44:27 +00003540 if (getDerived().AlwaysRebuild() ||
3541 PointeeType != TL.getPointeeLoc().getType()) {
3542 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3543 if (Result.isNull())
3544 return QualType();
3545 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003546
John McCallf85e1932011-06-15 23:02:42 +00003547 // Objective-C ARC can add lifetime qualifiers to the type that we're
3548 // pointing to.
3549 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003550
Douglas Gregor92e986e2010-04-22 16:44:27 +00003551 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3552 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003553 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003554}
Mike Stump1eb44332009-09-09 15:08:12 +00003555
3556template<typename Derived>
3557QualType
John McCalla2becad2009-10-21 00:40:46 +00003558TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003559 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003560 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003561 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3562 if (PointeeType.isNull())
3563 return QualType();
3564
3565 QualType Result = TL.getType();
3566 if (getDerived().AlwaysRebuild() ||
3567 PointeeType != TL.getPointeeLoc().getType()) {
3568 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003569 TL.getSigilLoc());
3570 if (Result.isNull())
3571 return QualType();
3572 }
3573
Douglas Gregor39968ad2010-04-22 16:50:51 +00003574 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003575 NewT.setSigilLoc(TL.getSigilLoc());
3576 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003577}
3578
John McCall85737a72009-10-30 00:06:24 +00003579/// Transforms a reference type. Note that somewhat paradoxically we
3580/// don't care whether the type itself is an l-value type or an r-value
3581/// type; we only care if the type was *written* as an l-value type
3582/// or an r-value type.
3583template<typename Derived>
3584QualType
3585TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003586 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003587 const ReferenceType *T = TL.getTypePtr();
3588
3589 // Note that this works with the pointee-as-written.
3590 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3591 if (PointeeType.isNull())
3592 return QualType();
3593
3594 QualType Result = TL.getType();
3595 if (getDerived().AlwaysRebuild() ||
3596 PointeeType != T->getPointeeTypeAsWritten()) {
3597 Result = getDerived().RebuildReferenceType(PointeeType,
3598 T->isSpelledAsLValue(),
3599 TL.getSigilLoc());
3600 if (Result.isNull())
3601 return QualType();
3602 }
3603
John McCallf85e1932011-06-15 23:02:42 +00003604 // Objective-C ARC can add lifetime qualifiers to the type that we're
3605 // referring to.
3606 TLB.TypeWasModifiedSafely(
3607 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3608
John McCall85737a72009-10-30 00:06:24 +00003609 // r-value references can be rebuilt as l-value references.
3610 ReferenceTypeLoc NewTL;
3611 if (isa<LValueReferenceType>(Result))
3612 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3613 else
3614 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3615 NewTL.setSigilLoc(TL.getSigilLoc());
3616
3617 return Result;
3618}
3619
Mike Stump1eb44332009-09-09 15:08:12 +00003620template<typename Derived>
3621QualType
John McCalla2becad2009-10-21 00:40:46 +00003622TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003623 LValueReferenceTypeLoc TL) {
3624 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003625}
3626
Mike Stump1eb44332009-09-09 15:08:12 +00003627template<typename Derived>
3628QualType
John McCalla2becad2009-10-21 00:40:46 +00003629TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003630 RValueReferenceTypeLoc TL) {
3631 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003632}
Mike Stump1eb44332009-09-09 15:08:12 +00003633
Douglas Gregor577f75a2009-08-04 16:50:30 +00003634template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003635QualType
John McCalla2becad2009-10-21 00:40:46 +00003636TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003637 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003638 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003639 if (PointeeType.isNull())
3640 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003641
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003642 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3643 TypeSourceInfo* NewClsTInfo = 0;
3644 if (OldClsTInfo) {
3645 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3646 if (!NewClsTInfo)
3647 return QualType();
3648 }
3649
3650 const MemberPointerType *T = TL.getTypePtr();
3651 QualType OldClsType = QualType(T->getClass(), 0);
3652 QualType NewClsType;
3653 if (NewClsTInfo)
3654 NewClsType = NewClsTInfo->getType();
3655 else {
3656 NewClsType = getDerived().TransformType(OldClsType);
3657 if (NewClsType.isNull())
3658 return QualType();
3659 }
Mike Stump1eb44332009-09-09 15:08:12 +00003660
John McCalla2becad2009-10-21 00:40:46 +00003661 QualType Result = TL.getType();
3662 if (getDerived().AlwaysRebuild() ||
3663 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003664 NewClsType != OldClsType) {
3665 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003666 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003667 if (Result.isNull())
3668 return QualType();
3669 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003670
John McCalla2becad2009-10-21 00:40:46 +00003671 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3672 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003673 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003674
3675 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003676}
3677
Mike Stump1eb44332009-09-09 15:08:12 +00003678template<typename Derived>
3679QualType
John McCalla2becad2009-10-21 00:40:46 +00003680TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003681 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003682 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003683 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003684 if (ElementType.isNull())
3685 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003686
John McCalla2becad2009-10-21 00:40:46 +00003687 QualType Result = TL.getType();
3688 if (getDerived().AlwaysRebuild() ||
3689 ElementType != T->getElementType()) {
3690 Result = getDerived().RebuildConstantArrayType(ElementType,
3691 T->getSizeModifier(),
3692 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003693 T->getIndexTypeCVRQualifiers(),
3694 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003695 if (Result.isNull())
3696 return QualType();
3697 }
Eli Friedman457a3772012-01-25 22:19:07 +00003698
3699 // We might have either a ConstantArrayType or a VariableArrayType now:
3700 // a ConstantArrayType is allowed to have an element type which is a
3701 // VariableArrayType if the type is dependent. Fortunately, all array
3702 // types have the same location layout.
3703 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003704 NewTL.setLBracketLoc(TL.getLBracketLoc());
3705 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003706
John McCalla2becad2009-10-21 00:40:46 +00003707 Expr *Size = TL.getSizeExpr();
3708 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003709 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3710 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003711 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003712 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003713 }
3714 NewTL.setSizeExpr(Size);
3715
3716 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003717}
Mike Stump1eb44332009-09-09 15:08:12 +00003718
Douglas Gregor577f75a2009-08-04 16:50:30 +00003719template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003720QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003721 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003722 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003723 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003724 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003725 if (ElementType.isNull())
3726 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003727
John McCalla2becad2009-10-21 00:40:46 +00003728 QualType Result = TL.getType();
3729 if (getDerived().AlwaysRebuild() ||
3730 ElementType != T->getElementType()) {
3731 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003732 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003733 T->getIndexTypeCVRQualifiers(),
3734 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003735 if (Result.isNull())
3736 return QualType();
3737 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003738
John McCalla2becad2009-10-21 00:40:46 +00003739 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3740 NewTL.setLBracketLoc(TL.getLBracketLoc());
3741 NewTL.setRBracketLoc(TL.getRBracketLoc());
3742 NewTL.setSizeExpr(0);
3743
3744 return Result;
3745}
3746
3747template<typename Derived>
3748QualType
3749TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003750 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003751 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003752 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3753 if (ElementType.isNull())
3754 return QualType();
3755
John McCall60d7b3a2010-08-24 06:29:42 +00003756 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003757 = getDerived().TransformExpr(T->getSizeExpr());
3758 if (SizeResult.isInvalid())
3759 return QualType();
3760
John McCall9ae2f072010-08-23 23:25:46 +00003761 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003762
3763 QualType Result = TL.getType();
3764 if (getDerived().AlwaysRebuild() ||
3765 ElementType != T->getElementType() ||
3766 Size != T->getSizeExpr()) {
3767 Result = getDerived().RebuildVariableArrayType(ElementType,
3768 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003769 Size,
John McCalla2becad2009-10-21 00:40:46 +00003770 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003771 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003772 if (Result.isNull())
3773 return QualType();
3774 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003775
John McCalla2becad2009-10-21 00:40:46 +00003776 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3777 NewTL.setLBracketLoc(TL.getLBracketLoc());
3778 NewTL.setRBracketLoc(TL.getRBracketLoc());
3779 NewTL.setSizeExpr(Size);
3780
3781 return Result;
3782}
3783
3784template<typename Derived>
3785QualType
3786TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003787 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003788 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003789 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3790 if (ElementType.isNull())
3791 return QualType();
3792
Richard Smithf6702a32011-12-20 02:08:33 +00003793 // Array bounds are constant expressions.
3794 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3795 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003796
John McCall3b657512011-01-19 10:06:00 +00003797 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3798 Expr *origSize = TL.getSizeExpr();
3799 if (!origSize) origSize = T->getSizeExpr();
3800
3801 ExprResult sizeResult
3802 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003803 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003804 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003805 return QualType();
3806
John McCall3b657512011-01-19 10:06:00 +00003807 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003808
3809 QualType Result = TL.getType();
3810 if (getDerived().AlwaysRebuild() ||
3811 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003812 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003813 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3814 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003815 size,
John McCalla2becad2009-10-21 00:40:46 +00003816 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003817 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003818 if (Result.isNull())
3819 return QualType();
3820 }
John McCalla2becad2009-10-21 00:40:46 +00003821
3822 // We might have any sort of array type now, but fortunately they
3823 // all have the same location layout.
3824 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3825 NewTL.setLBracketLoc(TL.getLBracketLoc());
3826 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003827 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003828
3829 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003830}
Mike Stump1eb44332009-09-09 15:08:12 +00003831
3832template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003833QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003834 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003835 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003836 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003837
3838 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003839 QualType ElementType = getDerived().TransformType(T->getElementType());
3840 if (ElementType.isNull())
3841 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003842
Richard Smithf6702a32011-12-20 02:08:33 +00003843 // Vector sizes are constant expressions.
3844 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3845 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003846
John McCall60d7b3a2010-08-24 06:29:42 +00003847 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003848 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003849 if (Size.isInvalid())
3850 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003851
John McCalla2becad2009-10-21 00:40:46 +00003852 QualType Result = TL.getType();
3853 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003854 ElementType != T->getElementType() ||
3855 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003856 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003857 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003858 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003859 if (Result.isNull())
3860 return QualType();
3861 }
John McCalla2becad2009-10-21 00:40:46 +00003862
3863 // Result might be dependent or not.
3864 if (isa<DependentSizedExtVectorType>(Result)) {
3865 DependentSizedExtVectorTypeLoc NewTL
3866 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3867 NewTL.setNameLoc(TL.getNameLoc());
3868 } else {
3869 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3870 NewTL.setNameLoc(TL.getNameLoc());
3871 }
3872
3873 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003874}
Mike Stump1eb44332009-09-09 15:08:12 +00003875
3876template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003877QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003878 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003879 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003880 QualType ElementType = getDerived().TransformType(T->getElementType());
3881 if (ElementType.isNull())
3882 return QualType();
3883
John McCalla2becad2009-10-21 00:40:46 +00003884 QualType Result = TL.getType();
3885 if (getDerived().AlwaysRebuild() ||
3886 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003887 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003888 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003889 if (Result.isNull())
3890 return QualType();
3891 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003892
John McCalla2becad2009-10-21 00:40:46 +00003893 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3894 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003895
John McCalla2becad2009-10-21 00:40:46 +00003896 return Result;
3897}
3898
3899template<typename Derived>
3900QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003901 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003902 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003903 QualType ElementType = getDerived().TransformType(T->getElementType());
3904 if (ElementType.isNull())
3905 return QualType();
3906
3907 QualType Result = TL.getType();
3908 if (getDerived().AlwaysRebuild() ||
3909 ElementType != T->getElementType()) {
3910 Result = getDerived().RebuildExtVectorType(ElementType,
3911 T->getNumElements(),
3912 /*FIXME*/ SourceLocation());
3913 if (Result.isNull())
3914 return QualType();
3915 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003916
John McCalla2becad2009-10-21 00:40:46 +00003917 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3918 NewTL.setNameLoc(TL.getNameLoc());
3919
3920 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003921}
Mike Stump1eb44332009-09-09 15:08:12 +00003922
3923template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003924ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003925TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003926 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003927 llvm::Optional<unsigned> NumExpansions,
3928 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003929 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003930 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003931
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003932 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003933 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003934 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003935 TypeLoc OldTL = OldDI->getTypeLoc();
3936 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003937
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003938 TypeLocBuilder TLB;
3939 TypeLoc NewTL = OldDI->getTypeLoc();
3940 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003941
3942 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003943 OldExpansionTL.getPatternLoc());
3944 if (Result.isNull())
3945 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003946
3947 Result = RebuildPackExpansionType(Result,
3948 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003949 OldExpansionTL.getEllipsisLoc(),
3950 NumExpansions);
3951 if (Result.isNull())
3952 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003953
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003954 PackExpansionTypeLoc NewExpansionTL
3955 = TLB.push<PackExpansionTypeLoc>(Result);
3956 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3957 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3958 } else
3959 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003960 if (!NewDI)
3961 return 0;
3962
John McCallfb44de92011-05-01 22:35:37 +00003963 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003964 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003965
3966 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3967 OldParm->getDeclContext(),
3968 OldParm->getInnerLocStart(),
3969 OldParm->getLocation(),
3970 OldParm->getIdentifier(),
3971 NewDI->getType(),
3972 NewDI,
3973 OldParm->getStorageClass(),
3974 OldParm->getStorageClassAsWritten(),
3975 /* DefArg */ NULL);
3976 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3977 OldParm->getFunctionScopeIndex() + indexAdjustment);
3978 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003979}
3980
3981template<typename Derived>
3982bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003983 TransformFunctionTypeParams(SourceLocation Loc,
3984 ParmVarDecl **Params, unsigned NumParams,
3985 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003986 SmallVectorImpl<QualType> &OutParamTypes,
3987 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003988 int indexAdjustment = 0;
3989
Douglas Gregora009b592011-01-07 00:20:55 +00003990 for (unsigned i = 0; i != NumParams; ++i) {
3991 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003992 assert(OldParm->getFunctionScopeIndex() == i);
3993
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003994 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003995 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003996 if (OldParm->isParameterPack()) {
3997 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003998 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003999
Douglas Gregor603cfb42011-01-05 23:12:31 +00004000 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004001 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
4002 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
4003 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4004 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004005 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4006
Douglas Gregor603cfb42011-01-05 23:12:31 +00004007 // Determine whether we should expand the parameter packs.
4008 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004009 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004010 llvm::Optional<unsigned> OrigNumExpansions
4011 = ExpansionTL.getTypePtr()->getNumExpansions();
4012 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004013 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4014 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004015 Unexpanded,
4016 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004017 RetainExpansion,
4018 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004019 return true;
4020 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004021
Douglas Gregor603cfb42011-01-05 23:12:31 +00004022 if (ShouldExpand) {
4023 // Expand the function parameter pack into multiple, separate
4024 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004025 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004026 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004027 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004028 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004029 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004030 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004031 OrigNumExpansions,
4032 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004033 if (!NewParm)
4034 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004035
Douglas Gregora009b592011-01-07 00:20:55 +00004036 OutParamTypes.push_back(NewParm->getType());
4037 if (PVars)
4038 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004039 }
Douglas Gregord3731192011-01-10 07:32:04 +00004040
4041 // If we're supposed to retain a pack expansion, do so by temporarily
4042 // forgetting the partially-substituted parameter pack.
4043 if (RetainExpansion) {
4044 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004045 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004046 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004047 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004048 OrigNumExpansions,
4049 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004050 if (!NewParm)
4051 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004052
Douglas Gregord3731192011-01-10 07:32:04 +00004053 OutParamTypes.push_back(NewParm->getType());
4054 if (PVars)
4055 PVars->push_back(NewParm);
4056 }
4057
John McCallfb44de92011-05-01 22:35:37 +00004058 // The next parameter should have the same adjustment as the
4059 // last thing we pushed, but we post-incremented indexAdjustment
4060 // on every push. Also, if we push nothing, the adjustment should
4061 // go down by one.
4062 indexAdjustment--;
4063
Douglas Gregor603cfb42011-01-05 23:12:31 +00004064 // We're done with the pack expansion.
4065 continue;
4066 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004067
4068 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004069 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004070 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4071 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004072 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004073 NumExpansions,
4074 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004075 } else {
4076 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004077 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004078 llvm::Optional<unsigned>(),
4079 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004080 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004081
John McCall21ef0fa2010-03-11 09:03:00 +00004082 if (!NewParm)
4083 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004084
Douglas Gregora009b592011-01-07 00:20:55 +00004085 OutParamTypes.push_back(NewParm->getType());
4086 if (PVars)
4087 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004088 continue;
4089 }
John McCall21ef0fa2010-03-11 09:03:00 +00004090
4091 // Deal with the possibility that we don't have a parameter
4092 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004093 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004094 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004095 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004096 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004097 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004098 = dyn_cast<PackExpansionType>(OldType)) {
4099 // We have a function parameter pack that may need to be expanded.
4100 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004101 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004102 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004103
Douglas Gregor603cfb42011-01-05 23:12:31 +00004104 // Determine whether we should expand the parameter packs.
4105 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004106 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004107 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004108 Unexpanded,
4109 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004110 RetainExpansion,
4111 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004112 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004113 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004114
Douglas Gregor603cfb42011-01-05 23:12:31 +00004115 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004116 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004117 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004118 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004119 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4120 QualType NewType = getDerived().TransformType(Pattern);
4121 if (NewType.isNull())
4122 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004123
Douglas Gregora009b592011-01-07 00:20:55 +00004124 OutParamTypes.push_back(NewType);
4125 if (PVars)
4126 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004127 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004128
Douglas Gregor603cfb42011-01-05 23:12:31 +00004129 // We're done with the pack expansion.
4130 continue;
4131 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004132
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004133 // If we're supposed to retain a pack expansion, do so by temporarily
4134 // forgetting the partially-substituted parameter pack.
4135 if (RetainExpansion) {
4136 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4137 QualType NewType = getDerived().TransformType(Pattern);
4138 if (NewType.isNull())
4139 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004140
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004141 OutParamTypes.push_back(NewType);
4142 if (PVars)
4143 PVars->push_back(0);
4144 }
Douglas Gregord3731192011-01-10 07:32:04 +00004145
Chad Rosier4a9d7952012-08-08 18:46:20 +00004146 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004147 // expansion.
4148 OldType = Expansion->getPattern();
4149 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004150 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4151 NewType = getDerived().TransformType(OldType);
4152 } else {
4153 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004154 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004155
Douglas Gregor603cfb42011-01-05 23:12:31 +00004156 if (NewType.isNull())
4157 return true;
4158
4159 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004160 NewType = getSema().Context.getPackExpansionType(NewType,
4161 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004162
Douglas Gregora009b592011-01-07 00:20:55 +00004163 OutParamTypes.push_back(NewType);
4164 if (PVars)
4165 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004166 }
4167
John McCallfb44de92011-05-01 22:35:37 +00004168#ifndef NDEBUG
4169 if (PVars) {
4170 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4171 if (ParmVarDecl *parm = (*PVars)[i])
4172 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004173 }
John McCallfb44de92011-05-01 22:35:37 +00004174#endif
4175
4176 return false;
4177}
John McCall21ef0fa2010-03-11 09:03:00 +00004178
4179template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004180QualType
John McCalla2becad2009-10-21 00:40:46 +00004181TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004182 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004183 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4184}
4185
4186template<typename Derived>
4187QualType
4188TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4189 FunctionProtoTypeLoc TL,
4190 CXXRecordDecl *ThisContext,
4191 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004192 // Transform the parameters and return type.
4193 //
Richard Smithe6975e92012-04-17 00:58:00 +00004194 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004195 // When the function has a trailing return type, we instantiate the
4196 // parameters before the return type, since the return type can then refer
4197 // to the parameters themselves (via decltype, sizeof, etc.).
4198 //
Chris Lattner686775d2011-07-20 06:58:45 +00004199 SmallVector<QualType, 4> ParamTypes;
4200 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004201 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004202
Douglas Gregordab60ad2010-10-01 18:44:50 +00004203 QualType ResultType;
4204
Richard Smith9fbf3272012-08-14 22:51:13 +00004205 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004206 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004207 TL.getParmArray(),
4208 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004209 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004210 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004211 return QualType();
4212
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004213 {
4214 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004215 // If a declaration declares a member function or member function
4216 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004217 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004218 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004219 // declarator.
4220 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004221
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004222 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4223 if (ResultType.isNull())
4224 return QualType();
4225 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004226 }
4227 else {
4228 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4229 if (ResultType.isNull())
4230 return QualType();
4231
Chad Rosier4a9d7952012-08-08 18:46:20 +00004232 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004233 TL.getParmArray(),
4234 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004235 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004236 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004237 return QualType();
4238 }
4239
Richard Smithe6975e92012-04-17 00:58:00 +00004240 // FIXME: Need to transform the exception-specification too.
4241
John McCalla2becad2009-10-21 00:40:46 +00004242 QualType Result = TL.getType();
4243 if (getDerived().AlwaysRebuild() ||
4244 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004245 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004246 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4247 Result = getDerived().RebuildFunctionProtoType(ResultType,
4248 ParamTypes.data(),
4249 ParamTypes.size(),
4250 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004251 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004252 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004253 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004254 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004255 if (Result.isNull())
4256 return QualType();
4257 }
Mike Stump1eb44332009-09-09 15:08:12 +00004258
John McCalla2becad2009-10-21 00:40:46 +00004259 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004260 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004261 NewTL.setLParenLoc(TL.getLParenLoc());
4262 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004263 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004264 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4265 NewTL.setArg(i, ParamDecls[i]);
4266
4267 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004268}
Mike Stump1eb44332009-09-09 15:08:12 +00004269
Douglas Gregor577f75a2009-08-04 16:50:30 +00004270template<typename Derived>
4271QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004272 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004273 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004274 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004275 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4276 if (ResultType.isNull())
4277 return QualType();
4278
4279 QualType Result = TL.getType();
4280 if (getDerived().AlwaysRebuild() ||
4281 ResultType != T->getResultType())
4282 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4283
4284 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004285 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004286 NewTL.setLParenLoc(TL.getLParenLoc());
4287 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004288 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004289
4290 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004291}
Mike Stump1eb44332009-09-09 15:08:12 +00004292
John McCalled976492009-12-04 22:46:56 +00004293template<typename Derived> QualType
4294TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004295 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004296 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004297 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004298 if (!D)
4299 return QualType();
4300
4301 QualType Result = TL.getType();
4302 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4303 Result = getDerived().RebuildUnresolvedUsingType(D);
4304 if (Result.isNull())
4305 return QualType();
4306 }
4307
4308 // We might get an arbitrary type spec type back. We should at
4309 // least always get a type spec type, though.
4310 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4311 NewTL.setNameLoc(TL.getNameLoc());
4312
4313 return Result;
4314}
4315
Douglas Gregor577f75a2009-08-04 16:50:30 +00004316template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004317QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004318 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004319 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004320 TypedefNameDecl *Typedef
4321 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4322 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004323 if (!Typedef)
4324 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004325
John McCalla2becad2009-10-21 00:40:46 +00004326 QualType Result = TL.getType();
4327 if (getDerived().AlwaysRebuild() ||
4328 Typedef != T->getDecl()) {
4329 Result = getDerived().RebuildTypedefType(Typedef);
4330 if (Result.isNull())
4331 return QualType();
4332 }
Mike Stump1eb44332009-09-09 15:08:12 +00004333
John McCalla2becad2009-10-21 00:40:46 +00004334 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4335 NewTL.setNameLoc(TL.getNameLoc());
4336
4337 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004338}
Mike Stump1eb44332009-09-09 15:08:12 +00004339
Douglas Gregor577f75a2009-08-04 16:50:30 +00004340template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004341QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004342 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004343 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004344 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4345 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004346
John McCall60d7b3a2010-08-24 06:29:42 +00004347 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004348 if (E.isInvalid())
4349 return QualType();
4350
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004351 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4352 if (E.isInvalid())
4353 return QualType();
4354
John McCalla2becad2009-10-21 00:40:46 +00004355 QualType Result = TL.getType();
4356 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004357 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004358 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004359 if (Result.isNull())
4360 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004361 }
John McCalla2becad2009-10-21 00:40:46 +00004362 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004363
John McCalla2becad2009-10-21 00:40:46 +00004364 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004365 NewTL.setTypeofLoc(TL.getTypeofLoc());
4366 NewTL.setLParenLoc(TL.getLParenLoc());
4367 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004368
4369 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004370}
Mike Stump1eb44332009-09-09 15:08:12 +00004371
4372template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004373QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004374 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004375 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4376 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4377 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004378 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004379
John McCalla2becad2009-10-21 00:40:46 +00004380 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004381 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4382 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004383 if (Result.isNull())
4384 return QualType();
4385 }
Mike Stump1eb44332009-09-09 15:08:12 +00004386
John McCalla2becad2009-10-21 00:40:46 +00004387 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004388 NewTL.setTypeofLoc(TL.getTypeofLoc());
4389 NewTL.setLParenLoc(TL.getLParenLoc());
4390 NewTL.setRParenLoc(TL.getRParenLoc());
4391 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004392
4393 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004394}
Mike Stump1eb44332009-09-09 15:08:12 +00004395
4396template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004397QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004398 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004399 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004400
Douglas Gregor670444e2009-08-04 22:27:00 +00004401 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004402 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4403 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004404
John McCall60d7b3a2010-08-24 06:29:42 +00004405 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004406 if (E.isInvalid())
4407 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004408
Richard Smith76f3f692012-02-22 02:04:18 +00004409 E = getSema().ActOnDecltypeExpression(E.take());
4410 if (E.isInvalid())
4411 return QualType();
4412
John McCalla2becad2009-10-21 00:40:46 +00004413 QualType Result = TL.getType();
4414 if (getDerived().AlwaysRebuild() ||
4415 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004416 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004417 if (Result.isNull())
4418 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004419 }
John McCalla2becad2009-10-21 00:40:46 +00004420 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004421
John McCalla2becad2009-10-21 00:40:46 +00004422 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4423 NewTL.setNameLoc(TL.getNameLoc());
4424
4425 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004426}
4427
4428template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004429QualType TreeTransform<Derived>::TransformUnaryTransformType(
4430 TypeLocBuilder &TLB,
4431 UnaryTransformTypeLoc TL) {
4432 QualType Result = TL.getType();
4433 if (Result->isDependentType()) {
4434 const UnaryTransformType *T = TL.getTypePtr();
4435 QualType NewBase =
4436 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4437 Result = getDerived().RebuildUnaryTransformType(NewBase,
4438 T->getUTTKind(),
4439 TL.getKWLoc());
4440 if (Result.isNull())
4441 return QualType();
4442 }
4443
4444 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4445 NewTL.setKWLoc(TL.getKWLoc());
4446 NewTL.setParensRange(TL.getParensRange());
4447 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4448 return Result;
4449}
4450
4451template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004452QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4453 AutoTypeLoc TL) {
4454 const AutoType *T = TL.getTypePtr();
4455 QualType OldDeduced = T->getDeducedType();
4456 QualType NewDeduced;
4457 if (!OldDeduced.isNull()) {
4458 NewDeduced = getDerived().TransformType(OldDeduced);
4459 if (NewDeduced.isNull())
4460 return QualType();
4461 }
4462
4463 QualType Result = TL.getType();
4464 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4465 Result = getDerived().RebuildAutoType(NewDeduced);
4466 if (Result.isNull())
4467 return QualType();
4468 }
4469
4470 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4471 NewTL.setNameLoc(TL.getNameLoc());
4472
4473 return Result;
4474}
4475
4476template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004477QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004478 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004479 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004480 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004481 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4482 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004483 if (!Record)
4484 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004485
John McCalla2becad2009-10-21 00:40:46 +00004486 QualType Result = TL.getType();
4487 if (getDerived().AlwaysRebuild() ||
4488 Record != T->getDecl()) {
4489 Result = getDerived().RebuildRecordType(Record);
4490 if (Result.isNull())
4491 return QualType();
4492 }
Mike Stump1eb44332009-09-09 15:08:12 +00004493
John McCalla2becad2009-10-21 00:40:46 +00004494 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4495 NewTL.setNameLoc(TL.getNameLoc());
4496
4497 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004498}
Mike Stump1eb44332009-09-09 15:08:12 +00004499
4500template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004501QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004502 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004503 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004504 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004505 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4506 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004507 if (!Enum)
4508 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004509
John McCalla2becad2009-10-21 00:40:46 +00004510 QualType Result = TL.getType();
4511 if (getDerived().AlwaysRebuild() ||
4512 Enum != T->getDecl()) {
4513 Result = getDerived().RebuildEnumType(Enum);
4514 if (Result.isNull())
4515 return QualType();
4516 }
Mike Stump1eb44332009-09-09 15:08:12 +00004517
John McCalla2becad2009-10-21 00:40:46 +00004518 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4519 NewTL.setNameLoc(TL.getNameLoc());
4520
4521 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004522}
John McCall7da24312009-09-05 00:15:47 +00004523
John McCall3cb0ebd2010-03-10 03:28:59 +00004524template<typename Derived>
4525QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4526 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004527 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004528 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4529 TL.getTypePtr()->getDecl());
4530 if (!D) return QualType();
4531
4532 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4533 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4534 return T;
4535}
4536
Douglas Gregor577f75a2009-08-04 16:50:30 +00004537template<typename Derived>
4538QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004539 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004540 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004541 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004542}
4543
Mike Stump1eb44332009-09-09 15:08:12 +00004544template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004545QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004546 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004547 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004548 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004549
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004550 // Substitute into the replacement type, which itself might involve something
4551 // that needs to be transformed. This only tends to occur with default
4552 // template arguments of template template parameters.
4553 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4554 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4555 if (Replacement.isNull())
4556 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004557
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004558 // Always canonicalize the replacement type.
4559 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4560 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004561 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004562 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004563
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004564 // Propagate type-source information.
4565 SubstTemplateTypeParmTypeLoc NewTL
4566 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4567 NewTL.setNameLoc(TL.getNameLoc());
4568 return Result;
4569
John McCall49a832b2009-10-18 09:09:24 +00004570}
4571
4572template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004573QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4574 TypeLocBuilder &TLB,
4575 SubstTemplateTypeParmPackTypeLoc TL) {
4576 return TransformTypeSpecType(TLB, TL);
4577}
4578
4579template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004580QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004581 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004582 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004583 const TemplateSpecializationType *T = TL.getTypePtr();
4584
Douglas Gregor1d752d72011-03-02 18:46:51 +00004585 // The nested-name-specifier never matters in a TemplateSpecializationType,
4586 // because we can't have a dependent nested-name-specifier anyway.
4587 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004588 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004589 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4590 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004591 if (Template.isNull())
4592 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004593
John McCall43fed0d2010-11-12 08:19:04 +00004594 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4595}
4596
Eli Friedmanb001de72011-10-06 23:00:33 +00004597template<typename Derived>
4598QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4599 AtomicTypeLoc TL) {
4600 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4601 if (ValueType.isNull())
4602 return QualType();
4603
4604 QualType Result = TL.getType();
4605 if (getDerived().AlwaysRebuild() ||
4606 ValueType != TL.getValueLoc().getType()) {
4607 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4608 if (Result.isNull())
4609 return QualType();
4610 }
4611
4612 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4613 NewTL.setKWLoc(TL.getKWLoc());
4614 NewTL.setLParenLoc(TL.getLParenLoc());
4615 NewTL.setRParenLoc(TL.getRParenLoc());
4616
4617 return Result;
4618}
4619
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004620namespace {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004621 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004622 /// container that provides a \c getArgLoc() member function.
4623 ///
4624 /// This iterator is intended to be used with the iterator form of
4625 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4626 template<typename ArgLocContainer>
4627 class TemplateArgumentLocContainerIterator {
4628 ArgLocContainer *Container;
4629 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004630
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004631 public:
4632 typedef TemplateArgumentLoc value_type;
4633 typedef TemplateArgumentLoc reference;
4634 typedef int difference_type;
4635 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004636
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004637 class pointer {
4638 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004639
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004640 public:
4641 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004642
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004643 const TemplateArgumentLoc *operator->() const {
4644 return &Arg;
4645 }
4646 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004647
4648
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004649 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004650
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004651 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4652 unsigned Index)
4653 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004654
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004655 TemplateArgumentLocContainerIterator &operator++() {
4656 ++Index;
4657 return *this;
4658 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004659
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004660 TemplateArgumentLocContainerIterator operator++(int) {
4661 TemplateArgumentLocContainerIterator Old(*this);
4662 ++(*this);
4663 return Old;
4664 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004665
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004666 TemplateArgumentLoc operator*() const {
4667 return Container->getArgLoc(Index);
4668 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004669
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004670 pointer operator->() const {
4671 return pointer(Container->getArgLoc(Index));
4672 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004673
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004674 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004675 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004676 return X.Container == Y.Container && X.Index == Y.Index;
4677 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004678
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004679 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004680 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004681 return !(X == Y);
4682 }
4683 };
4684}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004685
4686
John McCall43fed0d2010-11-12 08:19:04 +00004687template <typename Derived>
4688QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4689 TypeLocBuilder &TLB,
4690 TemplateSpecializationTypeLoc TL,
4691 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004692 TemplateArgumentListInfo NewTemplateArgs;
4693 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4694 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004695 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4696 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004697 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004698 ArgIterator(TL, TL.getNumArgs()),
4699 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004700 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004701
John McCall833ca992009-10-29 08:12:44 +00004702 // FIXME: maybe don't rebuild if all the template arguments are the same.
4703
4704 QualType Result =
4705 getDerived().RebuildTemplateSpecializationType(Template,
4706 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004707 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004708
4709 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004710 // Specializations of template template parameters are represented as
4711 // TemplateSpecializationTypes, and substitution of type alias templates
4712 // within a dependent context can transform them into
4713 // DependentTemplateSpecializationTypes.
4714 if (isa<DependentTemplateSpecializationType>(Result)) {
4715 DependentTemplateSpecializationTypeLoc NewTL
4716 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004717 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004718 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004719 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004720 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004721 NewTL.setLAngleLoc(TL.getLAngleLoc());
4722 NewTL.setRAngleLoc(TL.getRAngleLoc());
4723 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4724 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4725 return Result;
4726 }
4727
John McCall833ca992009-10-29 08:12:44 +00004728 TemplateSpecializationTypeLoc NewTL
4729 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004730 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004731 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4732 NewTL.setLAngleLoc(TL.getLAngleLoc());
4733 NewTL.setRAngleLoc(TL.getRAngleLoc());
4734 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4735 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004736 }
Mike Stump1eb44332009-09-09 15:08:12 +00004737
John McCall833ca992009-10-29 08:12:44 +00004738 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004739}
Mike Stump1eb44332009-09-09 15:08:12 +00004740
Douglas Gregora88f09f2011-02-28 17:23:35 +00004741template <typename Derived>
4742QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4743 TypeLocBuilder &TLB,
4744 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004745 TemplateName Template,
4746 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004747 TemplateArgumentListInfo NewTemplateArgs;
4748 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4749 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4750 typedef TemplateArgumentLocContainerIterator<
4751 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004752 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004753 ArgIterator(TL, TL.getNumArgs()),
4754 NewTemplateArgs))
4755 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004756
Douglas Gregora88f09f2011-02-28 17:23:35 +00004757 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004758
Douglas Gregora88f09f2011-02-28 17:23:35 +00004759 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4760 QualType Result
4761 = getSema().Context.getDependentTemplateSpecializationType(
4762 TL.getTypePtr()->getKeyword(),
4763 DTN->getQualifier(),
4764 DTN->getIdentifier(),
4765 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004766
Douglas Gregora88f09f2011-02-28 17:23:35 +00004767 DependentTemplateSpecializationTypeLoc NewTL
4768 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004769 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004770 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004771 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004772 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004773 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());
4777 return Result;
4778 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004779
4780 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004781 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004782 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004783 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004784
Douglas Gregora88f09f2011-02-28 17:23:35 +00004785 if (!Result.isNull()) {
4786 /// FIXME: Wrap this in an elaborated-type-specifier?
4787 TemplateSpecializationTypeLoc NewTL
4788 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004789 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004790 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004791 NewTL.setLAngleLoc(TL.getLAngleLoc());
4792 NewTL.setRAngleLoc(TL.getRAngleLoc());
4793 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4794 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4795 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004796
Douglas Gregora88f09f2011-02-28 17:23:35 +00004797 return Result;
4798}
4799
Mike Stump1eb44332009-09-09 15:08:12 +00004800template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004801QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004802TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004803 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004804 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004805
Douglas Gregor9e876872011-03-01 18:12:44 +00004806 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004807 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004808 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004809 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004810 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4811 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004812 return QualType();
4813 }
Mike Stump1eb44332009-09-09 15:08:12 +00004814
John McCall43fed0d2010-11-12 08:19:04 +00004815 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4816 if (NamedT.isNull())
4817 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004818
Richard Smith3e4c6c42011-05-05 21:57:07 +00004819 // C++0x [dcl.type.elab]p2:
4820 // If the identifier resolves to a typedef-name or the simple-template-id
4821 // resolves to an alias template specialization, the
4822 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004823 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4824 if (const TemplateSpecializationType *TST =
4825 NamedT->getAs<TemplateSpecializationType>()) {
4826 TemplateName Template = TST->getTemplateName();
4827 if (TypeAliasTemplateDecl *TAT =
4828 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4829 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4830 diag::err_tag_reference_non_tag) << 4;
4831 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4832 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004833 }
4834 }
4835
John McCalla2becad2009-10-21 00:40:46 +00004836 QualType Result = TL.getType();
4837 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004838 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004839 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004840 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004841 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004842 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004843 if (Result.isNull())
4844 return QualType();
4845 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004846
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004847 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004848 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004849 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004850 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004851}
Mike Stump1eb44332009-09-09 15:08:12 +00004852
4853template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004854QualType TreeTransform<Derived>::TransformAttributedType(
4855 TypeLocBuilder &TLB,
4856 AttributedTypeLoc TL) {
4857 const AttributedType *oldType = TL.getTypePtr();
4858 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4859 if (modifiedType.isNull())
4860 return QualType();
4861
4862 QualType result = TL.getType();
4863
4864 // FIXME: dependent operand expressions?
4865 if (getDerived().AlwaysRebuild() ||
4866 modifiedType != oldType->getModifiedType()) {
4867 // TODO: this is really lame; we should really be rebuilding the
4868 // equivalent type from first principles.
4869 QualType equivalentType
4870 = getDerived().TransformType(oldType->getEquivalentType());
4871 if (equivalentType.isNull())
4872 return QualType();
4873 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4874 modifiedType,
4875 equivalentType);
4876 }
4877
4878 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4879 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4880 if (TL.hasAttrOperand())
4881 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4882 if (TL.hasAttrExprOperand())
4883 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4884 else if (TL.hasAttrEnumOperand())
4885 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4886
4887 return result;
4888}
4889
4890template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004891QualType
4892TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4893 ParenTypeLoc TL) {
4894 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4895 if (Inner.isNull())
4896 return QualType();
4897
4898 QualType Result = TL.getType();
4899 if (getDerived().AlwaysRebuild() ||
4900 Inner != TL.getInnerLoc().getType()) {
4901 Result = getDerived().RebuildParenType(Inner);
4902 if (Result.isNull())
4903 return QualType();
4904 }
4905
4906 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4907 NewTL.setLParenLoc(TL.getLParenLoc());
4908 NewTL.setRParenLoc(TL.getRParenLoc());
4909 return Result;
4910}
4911
4912template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004913QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004914 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004915 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004916
Douglas Gregor2494dd02011-03-01 01:34:45 +00004917 NestedNameSpecifierLoc QualifierLoc
4918 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4919 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004920 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004921
John McCall33500952010-06-11 00:33:02 +00004922 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004923 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004924 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004925 QualifierLoc,
4926 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004927 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004928 if (Result.isNull())
4929 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004930
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004931 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4932 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004933 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4934
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004935 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004936 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004937 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004938 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004939 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004940 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004941 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004942 NewTL.setNameLoc(TL.getNameLoc());
4943 }
John McCalla2becad2009-10-21 00:40:46 +00004944 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004945}
Mike Stump1eb44332009-09-09 15:08:12 +00004946
Douglas Gregor577f75a2009-08-04 16:50:30 +00004947template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004948QualType TreeTransform<Derived>::
4949 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004950 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004951 NestedNameSpecifierLoc QualifierLoc;
4952 if (TL.getQualifierLoc()) {
4953 QualifierLoc
4954 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4955 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004956 return QualType();
4957 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004958
John McCall43fed0d2010-11-12 08:19:04 +00004959 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004960 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004961}
4962
4963template<typename Derived>
4964QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004965TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4966 DependentTemplateSpecializationTypeLoc TL,
4967 NestedNameSpecifierLoc QualifierLoc) {
4968 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004969
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004970 TemplateArgumentListInfo NewTemplateArgs;
4971 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4972 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004973
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004974 typedef TemplateArgumentLocContainerIterator<
4975 DependentTemplateSpecializationTypeLoc> ArgIterator;
4976 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4977 ArgIterator(TL, TL.getNumArgs()),
4978 NewTemplateArgs))
4979 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004980
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004981 QualType Result
4982 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4983 QualifierLoc,
4984 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004985 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004986 NewTemplateArgs);
4987 if (Result.isNull())
4988 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004989
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004990 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4991 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004992
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004993 // Copy information relevant to the template specialization.
4994 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004995 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004996 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004997 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004998 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4999 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005000 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005001 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005002
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005003 // Copy information relevant to the elaborated type.
5004 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005005 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005006 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005007 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5008 DependentTemplateSpecializationTypeLoc SpecTL
5009 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005010 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005011 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005012 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005013 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005014 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5015 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005016 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005017 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005018 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005019 TemplateSpecializationTypeLoc SpecTL
5020 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005021 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005022 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005023 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5024 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005025 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005026 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005027 }
5028 return Result;
5029}
5030
5031template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005032QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5033 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005034 QualType Pattern
5035 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005036 if (Pattern.isNull())
5037 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005038
5039 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005040 if (getDerived().AlwaysRebuild() ||
5041 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005042 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005043 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005044 TL.getEllipsisLoc(),
5045 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005046 if (Result.isNull())
5047 return QualType();
5048 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005049
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005050 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5051 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5052 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005053}
5054
5055template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005056QualType
5057TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005058 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005059 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005060 TLB.pushFullCopy(TL);
5061 return TL.getType();
5062}
5063
5064template<typename Derived>
5065QualType
5066TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005067 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005068 // ObjCObjectType is never dependent.
5069 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005070 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005071}
Mike Stump1eb44332009-09-09 15:08:12 +00005072
5073template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005074QualType
5075TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005076 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005077 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005078 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005079 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005080}
5081
Douglas Gregor577f75a2009-08-04 16:50:30 +00005082//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005083// Statement transformation
5084//===----------------------------------------------------------------------===//
5085template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005086StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005087TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005088 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005089}
5090
5091template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005092StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005093TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5094 return getDerived().TransformCompoundStmt(S, false);
5095}
5096
5097template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005098StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005099TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005100 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005101 Sema::CompoundScopeRAII CompoundScope(getSema());
5102
John McCall7114cba2010-08-27 19:56:05 +00005103 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005104 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005105 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005106 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5107 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005108 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005109 if (Result.isInvalid()) {
5110 // Immediately fail if this was a DeclStmt, since it's very
5111 // likely that this will cause problems for future statements.
5112 if (isa<DeclStmt>(*B))
5113 return StmtError();
5114
5115 // Otherwise, just keep processing substatements and fail later.
5116 SubStmtInvalid = true;
5117 continue;
5118 }
Mike Stump1eb44332009-09-09 15:08:12 +00005119
Douglas Gregor43959a92009-08-20 07:17:43 +00005120 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5121 Statements.push_back(Result.takeAs<Stmt>());
5122 }
Mike Stump1eb44332009-09-09 15:08:12 +00005123
John McCall7114cba2010-08-27 19:56:05 +00005124 if (SubStmtInvalid)
5125 return StmtError();
5126
Douglas Gregor43959a92009-08-20 07:17:43 +00005127 if (!getDerived().AlwaysRebuild() &&
5128 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005129 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005130
5131 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005132 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005133 S->getRBracLoc(),
5134 IsStmtExpr);
5135}
Mike Stump1eb44332009-09-09 15:08:12 +00005136
Douglas Gregor43959a92009-08-20 07:17:43 +00005137template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005138StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005139TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005140 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005141 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005142 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5143 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005144
Eli Friedman264c1f82009-11-19 03:14:00 +00005145 // Transform the left-hand case value.
5146 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005147 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005148 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005149 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005150
Eli Friedman264c1f82009-11-19 03:14:00 +00005151 // Transform the right-hand case value (for the GNU case-range extension).
5152 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005153 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005154 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005155 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005156 }
Mike Stump1eb44332009-09-09 15:08:12 +00005157
Douglas Gregor43959a92009-08-20 07:17:43 +00005158 // Build the case statement.
5159 // Case statements are always rebuilt so that they will attached to their
5160 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005161 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005162 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005163 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005164 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005165 S->getColonLoc());
5166 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005167 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005168
Douglas Gregor43959a92009-08-20 07:17:43 +00005169 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005170 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005171 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005172 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005173
Douglas Gregor43959a92009-08-20 07:17:43 +00005174 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005175 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005176}
5177
5178template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005179StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005180TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005181 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005182 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005183 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005184 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005185
Douglas Gregor43959a92009-08-20 07:17:43 +00005186 // Default statements are always rebuilt
5187 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005188 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005189}
Mike Stump1eb44332009-09-09 15:08:12 +00005190
Douglas Gregor43959a92009-08-20 07:17:43 +00005191template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005192StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005193TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005194 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005195 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005196 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005197
Chris Lattner57ad3782011-02-17 20:34:02 +00005198 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5199 S->getDecl());
5200 if (!LD)
5201 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005202
5203
Douglas Gregor43959a92009-08-20 07:17:43 +00005204 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005205 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005206 cast<LabelDecl>(LD), SourceLocation(),
5207 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005208}
Mike Stump1eb44332009-09-09 15:08:12 +00005209
Douglas Gregor43959a92009-08-20 07:17:43 +00005210template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005211StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005212TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5213 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5214 if (SubStmt.isInvalid())
5215 return StmtError();
5216
5217 // TODO: transform attributes
5218 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5219 return S;
5220
5221 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5222 S->getAttrs(),
5223 SubStmt.get());
5224}
5225
5226template<typename Derived>
5227StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005228TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005229 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005230 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005231 VarDecl *ConditionVar = 0;
5232 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005233 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005234 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005235 getDerived().TransformDefinition(
5236 S->getConditionVariable()->getLocation(),
5237 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005238 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005239 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005240 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005241 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005242
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005243 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005244 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005245
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005246 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005247 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005248 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005249 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005250 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005251 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005252
John McCall9ae2f072010-08-23 23:25:46 +00005253 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005254 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005255 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005256
John McCall9ae2f072010-08-23 23:25:46 +00005257 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5258 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005259 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005260
Douglas Gregor43959a92009-08-20 07:17:43 +00005261 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005262 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005263 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005264 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005265
Douglas Gregor43959a92009-08-20 07:17:43 +00005266 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005267 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005268 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005269 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005270
Douglas Gregor43959a92009-08-20 07:17:43 +00005271 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005272 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005273 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005274 Then.get() == S->getThen() &&
5275 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005276 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005277
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005278 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005279 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005280 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005281}
5282
5283template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005284StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005285TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005286 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005287 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005288 VarDecl *ConditionVar = 0;
5289 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005290 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005291 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005292 getDerived().TransformDefinition(
5293 S->getConditionVariable()->getLocation(),
5294 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005295 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005296 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005297 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005298 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005299
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005300 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005301 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005302 }
Mike Stump1eb44332009-09-09 15:08:12 +00005303
Douglas Gregor43959a92009-08-20 07:17:43 +00005304 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005305 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005306 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005307 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005308 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005309 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005310
Douglas Gregor43959a92009-08-20 07:17:43 +00005311 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005312 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005313 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005314 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005315
Douglas Gregor43959a92009-08-20 07:17:43 +00005316 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005317 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5318 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005319}
Mike Stump1eb44332009-09-09 15:08:12 +00005320
Douglas Gregor43959a92009-08-20 07:17:43 +00005321template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005322StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005323TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005324 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005325 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005326 VarDecl *ConditionVar = 0;
5327 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005328 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005329 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005330 getDerived().TransformDefinition(
5331 S->getConditionVariable()->getLocation(),
5332 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005333 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005334 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005335 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005336 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005337
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005338 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005339 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005340
5341 if (S->getCond()) {
5342 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005343 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005344 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005345 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005346 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005347 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005348 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005349 }
Mike Stump1eb44332009-09-09 15:08:12 +00005350
John McCall9ae2f072010-08-23 23:25:46 +00005351 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5352 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005353 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005354
Douglas Gregor43959a92009-08-20 07:17:43 +00005355 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005356 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005357 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005358 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005359
Douglas Gregor43959a92009-08-20 07:17:43 +00005360 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005361 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005362 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005363 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005364 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005365
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005366 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005367 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005368}
Mike Stump1eb44332009-09-09 15:08:12 +00005369
Douglas Gregor43959a92009-08-20 07:17:43 +00005370template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005371StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005372TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005373 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005374 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005375 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005376 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005377
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005378 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005379 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005380 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005381 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005382
Douglas Gregor43959a92009-08-20 07:17:43 +00005383 if (!getDerived().AlwaysRebuild() &&
5384 Cond.get() == S->getCond() &&
5385 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005386 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005387
John McCall9ae2f072010-08-23 23:25:46 +00005388 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5389 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005390 S->getRParenLoc());
5391}
Mike Stump1eb44332009-09-09 15:08:12 +00005392
Douglas Gregor43959a92009-08-20 07:17:43 +00005393template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005394StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005395TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005396 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005397 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005398 if (Init.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 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005402 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005403 VarDecl *ConditionVar = 0;
5404 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005405 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005406 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005407 getDerived().TransformDefinition(
5408 S->getConditionVariable()->getLocation(),
5409 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005410 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005411 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005412 } else {
5413 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005414
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005415 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005416 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005417
5418 if (S->getCond()) {
5419 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005420 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005421 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005422 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005423 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005424
John McCall9ae2f072010-08-23 23:25:46 +00005425 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005426 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005427 }
Mike Stump1eb44332009-09-09 15:08:12 +00005428
Chad Rosier4a9d7952012-08-08 18:46:20 +00005429 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005430 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005431 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005432
Douglas Gregor43959a92009-08-20 07:17:43 +00005433 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005434 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005435 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005436 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005437
John McCall9ae2f072010-08-23 23:25:46 +00005438 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5439 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005440 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005441
Douglas Gregor43959a92009-08-20 07:17:43 +00005442 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005443 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005444 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005445 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005446
Douglas Gregor43959a92009-08-20 07:17:43 +00005447 if (!getDerived().AlwaysRebuild() &&
5448 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005449 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005450 Inc.get() == S->getInc() &&
5451 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005452 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005453
Douglas Gregor43959a92009-08-20 07:17:43 +00005454 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005455 Init.get(), FullCond, ConditionVar,
5456 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005457}
5458
5459template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005460StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005461TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005462 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5463 S->getLabel());
5464 if (!LD)
5465 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005466
Douglas Gregor43959a92009-08-20 07:17:43 +00005467 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005468 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005469 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005470}
5471
5472template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005473StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005474TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005475 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005476 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005477 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005478 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005479
Douglas Gregor43959a92009-08-20 07:17:43 +00005480 if (!getDerived().AlwaysRebuild() &&
5481 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005482 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005483
5484 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005485 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005486}
5487
5488template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005489StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005490TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005491 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005492}
Mike Stump1eb44332009-09-09 15:08:12 +00005493
Douglas Gregor43959a92009-08-20 07:17:43 +00005494template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005495StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005496TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005497 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005498}
Mike Stump1eb44332009-09-09 15:08:12 +00005499
Douglas Gregor43959a92009-08-20 07:17:43 +00005500template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005501StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005502TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005503 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005504 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005505 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005506
Mike Stump1eb44332009-09-09 15:08:12 +00005507 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005508 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005509 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005510}
Mike Stump1eb44332009-09-09 15:08:12 +00005511
Douglas Gregor43959a92009-08-20 07:17:43 +00005512template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005513StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005514TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005515 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005516 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005517 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5518 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005519 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5520 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005521 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005522 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005523
Douglas Gregor43959a92009-08-20 07:17:43 +00005524 if (Transformed != *D)
5525 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005526
Douglas Gregor43959a92009-08-20 07:17:43 +00005527 Decls.push_back(Transformed);
5528 }
Mike Stump1eb44332009-09-09 15:08:12 +00005529
Douglas Gregor43959a92009-08-20 07:17:43 +00005530 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005531 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005532
5533 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005534 S->getStartLoc(), S->getEndLoc());
5535}
Mike Stump1eb44332009-09-09 15:08:12 +00005536
Douglas Gregor43959a92009-08-20 07:17:43 +00005537template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005538StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005539TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005540
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005541 SmallVector<Expr*, 8> Constraints;
5542 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005543 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005544
John McCall60d7b3a2010-08-24 06:29:42 +00005545 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005546 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005547
5548 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005549
Anders Carlsson703e3942010-01-24 05:50:09 +00005550 // Go through the outputs.
5551 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005552 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005553
Anders Carlsson703e3942010-01-24 05:50:09 +00005554 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005555 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005556
Anders Carlsson703e3942010-01-24 05:50:09 +00005557 // Transform the output expr.
5558 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005559 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005560 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005561 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005562
Anders Carlsson703e3942010-01-24 05:50:09 +00005563 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005564
John McCall9ae2f072010-08-23 23:25:46 +00005565 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005566 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005567
Anders Carlsson703e3942010-01-24 05:50:09 +00005568 // Go through the inputs.
5569 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005570 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005571
Anders Carlsson703e3942010-01-24 05:50:09 +00005572 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005573 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005574
Anders Carlsson703e3942010-01-24 05:50:09 +00005575 // Transform the input expr.
5576 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005577 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005578 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005579 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005580
Anders Carlsson703e3942010-01-24 05:50:09 +00005581 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005582
John McCall9ae2f072010-08-23 23:25:46 +00005583 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005584 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005585
Anders Carlsson703e3942010-01-24 05:50:09 +00005586 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005587 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005588
5589 // Go through the clobbers.
5590 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005591 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005592
5593 // No need to transform the asm string literal.
5594 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005595 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5596 S->isVolatile(), S->getNumOutputs(),
5597 S->getNumInputs(), Names.data(),
5598 Constraints, Exprs, AsmString.get(),
5599 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005600}
5601
Chad Rosier8cd64b42012-06-11 20:47:18 +00005602template<typename Derived>
5603StmtResult
5604TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005605 ArrayRef<Token> AsmToks =
5606 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005607
Chad Rosier7bd092b2012-08-15 16:53:30 +00005608 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
5609 AsmToks, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005610}
Douglas Gregor43959a92009-08-20 07:17:43 +00005611
5612template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005613StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005614TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005615 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005616 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005617 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005618 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005619
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005620 // Transform the @catch statements (if present).
5621 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005622 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005623 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005624 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005625 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005626 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005627 if (Catch.get() != S->getCatchStmt(I))
5628 AnyCatchChanged = true;
5629 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005630 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005631
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005632 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005633 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005634 if (S->getFinallyStmt()) {
5635 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5636 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005637 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005638 }
5639
5640 // If nothing changed, just retain this statement.
5641 if (!getDerived().AlwaysRebuild() &&
5642 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005643 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005644 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005645 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005646
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005647 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005648 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005649 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005650}
Mike Stump1eb44332009-09-09 15:08:12 +00005651
Douglas Gregor43959a92009-08-20 07:17:43 +00005652template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005653StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005654TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005655 // Transform the @catch parameter, if there is one.
5656 VarDecl *Var = 0;
5657 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5658 TypeSourceInfo *TSInfo = 0;
5659 if (FromVar->getTypeSourceInfo()) {
5660 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5661 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005662 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005663 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005664
Douglas Gregorbe270a02010-04-26 17:57:08 +00005665 QualType T;
5666 if (TSInfo)
5667 T = TSInfo->getType();
5668 else {
5669 T = getDerived().TransformType(FromVar->getType());
5670 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005671 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005672 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005673
Douglas Gregorbe270a02010-04-26 17:57:08 +00005674 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5675 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005676 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005677 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005678
John McCall60d7b3a2010-08-24 06:29:42 +00005679 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005680 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005681 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005682
5683 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005684 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005685 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005686}
Mike Stump1eb44332009-09-09 15:08:12 +00005687
Douglas Gregor43959a92009-08-20 07:17:43 +00005688template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005689StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005690TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005691 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005692 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005693 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005694 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005695
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005696 // If nothing changed, just retain this statement.
5697 if (!getDerived().AlwaysRebuild() &&
5698 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005699 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005700
5701 // Build a new statement.
5702 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005703 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005704}
Mike Stump1eb44332009-09-09 15:08:12 +00005705
Douglas Gregor43959a92009-08-20 07:17:43 +00005706template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005707StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005708TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005709 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005710 if (S->getThrowExpr()) {
5711 Operand = getDerived().TransformExpr(S->getThrowExpr());
5712 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005713 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005714 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005715
Douglas Gregord1377b22010-04-22 21:44:01 +00005716 if (!getDerived().AlwaysRebuild() &&
5717 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005718 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005719
John McCall9ae2f072010-08-23 23:25:46 +00005720 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005721}
Mike Stump1eb44332009-09-09 15:08:12 +00005722
Douglas Gregor43959a92009-08-20 07:17:43 +00005723template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005724StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005725TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005726 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005727 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005728 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005729 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005730 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005731 Object =
5732 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5733 Object.get());
5734 if (Object.isInvalid())
5735 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005736
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005737 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005738 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005739 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005740 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005741
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005742 // If nothing change, just retain the current statement.
5743 if (!getDerived().AlwaysRebuild() &&
5744 Object.get() == S->getSynchExpr() &&
5745 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005746 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005747
5748 // Build a new statement.
5749 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005750 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005751}
5752
5753template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005754StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005755TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5756 ObjCAutoreleasePoolStmt *S) {
5757 // Transform the body.
5758 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5759 if (Body.isInvalid())
5760 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005761
John McCallf85e1932011-06-15 23:02:42 +00005762 // If nothing changed, just retain this statement.
5763 if (!getDerived().AlwaysRebuild() &&
5764 Body.get() == S->getSubStmt())
5765 return SemaRef.Owned(S);
5766
5767 // Build a new statement.
5768 return getDerived().RebuildObjCAutoreleasePoolStmt(
5769 S->getAtLoc(), Body.get());
5770}
5771
5772template<typename Derived>
5773StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005774TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005775 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005776 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005777 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005778 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005779 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005780
Douglas Gregorc3203e72010-04-22 23:10:45 +00005781 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005782 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005783 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005784 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005785
Douglas Gregorc3203e72010-04-22 23:10:45 +00005786 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005787 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005788 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005789 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005790
Douglas Gregorc3203e72010-04-22 23:10:45 +00005791 // If nothing changed, just retain this statement.
5792 if (!getDerived().AlwaysRebuild() &&
5793 Element.get() == S->getElement() &&
5794 Collection.get() == S->getCollection() &&
5795 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005796 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005797
Douglas Gregorc3203e72010-04-22 23:10:45 +00005798 // Build a new statement.
5799 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005800 Element.get(),
5801 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005802 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005803 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005804}
5805
5806
5807template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005808StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005809TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5810 // Transform the exception declaration, if any.
5811 VarDecl *Var = 0;
5812 if (S->getExceptionDecl()) {
5813 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005814 TypeSourceInfo *T = getDerived().TransformType(
5815 ExceptionDecl->getTypeSourceInfo());
5816 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005817 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005818
Douglas Gregor83cb9422010-09-09 17:09:21 +00005819 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005820 ExceptionDecl->getInnerLocStart(),
5821 ExceptionDecl->getLocation(),
5822 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005823 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005824 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005825 }
Mike Stump1eb44332009-09-09 15:08:12 +00005826
Douglas Gregor43959a92009-08-20 07:17:43 +00005827 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005828 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005829 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005830 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005831
Douglas Gregor43959a92009-08-20 07:17:43 +00005832 if (!getDerived().AlwaysRebuild() &&
5833 !Var &&
5834 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005835 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005836
5837 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5838 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005839 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005840}
Mike Stump1eb44332009-09-09 15:08:12 +00005841
Douglas Gregor43959a92009-08-20 07:17:43 +00005842template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005843StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005844TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5845 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005846 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005847 = getDerived().TransformCompoundStmt(S->getTryBlock());
5848 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005849 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005850
Douglas Gregor43959a92009-08-20 07:17:43 +00005851 // Transform the handlers.
5852 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005853 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00005854 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005855 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005856 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5857 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005858 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005859
Douglas Gregor43959a92009-08-20 07:17:43 +00005860 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5861 Handlers.push_back(Handler.takeAs<Stmt>());
5862 }
Mike Stump1eb44332009-09-09 15:08:12 +00005863
Douglas Gregor43959a92009-08-20 07:17:43 +00005864 if (!getDerived().AlwaysRebuild() &&
5865 TryBlock.get() == S->getTryBlock() &&
5866 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005867 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005868
John McCall9ae2f072010-08-23 23:25:46 +00005869 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005870 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00005871}
Mike Stump1eb44332009-09-09 15:08:12 +00005872
Richard Smithad762fc2011-04-14 22:09:26 +00005873template<typename Derived>
5874StmtResult
5875TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5876 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5877 if (Range.isInvalid())
5878 return StmtError();
5879
5880 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5881 if (BeginEnd.isInvalid())
5882 return StmtError();
5883
5884 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5885 if (Cond.isInvalid())
5886 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005887 if (Cond.get())
5888 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5889 if (Cond.isInvalid())
5890 return StmtError();
5891 if (Cond.get())
5892 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005893
5894 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5895 if (Inc.isInvalid())
5896 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005897 if (Inc.get())
5898 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005899
5900 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5901 if (LoopVar.isInvalid())
5902 return StmtError();
5903
5904 StmtResult NewStmt = S;
5905 if (getDerived().AlwaysRebuild() ||
5906 Range.get() != S->getRangeStmt() ||
5907 BeginEnd.get() != S->getBeginEndStmt() ||
5908 Cond.get() != S->getCond() ||
5909 Inc.get() != S->getInc() ||
5910 LoopVar.get() != S->getLoopVarStmt())
5911 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5912 S->getColonLoc(), Range.get(),
5913 BeginEnd.get(), Cond.get(),
5914 Inc.get(), LoopVar.get(),
5915 S->getRParenLoc());
5916
5917 StmtResult Body = getDerived().TransformStmt(S->getBody());
5918 if (Body.isInvalid())
5919 return StmtError();
5920
5921 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5922 // it now so we have a new statement to attach the body to.
5923 if (Body.get() != S->getBody() && NewStmt.get() == S)
5924 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5925 S->getColonLoc(), Range.get(),
5926 BeginEnd.get(), Cond.get(),
5927 Inc.get(), LoopVar.get(),
5928 S->getRParenLoc());
5929
5930 if (NewStmt.get() == S)
5931 return SemaRef.Owned(S);
5932
5933 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5934}
5935
John Wiegley28bbe4b2011-04-28 01:08:34 +00005936template<typename Derived>
5937StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005938TreeTransform<Derived>::TransformMSDependentExistsStmt(
5939 MSDependentExistsStmt *S) {
5940 // Transform the nested-name-specifier, if any.
5941 NestedNameSpecifierLoc QualifierLoc;
5942 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005943 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00005944 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5945 if (!QualifierLoc)
5946 return StmtError();
5947 }
5948
5949 // Transform the declaration name.
5950 DeclarationNameInfo NameInfo = S->getNameInfo();
5951 if (NameInfo.getName()) {
5952 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5953 if (!NameInfo.getName())
5954 return StmtError();
5955 }
5956
5957 // Check whether anything changed.
5958 if (!getDerived().AlwaysRebuild() &&
5959 QualifierLoc == S->getQualifierLoc() &&
5960 NameInfo.getName() == S->getNameInfo().getName())
5961 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005962
Douglas Gregorba0513d2011-10-25 01:33:02 +00005963 // Determine whether this name exists, if we can.
5964 CXXScopeSpec SS;
5965 SS.Adopt(QualifierLoc);
5966 bool Dependent = false;
5967 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5968 case Sema::IER_Exists:
5969 if (S->isIfExists())
5970 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005971
Douglas Gregorba0513d2011-10-25 01:33:02 +00005972 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5973
5974 case Sema::IER_DoesNotExist:
5975 if (S->isIfNotExists())
5976 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005977
Douglas Gregorba0513d2011-10-25 01:33:02 +00005978 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005979
Douglas Gregorba0513d2011-10-25 01:33:02 +00005980 case Sema::IER_Dependent:
5981 Dependent = true;
5982 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005983
Douglas Gregor65019ac2011-10-25 03:44:56 +00005984 case Sema::IER_Error:
5985 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005986 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005987
Douglas Gregorba0513d2011-10-25 01:33:02 +00005988 // We need to continue with the instantiation, so do so now.
5989 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5990 if (SubStmt.isInvalid())
5991 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005992
Douglas Gregorba0513d2011-10-25 01:33:02 +00005993 // If we have resolved the name, just transform to the substatement.
5994 if (!Dependent)
5995 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005996
Douglas Gregorba0513d2011-10-25 01:33:02 +00005997 // The name is still dependent, so build a dependent expression again.
5998 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5999 S->isIfExists(),
6000 QualifierLoc,
6001 NameInfo,
6002 SubStmt.get());
6003}
6004
6005template<typename Derived>
6006StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006007TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6008 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6009 if(TryBlock.isInvalid()) return StmtError();
6010
6011 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6012 if(!getDerived().AlwaysRebuild() &&
6013 TryBlock.get() == S->getTryBlock() &&
6014 Handler.get() == S->getHandler())
6015 return SemaRef.Owned(S);
6016
6017 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6018 S->getTryLoc(),
6019 TryBlock.take(),
6020 Handler.take());
6021}
6022
6023template<typename Derived>
6024StmtResult
6025TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6026 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6027 if(Block.isInvalid()) return StmtError();
6028
6029 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6030 Block.take());
6031}
6032
6033template<typename Derived>
6034StmtResult
6035TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6036 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6037 if(FilterExpr.isInvalid()) return StmtError();
6038
6039 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6040 if(Block.isInvalid()) return StmtError();
6041
6042 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6043 FilterExpr.take(),
6044 Block.take());
6045}
6046
6047template<typename Derived>
6048StmtResult
6049TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6050 if(isa<SEHFinallyStmt>(Handler))
6051 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6052 else
6053 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6054}
6055
Douglas Gregor43959a92009-08-20 07:17:43 +00006056//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006057// Expression transformation
6058//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006059template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006060ExprResult
John McCall454feb92009-12-08 09:21:05 +00006061TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006062 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006063}
Mike Stump1eb44332009-09-09 15:08:12 +00006064
6065template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006066ExprResult
John McCall454feb92009-12-08 09:21:05 +00006067TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006068 NestedNameSpecifierLoc QualifierLoc;
6069 if (E->getQualifierLoc()) {
6070 QualifierLoc
6071 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6072 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006073 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006074 }
John McCalldbd872f2009-12-08 09:08:17 +00006075
6076 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006077 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6078 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006079 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006080 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006081
John McCallec8045d2010-08-17 21:27:17 +00006082 DeclarationNameInfo NameInfo = E->getNameInfo();
6083 if (NameInfo.getName()) {
6084 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6085 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006086 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006087 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006088
6089 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006090 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006091 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006092 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006093 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006094
6095 // Mark it referenced in the new context regardless.
6096 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006097 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006098
John McCall3fa5cae2010-10-26 07:05:15 +00006099 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006100 }
John McCalldbd872f2009-12-08 09:08:17 +00006101
6102 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006103 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006104 TemplateArgs = &TransArgs;
6105 TransArgs.setLAngleLoc(E->getLAngleLoc());
6106 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006107 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6108 E->getNumTemplateArgs(),
6109 TransArgs))
6110 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006111 }
6112
Chad Rosier4a9d7952012-08-08 18:46:20 +00006113 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006114 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006115}
Mike Stump1eb44332009-09-09 15:08:12 +00006116
Douglas Gregorb98b1992009-08-11 05:31:07 +00006117template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006118ExprResult
John McCall454feb92009-12-08 09:21:05 +00006119TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006120 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006121}
Mike Stump1eb44332009-09-09 15:08:12 +00006122
Douglas Gregorb98b1992009-08-11 05:31:07 +00006123template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006124ExprResult
John McCall454feb92009-12-08 09:21:05 +00006125TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006126 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006127}
Mike Stump1eb44332009-09-09 15:08:12 +00006128
Douglas Gregorb98b1992009-08-11 05:31:07 +00006129template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006130ExprResult
John McCall454feb92009-12-08 09:21:05 +00006131TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006132 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006133}
Mike Stump1eb44332009-09-09 15:08:12 +00006134
Douglas Gregorb98b1992009-08-11 05:31:07 +00006135template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006136ExprResult
John McCall454feb92009-12-08 09:21:05 +00006137TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006138 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006139}
Mike Stump1eb44332009-09-09 15:08:12 +00006140
Douglas Gregorb98b1992009-08-11 05:31:07 +00006141template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006142ExprResult
John McCall454feb92009-12-08 09:21:05 +00006143TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006144 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006145}
6146
6147template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006148ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006149TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6150 return SemaRef.MaybeBindToTemporary(E);
6151}
6152
6153template<typename Derived>
6154ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006155TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6156 ExprResult ControllingExpr =
6157 getDerived().TransformExpr(E->getControllingExpr());
6158 if (ControllingExpr.isInvalid())
6159 return ExprError();
6160
Chris Lattner686775d2011-07-20 06:58:45 +00006161 SmallVector<Expr *, 4> AssocExprs;
6162 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006163 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6164 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6165 if (TS) {
6166 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6167 if (!AssocType)
6168 return ExprError();
6169 AssocTypes.push_back(AssocType);
6170 } else {
6171 AssocTypes.push_back(0);
6172 }
6173
6174 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6175 if (AssocExpr.isInvalid())
6176 return ExprError();
6177 AssocExprs.push_back(AssocExpr.release());
6178 }
6179
6180 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6181 E->getDefaultLoc(),
6182 E->getRParenLoc(),
6183 ControllingExpr.release(),
6184 AssocTypes.data(),
6185 AssocExprs.data(),
6186 E->getNumAssocs());
6187}
6188
6189template<typename Derived>
6190ExprResult
John McCall454feb92009-12-08 09:21:05 +00006191TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006192 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006193 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006194 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006195
Douglas Gregorb98b1992009-08-11 05:31:07 +00006196 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006197 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006198
John McCall9ae2f072010-08-23 23:25:46 +00006199 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006200 E->getRParen());
6201}
6202
Richard Smithefeeccf2012-10-21 03:28:35 +00006203/// \brief The operand of a unary address-of operator has special rules: it's
6204/// allowed to refer to a non-static member of a class even if there's no 'this'
6205/// object available.
6206template<typename Derived>
6207ExprResult
6208TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6209 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6210 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6211 else
6212 return getDerived().TransformExpr(E);
6213}
6214
Mike Stump1eb44332009-09-09 15:08:12 +00006215template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006216ExprResult
John McCall454feb92009-12-08 09:21:05 +00006217TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00006218 ExprResult SubExpr = TransformAddressOfOperand(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006219 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006220 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006221
Douglas Gregorb98b1992009-08-11 05:31:07 +00006222 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006223 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006224
Douglas Gregorb98b1992009-08-11 05:31:07 +00006225 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6226 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006227 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006228}
Mike Stump1eb44332009-09-09 15:08:12 +00006229
Douglas Gregorb98b1992009-08-11 05:31:07 +00006230template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006231ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006232TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6233 // Transform the type.
6234 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6235 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006236 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006237
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006238 // Transform all of the components into components similar to what the
6239 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006240 // FIXME: It would be slightly more efficient in the non-dependent case to
6241 // just map FieldDecls, rather than requiring the rebuilder to look for
6242 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006243 // template code that we don't care.
6244 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006245 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006246 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006247 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006248 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6249 const Node &ON = E->getComponent(I);
6250 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006251 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006252 Comp.LocStart = ON.getSourceRange().getBegin();
6253 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006254 switch (ON.getKind()) {
6255 case Node::Array: {
6256 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006257 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006258 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006259 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006260
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006261 ExprChanged = ExprChanged || Index.get() != FromIndex;
6262 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006263 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006264 break;
6265 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006266
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006267 case Node::Field:
6268 case Node::Identifier:
6269 Comp.isBrackets = false;
6270 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006271 if (!Comp.U.IdentInfo)
6272 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006273
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006274 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006275
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006276 case Node::Base:
6277 // Will be recomputed during the rebuild.
6278 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006279 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006280
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006281 Components.push_back(Comp);
6282 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006283
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006284 // If nothing changed, retain the existing expression.
6285 if (!getDerived().AlwaysRebuild() &&
6286 Type == E->getTypeSourceInfo() &&
6287 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006288 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006289
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006290 // Build a new offsetof expression.
6291 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6292 Components.data(), Components.size(),
6293 E->getRParenLoc());
6294}
6295
6296template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006297ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006298TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6299 assert(getDerived().AlreadyTransformed(E->getType()) &&
6300 "opaque value expression requires transformation");
6301 return SemaRef.Owned(E);
6302}
6303
6304template<typename Derived>
6305ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006306TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006307 // Rebuild the syntactic form. The original syntactic form has
6308 // opaque-value expressions in it, so strip those away and rebuild
6309 // the result. This is a really awful way of doing this, but the
6310 // better solution (rebuilding the semantic expressions and
6311 // rebinding OVEs as necessary) doesn't work; we'd need
6312 // TreeTransform to not strip away implicit conversions.
6313 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6314 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006315 if (result.isInvalid()) return ExprError();
6316
6317 // If that gives us a pseudo-object result back, the pseudo-object
6318 // expression must have been an lvalue-to-rvalue conversion which we
6319 // should reapply.
6320 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6321 result = SemaRef.checkPseudoObjectRValue(result.take());
6322
6323 return result;
6324}
6325
6326template<typename Derived>
6327ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006328TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6329 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006330 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006331 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006332
John McCalla93c9342009-12-07 02:54:59 +00006333 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006334 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006335 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006336
John McCall5ab75172009-11-04 07:28:41 +00006337 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006338 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006339
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006340 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6341 E->getKind(),
6342 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006343 }
Mike Stump1eb44332009-09-09 15:08:12 +00006344
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006345 // C++0x [expr.sizeof]p1:
6346 // The operand is either an expression, which is an unevaluated operand
6347 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006348 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6349 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006350
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006351 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6352 if (SubExpr.isInvalid())
6353 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006354
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006355 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6356 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006357
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006358 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6359 E->getOperatorLoc(),
6360 E->getKind(),
6361 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006362}
Mike Stump1eb44332009-09-09 15:08:12 +00006363
Douglas Gregorb98b1992009-08-11 05:31:07 +00006364template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006365ExprResult
John McCall454feb92009-12-08 09:21:05 +00006366TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006367 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006368 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006369 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006370
John McCall60d7b3a2010-08-24 06:29:42 +00006371 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006372 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006373 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006374
6375
Douglas Gregorb98b1992009-08-11 05:31:07 +00006376 if (!getDerived().AlwaysRebuild() &&
6377 LHS.get() == E->getLHS() &&
6378 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006379 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006380
John McCall9ae2f072010-08-23 23:25:46 +00006381 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006382 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006383 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006384 E->getRBracketLoc());
6385}
Mike Stump1eb44332009-09-09 15:08:12 +00006386
6387template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006388ExprResult
John McCall454feb92009-12-08 09:21:05 +00006389TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006390 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006391 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006392 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006393 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006394
6395 // Transform arguments.
6396 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006397 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006398 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006399 &ArgChanged))
6400 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006401
Douglas Gregorb98b1992009-08-11 05:31:07 +00006402 if (!getDerived().AlwaysRebuild() &&
6403 Callee.get() == E->getCallee() &&
6404 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006405 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006406
Douglas Gregorb98b1992009-08-11 05:31:07 +00006407 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006408 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006409 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006410 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006411 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006412 E->getRParenLoc());
6413}
Mike Stump1eb44332009-09-09 15:08:12 +00006414
6415template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006416ExprResult
John McCall454feb92009-12-08 09:21:05 +00006417TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006418 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006419 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006420 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006421
Douglas Gregor40d96a62011-02-28 21:54:11 +00006422 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006423 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006424 QualifierLoc
6425 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006426
Douglas Gregor40d96a62011-02-28 21:54:11 +00006427 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006428 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006429 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006430 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006431
Eli Friedmanf595cc42009-12-04 06:40:45 +00006432 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006433 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6434 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006435 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006436 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006437
John McCall6bb80172010-03-30 21:47:33 +00006438 NamedDecl *FoundDecl = E->getFoundDecl();
6439 if (FoundDecl == E->getMemberDecl()) {
6440 FoundDecl = Member;
6441 } else {
6442 FoundDecl = cast_or_null<NamedDecl>(
6443 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6444 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006445 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006446 }
6447
Douglas Gregorb98b1992009-08-11 05:31:07 +00006448 if (!getDerived().AlwaysRebuild() &&
6449 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006450 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006451 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006452 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006453 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006454
Anders Carlsson1f240322009-12-22 05:24:09 +00006455 // Mark it referenced in the new context regardless.
6456 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006457 SemaRef.MarkMemberReferenced(E);
6458
John McCall3fa5cae2010-10-26 07:05:15 +00006459 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006460 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006461
John McCalld5532b62009-11-23 01:53:49 +00006462 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006463 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006464 TransArgs.setLAngleLoc(E->getLAngleLoc());
6465 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006466 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6467 E->getNumTemplateArgs(),
6468 TransArgs))
6469 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006470 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006471
Douglas Gregorb98b1992009-08-11 05:31:07 +00006472 // FIXME: Bogus source location for the operator
6473 SourceLocation FakeOperatorLoc
6474 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6475
John McCallc2233c52010-01-15 08:34:02 +00006476 // FIXME: to do this check properly, we will need to preserve the
6477 // first-qualifier-in-scope here, just in case we had a dependent
6478 // base (and therefore couldn't do the check) and a
6479 // nested-name-qualifier (and therefore could do the lookup).
6480 NamedDecl *FirstQualifierInScope = 0;
6481
John McCall9ae2f072010-08-23 23:25:46 +00006482 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006483 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006484 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006485 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006486 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006487 Member,
John McCall6bb80172010-03-30 21:47:33 +00006488 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006489 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006490 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006491 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006492}
Mike Stump1eb44332009-09-09 15:08:12 +00006493
Douglas Gregorb98b1992009-08-11 05:31:07 +00006494template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006495ExprResult
John McCall454feb92009-12-08 09:21:05 +00006496TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006497 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006498 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006499 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006500
John McCall60d7b3a2010-08-24 06:29:42 +00006501 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006502 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006503 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006504
Douglas Gregorb98b1992009-08-11 05:31:07 +00006505 if (!getDerived().AlwaysRebuild() &&
6506 LHS.get() == E->getLHS() &&
6507 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006508 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006509
Lang Hamesbe9af122012-10-02 04:45:10 +00006510 Sema::FPContractStateRAII FPContractState(getSema());
6511 getSema().FPFeatures.fp_contract = E->isFPContractable();
6512
Douglas Gregorb98b1992009-08-11 05:31:07 +00006513 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006514 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006515}
6516
Mike Stump1eb44332009-09-09 15:08:12 +00006517template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006518ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006519TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006520 CompoundAssignOperator *E) {
6521 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006522}
Mike Stump1eb44332009-09-09 15:08:12 +00006523
Douglas Gregorb98b1992009-08-11 05:31:07 +00006524template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006525ExprResult TreeTransform<Derived>::
6526TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6527 // Just rebuild the common and RHS expressions and see whether we
6528 // get any changes.
6529
6530 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6531 if (commonExpr.isInvalid())
6532 return ExprError();
6533
6534 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6535 if (rhs.isInvalid())
6536 return ExprError();
6537
6538 if (!getDerived().AlwaysRebuild() &&
6539 commonExpr.get() == e->getCommon() &&
6540 rhs.get() == e->getFalseExpr())
6541 return SemaRef.Owned(e);
6542
6543 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6544 e->getQuestionLoc(),
6545 0,
6546 e->getColonLoc(),
6547 rhs.get());
6548}
6549
6550template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006551ExprResult
John McCall454feb92009-12-08 09:21:05 +00006552TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006553 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006554 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006555 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006556
John McCall60d7b3a2010-08-24 06:29:42 +00006557 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006558 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006559 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006560
John McCall60d7b3a2010-08-24 06:29:42 +00006561 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006562 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006563 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006564
Douglas Gregorb98b1992009-08-11 05:31:07 +00006565 if (!getDerived().AlwaysRebuild() &&
6566 Cond.get() == E->getCond() &&
6567 LHS.get() == E->getLHS() &&
6568 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006569 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006570
John McCall9ae2f072010-08-23 23:25:46 +00006571 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006572 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006573 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006574 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006575 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006576}
Mike Stump1eb44332009-09-09 15:08:12 +00006577
6578template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006579ExprResult
John McCall454feb92009-12-08 09:21:05 +00006580TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006581 // Implicit casts are eliminated during transformation, since they
6582 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006583 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006584}
Mike Stump1eb44332009-09-09 15:08:12 +00006585
Douglas Gregorb98b1992009-08-11 05:31:07 +00006586template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006587ExprResult
John McCall454feb92009-12-08 09:21:05 +00006588TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006589 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6590 if (!Type)
6591 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006592
John McCall60d7b3a2010-08-24 06:29:42 +00006593 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006594 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006595 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006596 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006597
Douglas Gregorb98b1992009-08-11 05:31:07 +00006598 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006599 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006600 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006601 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006602
John McCall9d125032010-01-15 18:39:57 +00006603 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006604 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006605 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006606 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006607}
Mike Stump1eb44332009-09-09 15:08:12 +00006608
Douglas Gregorb98b1992009-08-11 05:31:07 +00006609template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006610ExprResult
John McCall454feb92009-12-08 09:21:05 +00006611TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006612 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6613 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6614 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006615 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006616
John McCall60d7b3a2010-08-24 06:29:42 +00006617 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006618 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006619 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006620
Douglas Gregorb98b1992009-08-11 05:31:07 +00006621 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006622 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006623 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006624 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006625
John McCall1d7d8d62010-01-19 22:33:45 +00006626 // Note: the expression type doesn't necessarily match the
6627 // type-as-written, but that's okay, because it should always be
6628 // derivable from the initializer.
6629
John McCall42f56b52010-01-18 19:35:47 +00006630 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006631 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006632 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006633}
Mike Stump1eb44332009-09-09 15:08:12 +00006634
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006636ExprResult
John McCall454feb92009-12-08 09:21:05 +00006637TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006638 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006639 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006640 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006641
Douglas Gregorb98b1992009-08-11 05:31:07 +00006642 if (!getDerived().AlwaysRebuild() &&
6643 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006644 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006645
Douglas Gregorb98b1992009-08-11 05:31:07 +00006646 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006647 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006648 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006649 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006650 E->getAccessorLoc(),
6651 E->getAccessor());
6652}
Mike Stump1eb44332009-09-09 15:08:12 +00006653
Douglas Gregorb98b1992009-08-11 05:31:07 +00006654template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006655ExprResult
John McCall454feb92009-12-08 09:21:05 +00006656TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006657 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006658
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006659 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006660 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006661 Inits, &InitChanged))
6662 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006663
Douglas Gregorb98b1992009-08-11 05:31:07 +00006664 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006665 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006666
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006667 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006668 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006669}
Mike Stump1eb44332009-09-09 15:08:12 +00006670
Douglas Gregorb98b1992009-08-11 05:31:07 +00006671template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006672ExprResult
John McCall454feb92009-12-08 09:21:05 +00006673TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006674 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006675
Douglas Gregor43959a92009-08-20 07:17:43 +00006676 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006677 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006678 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006679 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006680
Douglas Gregor43959a92009-08-20 07:17:43 +00006681 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006682 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006683 bool ExprChanged = false;
6684 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6685 DEnd = E->designators_end();
6686 D != DEnd; ++D) {
6687 if (D->isFieldDesignator()) {
6688 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6689 D->getDotLoc(),
6690 D->getFieldLoc()));
6691 continue;
6692 }
Mike Stump1eb44332009-09-09 15:08:12 +00006693
Douglas Gregorb98b1992009-08-11 05:31:07 +00006694 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006695 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006696 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006697 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006698
6699 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006700 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006701
Douglas Gregorb98b1992009-08-11 05:31:07 +00006702 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6703 ArrayExprs.push_back(Index.release());
6704 continue;
6705 }
Mike Stump1eb44332009-09-09 15:08:12 +00006706
Douglas Gregorb98b1992009-08-11 05:31:07 +00006707 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006708 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006709 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6710 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006711 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006712
John McCall60d7b3a2010-08-24 06:29:42 +00006713 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006714 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006715 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006716
6717 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006718 End.get(),
6719 D->getLBracketLoc(),
6720 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006721
Douglas Gregorb98b1992009-08-11 05:31:07 +00006722 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6723 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006724
Douglas Gregorb98b1992009-08-11 05:31:07 +00006725 ArrayExprs.push_back(Start.release());
6726 ArrayExprs.push_back(End.release());
6727 }
Mike Stump1eb44332009-09-09 15:08:12 +00006728
Douglas Gregorb98b1992009-08-11 05:31:07 +00006729 if (!getDerived().AlwaysRebuild() &&
6730 Init.get() == E->getInit() &&
6731 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006732 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006733
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006734 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006735 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006736 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006737}
Mike Stump1eb44332009-09-09 15:08:12 +00006738
Douglas Gregorb98b1992009-08-11 05:31:07 +00006739template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006740ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006741TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006742 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006743 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006744
Douglas Gregor5557b252009-10-28 00:29:27 +00006745 // FIXME: Will we ever have proper type location here? Will we actually
6746 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006747 QualType T = getDerived().TransformType(E->getType());
6748 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006749 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006750
Douglas Gregorb98b1992009-08-11 05:31:07 +00006751 if (!getDerived().AlwaysRebuild() &&
6752 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006753 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006754
Douglas Gregorb98b1992009-08-11 05:31:07 +00006755 return getDerived().RebuildImplicitValueInitExpr(T);
6756}
Mike Stump1eb44332009-09-09 15:08:12 +00006757
Douglas Gregorb98b1992009-08-11 05:31:07 +00006758template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006759ExprResult
John McCall454feb92009-12-08 09:21:05 +00006760TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006761 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6762 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006763 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006764
John McCall60d7b3a2010-08-24 06:29:42 +00006765 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006766 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006767 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006768
Douglas Gregorb98b1992009-08-11 05:31:07 +00006769 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006770 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006771 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006772 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006773
John McCall9ae2f072010-08-23 23:25:46 +00006774 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006775 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006776}
6777
6778template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006779ExprResult
John McCall454feb92009-12-08 09:21:05 +00006780TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006781 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006782 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00006783 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6784 &ArgumentChanged))
6785 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006786
Douglas Gregorb98b1992009-08-11 05:31:07 +00006787 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006788 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006789 E->getRParenLoc());
6790}
Mike Stump1eb44332009-09-09 15:08:12 +00006791
Douglas Gregorb98b1992009-08-11 05:31:07 +00006792/// \brief Transform an address-of-label expression.
6793///
6794/// By default, the transformation of an address-of-label expression always
6795/// rebuilds the expression, so that the label identifier can be resolved to
6796/// the corresponding label statement by semantic analysis.
6797template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006798ExprResult
John McCall454feb92009-12-08 09:21:05 +00006799TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006800 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6801 E->getLabel());
6802 if (!LD)
6803 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006804
Douglas Gregorb98b1992009-08-11 05:31:07 +00006805 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006806 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006807}
Mike Stump1eb44332009-09-09 15:08:12 +00006808
6809template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006810ExprResult
John McCall454feb92009-12-08 09:21:05 +00006811TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006812 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006813 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006814 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006815 if (SubStmt.isInvalid()) {
6816 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006817 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006818 }
Mike Stump1eb44332009-09-09 15:08:12 +00006819
Douglas Gregorb98b1992009-08-11 05:31:07 +00006820 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006821 SubStmt.get() == E->getSubStmt()) {
6822 // Calling this an 'error' is unintuitive, but it does the right thing.
6823 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006824 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006825 }
Mike Stump1eb44332009-09-09 15:08:12 +00006826
6827 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006828 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006829 E->getRParenLoc());
6830}
Mike Stump1eb44332009-09-09 15:08:12 +00006831
Douglas Gregorb98b1992009-08-11 05:31:07 +00006832template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006833ExprResult
John McCall454feb92009-12-08 09:21:05 +00006834TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006835 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006836 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006837 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006838
John McCall60d7b3a2010-08-24 06:29:42 +00006839 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006840 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006841 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006842
John McCall60d7b3a2010-08-24 06:29:42 +00006843 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006844 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006845 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006846
Douglas Gregorb98b1992009-08-11 05:31:07 +00006847 if (!getDerived().AlwaysRebuild() &&
6848 Cond.get() == E->getCond() &&
6849 LHS.get() == E->getLHS() &&
6850 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006851 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006852
Douglas Gregorb98b1992009-08-11 05:31:07 +00006853 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006854 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006855 E->getRParenLoc());
6856}
Mike Stump1eb44332009-09-09 15:08:12 +00006857
Douglas Gregorb98b1992009-08-11 05:31:07 +00006858template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006859ExprResult
John McCall454feb92009-12-08 09:21:05 +00006860TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006861 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006862}
6863
6864template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006865ExprResult
John McCall454feb92009-12-08 09:21:05 +00006866TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006867 switch (E->getOperator()) {
6868 case OO_New:
6869 case OO_Delete:
6870 case OO_Array_New:
6871 case OO_Array_Delete:
6872 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006873
Douglas Gregor668d6d92009-12-13 20:44:55 +00006874 case OO_Call: {
6875 // This is a call to an object's operator().
6876 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6877
6878 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006879 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006880 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006881 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006882
6883 // FIXME: Poor location information
6884 SourceLocation FakeLParenLoc
6885 = SemaRef.PP.getLocForEndOfToken(
6886 static_cast<Expr *>(Object.get())->getLocEnd());
6887
6888 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006889 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006890 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006891 Args))
6892 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006893
John McCall9ae2f072010-08-23 23:25:46 +00006894 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006895 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006896 E->getLocEnd());
6897 }
6898
6899#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6900 case OO_##Name:
6901#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6902#include "clang/Basic/OperatorKinds.def"
6903 case OO_Subscript:
6904 // Handled below.
6905 break;
6906
6907 case OO_Conditional:
6908 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006909
6910 case OO_None:
6911 case NUM_OVERLOADED_OPERATORS:
6912 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006913 }
6914
John McCall60d7b3a2010-08-24 06:29:42 +00006915 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006916 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006917 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006918
Richard Smithefeeccf2012-10-21 03:28:35 +00006919 ExprResult First;
6920 if (E->getOperator() == OO_Amp)
6921 First = getDerived().TransformAddressOfOperand(E->getArg(0));
6922 else
6923 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006924 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006925 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006926
John McCall60d7b3a2010-08-24 06:29:42 +00006927 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006928 if (E->getNumArgs() == 2) {
6929 Second = getDerived().TransformExpr(E->getArg(1));
6930 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006931 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006932 }
Mike Stump1eb44332009-09-09 15:08:12 +00006933
Douglas Gregorb98b1992009-08-11 05:31:07 +00006934 if (!getDerived().AlwaysRebuild() &&
6935 Callee.get() == E->getCallee() &&
6936 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006937 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006938 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006939
Lang Hamesbe9af122012-10-02 04:45:10 +00006940 Sema::FPContractStateRAII FPContractState(getSema());
6941 getSema().FPFeatures.fp_contract = E->isFPContractable();
6942
Douglas Gregorb98b1992009-08-11 05:31:07 +00006943 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6944 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006945 Callee.get(),
6946 First.get(),
6947 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006948}
Mike Stump1eb44332009-09-09 15:08:12 +00006949
Douglas Gregorb98b1992009-08-11 05:31:07 +00006950template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006951ExprResult
John McCall454feb92009-12-08 09:21:05 +00006952TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6953 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006954}
Mike Stump1eb44332009-09-09 15:08:12 +00006955
Douglas Gregorb98b1992009-08-11 05:31:07 +00006956template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006957ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006958TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6959 // Transform the callee.
6960 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6961 if (Callee.isInvalid())
6962 return ExprError();
6963
6964 // Transform exec config.
6965 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6966 if (EC.isInvalid())
6967 return ExprError();
6968
6969 // Transform arguments.
6970 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006971 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006972 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006973 &ArgChanged))
6974 return ExprError();
6975
6976 if (!getDerived().AlwaysRebuild() &&
6977 Callee.get() == E->getCallee() &&
6978 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006979 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006980
6981 // FIXME: Wrong source location information for the '('.
6982 SourceLocation FakeLParenLoc
6983 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6984 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006985 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006986 E->getRParenLoc(), EC.get());
6987}
6988
6989template<typename Derived>
6990ExprResult
John McCall454feb92009-12-08 09:21:05 +00006991TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006992 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6993 if (!Type)
6994 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006995
John McCall60d7b3a2010-08-24 06:29:42 +00006996 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006997 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006998 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006999 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007000
Douglas Gregorb98b1992009-08-11 05:31:07 +00007001 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007002 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007003 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007004 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007005
Douglas Gregorb98b1992009-08-11 05:31:07 +00007006 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00007007 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007008 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
7009 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007010 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007011 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007012 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007013 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007014 FakeRAngleLoc,
7015 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007016 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007017 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007018}
Mike Stump1eb44332009-09-09 15:08:12 +00007019
Douglas Gregorb98b1992009-08-11 05:31:07 +00007020template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007021ExprResult
John McCall454feb92009-12-08 09:21:05 +00007022TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7023 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007024}
Mike Stump1eb44332009-09-09 15:08:12 +00007025
7026template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007027ExprResult
John McCall454feb92009-12-08 09:21:05 +00007028TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7029 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007030}
7031
Douglas Gregorb98b1992009-08-11 05:31:07 +00007032template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007033ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007034TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007035 CXXReinterpretCastExpr *E) {
7036 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007037}
Mike Stump1eb44332009-09-09 15:08:12 +00007038
Douglas Gregorb98b1992009-08-11 05:31:07 +00007039template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007040ExprResult
John McCall454feb92009-12-08 09:21:05 +00007041TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7042 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007043}
Mike Stump1eb44332009-09-09 15:08:12 +00007044
Douglas Gregorb98b1992009-08-11 05:31:07 +00007045template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007046ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007047TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007048 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007049 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7050 if (!Type)
7051 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007052
John McCall60d7b3a2010-08-24 06:29:42 +00007053 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007054 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007055 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007056 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007057
Douglas Gregorb98b1992009-08-11 05:31:07 +00007058 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007059 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007060 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007061 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007062
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007063 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007064 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007065 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007066 E->getRParenLoc());
7067}
Mike Stump1eb44332009-09-09 15:08:12 +00007068
Douglas Gregorb98b1992009-08-11 05:31:07 +00007069template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007070ExprResult
John McCall454feb92009-12-08 09:21:05 +00007071TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007072 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007073 TypeSourceInfo *TInfo
7074 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7075 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007076 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007077
Douglas Gregorb98b1992009-08-11 05:31:07 +00007078 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007079 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007080 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007081
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007082 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7083 E->getLocStart(),
7084 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007085 E->getLocEnd());
7086 }
Mike Stump1eb44332009-09-09 15:08:12 +00007087
Eli Friedmanef331b72012-01-20 01:26:23 +00007088 // We don't know whether the subexpression is potentially evaluated until
7089 // after we perform semantic analysis. We speculatively assume it is
7090 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007091 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007092 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7093 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007094
John McCall60d7b3a2010-08-24 06:29:42 +00007095 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007096 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007097 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007098
Douglas Gregorb98b1992009-08-11 05:31:07 +00007099 if (!getDerived().AlwaysRebuild() &&
7100 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007101 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007102
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007103 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7104 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007105 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007106 E->getLocEnd());
7107}
7108
7109template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007110ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007111TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7112 if (E->isTypeOperand()) {
7113 TypeSourceInfo *TInfo
7114 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7115 if (!TInfo)
7116 return ExprError();
7117
7118 if (!getDerived().AlwaysRebuild() &&
7119 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007120 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007121
Douglas Gregor3c52a212011-03-06 17:40:41 +00007122 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007123 E->getLocStart(),
7124 TInfo,
7125 E->getLocEnd());
7126 }
7127
Francois Pichet01b7c302010-09-08 12:20:18 +00007128 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7129
7130 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7131 if (SubExpr.isInvalid())
7132 return ExprError();
7133
7134 if (!getDerived().AlwaysRebuild() &&
7135 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007136 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007137
7138 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7139 E->getLocStart(),
7140 SubExpr.get(),
7141 E->getLocEnd());
7142}
7143
7144template<typename Derived>
7145ExprResult
John McCall454feb92009-12-08 09:21:05 +00007146TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007147 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007148}
Mike Stump1eb44332009-09-09 15:08:12 +00007149
Douglas Gregorb98b1992009-08-11 05:31:07 +00007150template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007151ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007152TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007153 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007154 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007155}
Mike Stump1eb44332009-09-09 15:08:12 +00007156
Douglas Gregorb98b1992009-08-11 05:31:07 +00007157template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007158ExprResult
John McCall454feb92009-12-08 09:21:05 +00007159TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007160 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007161 QualType T;
7162 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7163 T = MD->getThisType(getSema().Context);
7164 else
7165 T = getSema().Context.getPointerType(
7166 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007167
Douglas Gregorec79d872012-02-24 17:41:38 +00007168 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7169 // Make sure that we capture 'this'.
7170 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007171 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007172 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007173
Douglas Gregor828a1972010-01-07 23:12:05 +00007174 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007175}
Mike Stump1eb44332009-09-09 15:08:12 +00007176
Douglas Gregorb98b1992009-08-11 05:31:07 +00007177template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007178ExprResult
John McCall454feb92009-12-08 09:21:05 +00007179TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007180 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007181 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007182 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007183
Douglas Gregorb98b1992009-08-11 05:31:07 +00007184 if (!getDerived().AlwaysRebuild() &&
7185 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007186 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007187
Douglas Gregorbca01b42011-07-06 22:04:06 +00007188 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7189 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007190}
Mike Stump1eb44332009-09-09 15:08:12 +00007191
Douglas Gregorb98b1992009-08-11 05:31:07 +00007192template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007193ExprResult
John McCall454feb92009-12-08 09:21:05 +00007194TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007195 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007196 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7197 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007198 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007199 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007200
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007201 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007202 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007203 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007204
Douglas Gregor036aed12009-12-23 23:03:06 +00007205 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007206}
Mike Stump1eb44332009-09-09 15:08:12 +00007207
Douglas Gregorb98b1992009-08-11 05:31:07 +00007208template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007209ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007210TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7211 CXXScalarValueInitExpr *E) {
7212 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7213 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007214 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007215
Douglas Gregorb98b1992009-08-11 05:31:07 +00007216 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007217 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007218 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007219
Chad Rosier4a9d7952012-08-08 18:46:20 +00007220 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007221 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007222 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007223}
Mike Stump1eb44332009-09-09 15:08:12 +00007224
Douglas Gregorb98b1992009-08-11 05:31:07 +00007225template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007226ExprResult
John McCall454feb92009-12-08 09:21:05 +00007227TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007228 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007229 TypeSourceInfo *AllocTypeInfo
7230 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7231 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007232 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007233
Douglas Gregorb98b1992009-08-11 05:31:07 +00007234 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007235 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007236 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007237 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007238
Douglas Gregorb98b1992009-08-11 05:31:07 +00007239 // Transform the placement arguments (if any).
7240 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007241 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007242 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007243 E->getNumPlacementArgs(), true,
7244 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007245 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007246
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007247 // Transform the initializer (if any).
7248 Expr *OldInit = E->getInitializer();
7249 ExprResult NewInit;
7250 if (OldInit)
7251 NewInit = getDerived().TransformExpr(OldInit);
7252 if (NewInit.isInvalid())
7253 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007254
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007255 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007256 FunctionDecl *OperatorNew = 0;
7257 if (E->getOperatorNew()) {
7258 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007259 getDerived().TransformDecl(E->getLocStart(),
7260 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007261 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007262 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007263 }
7264
7265 FunctionDecl *OperatorDelete = 0;
7266 if (E->getOperatorDelete()) {
7267 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007268 getDerived().TransformDecl(E->getLocStart(),
7269 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007270 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007271 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007272 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007273
Douglas Gregorb98b1992009-08-11 05:31:07 +00007274 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007275 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007276 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007277 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007278 OperatorNew == E->getOperatorNew() &&
7279 OperatorDelete == E->getOperatorDelete() &&
7280 !ArgumentChanged) {
7281 // Mark any declarations we need as referenced.
7282 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007283 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007284 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007285 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007286 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007287
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007288 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007289 QualType ElementType
7290 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7291 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7292 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7293 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007294 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007295 }
7296 }
7297 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007298
John McCall3fa5cae2010-10-26 07:05:15 +00007299 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007300 }
Mike Stump1eb44332009-09-09 15:08:12 +00007301
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007302 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007303 if (!ArraySize.get()) {
7304 // If no array size was specified, but the new expression was
7305 // instantiated with an array type (e.g., "new T" where T is
7306 // instantiated with "int[4]"), extract the outer bound from the
7307 // array type as our array size. We do this with constant and
7308 // dependently-sized array types.
7309 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7310 if (!ArrayT) {
7311 // Do nothing
7312 } else if (const ConstantArrayType *ConsArrayT
7313 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007314 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007315 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007316 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007317 SemaRef.Context.getSizeType(),
7318 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007319 AllocType = ConsArrayT->getElementType();
7320 } else if (const DependentSizedArrayType *DepArrayT
7321 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7322 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007323 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007324 AllocType = DepArrayT->getElementType();
7325 }
7326 }
7327 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007328
Douglas Gregorb98b1992009-08-11 05:31:07 +00007329 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7330 E->isGlobalNew(),
7331 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007332 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007333 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007334 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007335 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007336 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007337 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007338 E->getDirectInitRange(),
7339 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007340}
Mike Stump1eb44332009-09-09 15:08:12 +00007341
Douglas Gregorb98b1992009-08-11 05:31:07 +00007342template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007343ExprResult
John McCall454feb92009-12-08 09:21:05 +00007344TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007345 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007346 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007347 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007348
Douglas Gregor1af74512010-02-26 00:38:10 +00007349 // Transform the delete operator, if known.
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 Gregor1af74512010-02-26 00:38:10 +00007360 Operand.get() == E->getArgument() &&
7361 OperatorDelete == E->getOperatorDelete()) {
7362 // Mark any declarations we need as referenced.
7363 // FIXME: instantiation-specific.
7364 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007365 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007366
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007367 if (!E->getArgument()->isTypeDependent()) {
7368 QualType Destroyed = SemaRef.Context.getBaseElementType(
7369 E->getDestroyedType());
7370 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7371 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007372 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007373 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007374 }
7375 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007376
John McCall3fa5cae2010-10-26 07:05:15 +00007377 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007378 }
Mike Stump1eb44332009-09-09 15:08:12 +00007379
Douglas Gregorb98b1992009-08-11 05:31:07 +00007380 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7381 E->isGlobalDelete(),
7382 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007383 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007384}
Mike Stump1eb44332009-09-09 15:08:12 +00007385
Douglas Gregorb98b1992009-08-11 05:31:07 +00007386template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007387ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007388TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007389 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007390 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007391 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007392 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007393
John McCallb3d87482010-08-24 05:47:05 +00007394 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007395 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007396 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007397 E->getOperatorLoc(),
7398 E->isArrow()? tok::arrow : tok::period,
7399 ObjectTypePtr,
7400 MayBePseudoDestructor);
7401 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007402 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007403
John McCallb3d87482010-08-24 05:47:05 +00007404 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007405 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7406 if (QualifierLoc) {
7407 QualifierLoc
7408 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7409 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007410 return ExprError();
7411 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007412 CXXScopeSpec SS;
7413 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007414
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007415 PseudoDestructorTypeStorage Destroyed;
7416 if (E->getDestroyedTypeInfo()) {
7417 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007418 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007419 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007420 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007421 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007422 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007423 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007424 // We aren't likely to be able to resolve the identifier down to a type
7425 // now anyway, so just retain the identifier.
7426 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7427 E->getDestroyedTypeLoc());
7428 } else {
7429 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007430 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007431 *E->getDestroyedTypeIdentifier(),
7432 E->getDestroyedTypeLoc(),
7433 /*Scope=*/0,
7434 SS, ObjectTypePtr,
7435 false);
7436 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007437 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007438
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007439 Destroyed
7440 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7441 E->getDestroyedTypeLoc());
7442 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007443
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007444 TypeSourceInfo *ScopeTypeInfo = 0;
7445 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007446 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007447 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007448 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007449 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007450
John McCall9ae2f072010-08-23 23:25:46 +00007451 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007452 E->getOperatorLoc(),
7453 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007454 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007455 ScopeTypeInfo,
7456 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007457 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007458 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007459}
Mike Stump1eb44332009-09-09 15:08:12 +00007460
Douglas Gregora71d8192009-09-04 17:36:40 +00007461template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007462ExprResult
John McCallba135432009-11-21 08:51:07 +00007463TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007464 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007465 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7466 Sema::LookupOrdinaryName);
7467
7468 // Transform all the decls.
7469 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7470 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007471 NamedDecl *InstD = static_cast<NamedDecl*>(
7472 getDerived().TransformDecl(Old->getNameLoc(),
7473 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007474 if (!InstD) {
7475 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7476 // This can happen because of dependent hiding.
7477 if (isa<UsingShadowDecl>(*I))
7478 continue;
7479 else
John McCallf312b1e2010-08-26 23:41:50 +00007480 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007481 }
John McCallf7a1a742009-11-24 19:00:30 +00007482
7483 // Expand using declarations.
7484 if (isa<UsingDecl>(InstD)) {
7485 UsingDecl *UD = cast<UsingDecl>(InstD);
7486 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7487 E = UD->shadow_end(); I != E; ++I)
7488 R.addDecl(*I);
7489 continue;
7490 }
7491
7492 R.addDecl(InstD);
7493 }
7494
7495 // Resolve a kind, but don't do any further analysis. If it's
7496 // ambiguous, the callee needs to deal with it.
7497 R.resolveKind();
7498
7499 // Rebuild the nested-name qualifier, if present.
7500 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007501 if (Old->getQualifierLoc()) {
7502 NestedNameSpecifierLoc QualifierLoc
7503 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7504 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007505 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007506
Douglas Gregor4c9be892011-02-28 20:01:57 +00007507 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007508 }
7509
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007510 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007511 CXXRecordDecl *NamingClass
7512 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7513 Old->getNameLoc(),
7514 Old->getNamingClass()));
7515 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007516 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007517
Douglas Gregor66c45152010-04-27 16:10:10 +00007518 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007519 }
7520
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007521 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7522
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007523 // If we have neither explicit template arguments, nor the template keyword,
7524 // it's a normal declaration name.
7525 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007526 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7527
7528 // If we have template arguments, rebuild them, then rebuild the
7529 // templateid expression.
7530 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007531 if (Old->hasExplicitTemplateArgs() &&
7532 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007533 Old->getNumTemplateArgs(),
7534 TransArgs))
7535 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007536
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007537 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007538 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007539}
Mike Stump1eb44332009-09-09 15:08:12 +00007540
Douglas Gregorb98b1992009-08-11 05:31:07 +00007541template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007542ExprResult
John McCall454feb92009-12-08 09:21:05 +00007543TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007544 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7545 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007546 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007547
Douglas Gregorb98b1992009-08-11 05:31:07 +00007548 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007549 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007550 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007551
Mike Stump1eb44332009-09-09 15:08:12 +00007552 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007553 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007554 T,
7555 E->getLocEnd());
7556}
Mike Stump1eb44332009-09-09 15:08:12 +00007557
Douglas Gregorb98b1992009-08-11 05:31:07 +00007558template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007559ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007560TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7561 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7562 if (!LhsT)
7563 return ExprError();
7564
7565 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7566 if (!RhsT)
7567 return ExprError();
7568
7569 if (!getDerived().AlwaysRebuild() &&
7570 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7571 return SemaRef.Owned(E);
7572
7573 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7574 E->getLocStart(),
7575 LhsT, RhsT,
7576 E->getLocEnd());
7577}
7578
7579template<typename Derived>
7580ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007581TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7582 bool ArgChanged = false;
7583 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7584 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7585 TypeSourceInfo *From = E->getArg(I);
7586 TypeLoc FromTL = From->getTypeLoc();
7587 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7588 TypeLocBuilder TLB;
7589 TLB.reserve(FromTL.getFullDataSize());
7590 QualType To = getDerived().TransformType(TLB, FromTL);
7591 if (To.isNull())
7592 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007593
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007594 if (To == From->getType())
7595 Args.push_back(From);
7596 else {
7597 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7598 ArgChanged = true;
7599 }
7600 continue;
7601 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007602
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007603 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007604
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007605 // We have a pack expansion. Instantiate it.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007606 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007607 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7608 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7609 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007610
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007611 // Determine whether the set of unexpanded parameter packs can and should
7612 // be expanded.
7613 bool Expand = true;
7614 bool RetainExpansion = false;
7615 llvm::Optional<unsigned> OrigNumExpansions
7616 = ExpansionTL.getTypePtr()->getNumExpansions();
7617 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7618 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7619 PatternTL.getSourceRange(),
7620 Unexpanded,
7621 Expand, RetainExpansion,
7622 NumExpansions))
7623 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007624
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007625 if (!Expand) {
7626 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007627 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007628 // expansion.
7629 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007630
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007631 TypeLocBuilder TLB;
7632 TLB.reserve(From->getTypeLoc().getFullDataSize());
7633
7634 QualType To = getDerived().TransformType(TLB, PatternTL);
7635 if (To.isNull())
7636 return ExprError();
7637
Chad Rosier4a9d7952012-08-08 18:46:20 +00007638 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007639 PatternTL.getSourceRange(),
7640 ExpansionTL.getEllipsisLoc(),
7641 NumExpansions);
7642 if (To.isNull())
7643 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007644
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007645 PackExpansionTypeLoc ToExpansionTL
7646 = TLB.push<PackExpansionTypeLoc>(To);
7647 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7648 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7649 continue;
7650 }
7651
7652 // Expand the pack expansion by substituting for each argument in the
7653 // pack(s).
7654 for (unsigned I = 0; I != *NumExpansions; ++I) {
7655 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7656 TypeLocBuilder TLB;
7657 TLB.reserve(PatternTL.getFullDataSize());
7658 QualType To = getDerived().TransformType(TLB, PatternTL);
7659 if (To.isNull())
7660 return ExprError();
7661
7662 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7663 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007664
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007665 if (!RetainExpansion)
7666 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007667
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007668 // If we're supposed to retain a pack expansion, do so by temporarily
7669 // forgetting the partially-substituted parameter pack.
7670 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7671
7672 TypeLocBuilder TLB;
7673 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007674
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007675 QualType To = getDerived().TransformType(TLB, PatternTL);
7676 if (To.isNull())
7677 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007678
7679 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007680 PatternTL.getSourceRange(),
7681 ExpansionTL.getEllipsisLoc(),
7682 NumExpansions);
7683 if (To.isNull())
7684 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007685
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007686 PackExpansionTypeLoc ToExpansionTL
7687 = TLB.push<PackExpansionTypeLoc>(To);
7688 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7689 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7690 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007691
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007692 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7693 return SemaRef.Owned(E);
7694
7695 return getDerived().RebuildTypeTrait(E->getTrait(),
7696 E->getLocStart(),
7697 Args,
7698 E->getLocEnd());
7699}
7700
7701template<typename Derived>
7702ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007703TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7704 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7705 if (!T)
7706 return ExprError();
7707
7708 if (!getDerived().AlwaysRebuild() &&
7709 T == E->getQueriedTypeSourceInfo())
7710 return SemaRef.Owned(E);
7711
7712 ExprResult SubExpr;
7713 {
7714 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7715 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7716 if (SubExpr.isInvalid())
7717 return ExprError();
7718
7719 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7720 return SemaRef.Owned(E);
7721 }
7722
7723 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7724 E->getLocStart(),
7725 T,
7726 SubExpr.get(),
7727 E->getLocEnd());
7728}
7729
7730template<typename Derived>
7731ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007732TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7733 ExprResult SubExpr;
7734 {
7735 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7736 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7737 if (SubExpr.isInvalid())
7738 return ExprError();
7739
7740 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7741 return SemaRef.Owned(E);
7742 }
7743
7744 return getDerived().RebuildExpressionTrait(
7745 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7746}
7747
7748template<typename Derived>
7749ExprResult
John McCall865d4472009-11-19 22:55:06 +00007750TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007751 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00007752 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
7753}
7754
7755template<typename Derived>
7756ExprResult
7757TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
7758 DependentScopeDeclRefExpr *E,
7759 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007760 NestedNameSpecifierLoc QualifierLoc
7761 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7762 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007763 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007764 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007765
John McCall43fed0d2010-11-12 08:19:04 +00007766 // TODO: If this is a conversion-function-id, verify that the
7767 // destination type name (if present) resolves the same way after
7768 // instantiation as it did in the local scope.
7769
Abramo Bagnara25777432010-08-11 22:01:17 +00007770 DeclarationNameInfo NameInfo
7771 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7772 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007773 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007774
John McCallf7a1a742009-11-24 19:00:30 +00007775 if (!E->hasExplicitTemplateArgs()) {
7776 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007777 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007778 // Note: it is sufficient to compare the Name component of NameInfo:
7779 // if name has not changed, DNLoc has not changed either.
7780 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007781 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007782
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007783 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007784 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007785 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007786 /*TemplateArgs*/ 0,
7787 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007788 }
John McCalld5532b62009-11-23 01:53:49 +00007789
7790 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007791 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7792 E->getNumTemplateArgs(),
7793 TransArgs))
7794 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007795
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007796 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007797 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007798 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007799 &TransArgs,
7800 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007801}
7802
7803template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007804ExprResult
John McCall454feb92009-12-08 09:21:05 +00007805TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00007806 // CXXConstructExprs other than for list-initialization and
7807 // CXXTemporaryObjectExpr are always implicit, so when we have
7808 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00007809 if ((E->getNumArgs() == 1 ||
7810 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00007811 (!getDerived().DropCallArgument(E->getArg(0))) &&
7812 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00007813 return getDerived().TransformExpr(E->getArg(0));
7814
Douglas Gregorb98b1992009-08-11 05:31:07 +00007815 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7816
7817 QualType T = getDerived().TransformType(E->getType());
7818 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007819 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007820
7821 CXXConstructorDecl *Constructor
7822 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007823 getDerived().TransformDecl(E->getLocStart(),
7824 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007825 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007826 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007827
Douglas Gregorb98b1992009-08-11 05:31:07 +00007828 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007829 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007830 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007831 &ArgumentChanged))
7832 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007833
Douglas Gregorb98b1992009-08-11 05:31:07 +00007834 if (!getDerived().AlwaysRebuild() &&
7835 T == E->getType() &&
7836 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007837 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007838 // Mark the constructor as referenced.
7839 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007840 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007841 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007842 }
Mike Stump1eb44332009-09-09 15:08:12 +00007843
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007844 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7845 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007846 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007847 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00007848 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007849 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007850 E->getConstructionKind(),
7851 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007852}
Mike Stump1eb44332009-09-09 15:08:12 +00007853
Douglas Gregorb98b1992009-08-11 05:31:07 +00007854/// \brief Transform a C++ temporary-binding expression.
7855///
Douglas Gregor51326552009-12-24 18:51:59 +00007856/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7857/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007858template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007859ExprResult
John McCall454feb92009-12-08 09:21:05 +00007860TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007861 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007862}
Mike Stump1eb44332009-09-09 15:08:12 +00007863
John McCall4765fa02010-12-06 08:20:24 +00007864/// \brief Transform a C++ expression that contains cleanups that should
7865/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007866///
John McCall4765fa02010-12-06 08:20:24 +00007867/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007868/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007869template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007870ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007871TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007872 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007873}
Mike Stump1eb44332009-09-09 15:08:12 +00007874
Douglas Gregorb98b1992009-08-11 05:31:07 +00007875template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007876ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007877TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007878 CXXTemporaryObjectExpr *E) {
7879 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7880 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007881 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007882
Douglas Gregorb98b1992009-08-11 05:31:07 +00007883 CXXConstructorDecl *Constructor
7884 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00007885 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007886 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007887 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007888 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007889
Douglas Gregorb98b1992009-08-11 05:31:07 +00007890 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007891 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007892 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007893 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007894 &ArgumentChanged))
7895 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007896
Douglas Gregorb98b1992009-08-11 05:31:07 +00007897 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007898 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007899 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007900 !ArgumentChanged) {
7901 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007902 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007903 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007904 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007905
Richard Smithc83c2302012-12-19 01:39:02 +00007906 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00007907 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7908 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007909 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007910 E->getLocEnd());
7911}
Mike Stump1eb44332009-09-09 15:08:12 +00007912
Douglas Gregorb98b1992009-08-11 05:31:07 +00007913template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007914ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007915TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007916 // Transform the type of the lambda parameters and start the definition of
7917 // the lambda itself.
7918 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00007919 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00007920 if (!MethodTy)
7921 return ExprError();
7922
Eli Friedman8da8a662012-09-19 01:18:11 +00007923 // Create the local class that will describe the lambda.
7924 CXXRecordDecl *Class
7925 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7926 MethodTy,
7927 /*KnownDependent=*/false);
7928 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7929
Douglas Gregorc6889e72012-02-14 22:28:59 +00007930 // Transform lambda parameters.
Douglas Gregorc6889e72012-02-14 22:28:59 +00007931 llvm::SmallVector<QualType, 4> ParamTypes;
7932 llvm::SmallVector<ParmVarDecl *, 4> Params;
7933 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7934 E->getCallOperator()->param_begin(),
7935 E->getCallOperator()->param_size(),
7936 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00007937 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00007938
Douglas Gregordfca6f52012-02-13 22:00:16 +00007939 // Build the call operator.
7940 CXXMethodDecl *CallOperator
7941 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007942 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007943 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007944 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007945 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00007946
Richard Smith612409e2012-07-25 03:56:55 +00007947 return getDerived().TransformLambdaScope(E, CallOperator);
7948}
7949
7950template<typename Derived>
7951ExprResult
7952TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
7953 CXXMethodDecl *CallOperator) {
Douglas Gregord5387e82012-02-14 00:00:48 +00007954 // Introduce the context of the call operator.
7955 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7956
Douglas Gregordfca6f52012-02-13 22:00:16 +00007957 // Enter the scope of the lambda.
7958 sema::LambdaScopeInfo *LSI
7959 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7960 E->getCaptureDefault(),
7961 E->hasExplicitParameters(),
7962 E->hasExplicitResultType(),
7963 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007964
Douglas Gregordfca6f52012-02-13 22:00:16 +00007965 // Transform captures.
Richard Smith612409e2012-07-25 03:56:55 +00007966 bool Invalid = false;
Douglas Gregordfca6f52012-02-13 22:00:16 +00007967 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007968 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007969 CEnd = E->capture_end();
7970 C != CEnd; ++C) {
7971 // When we hit the first implicit capture, tell Sema that we've finished
7972 // the list of explicit captures.
7973 if (!FinishedExplicitCaptures && C->isImplicit()) {
7974 getSema().finishLambdaExplicitCaptures(LSI);
7975 FinishedExplicitCaptures = true;
7976 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007977
Douglas Gregordfca6f52012-02-13 22:00:16 +00007978 // Capturing 'this' is trivial.
7979 if (C->capturesThis()) {
7980 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7981 continue;
7982 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007983
Douglas Gregora7365242012-02-14 19:27:52 +00007984 // Determine the capture kind for Sema.
7985 Sema::TryCaptureKind Kind
7986 = C->isImplicit()? Sema::TryCapture_Implicit
7987 : C->getCaptureKind() == LCK_ByCopy
7988 ? Sema::TryCapture_ExplicitByVal
7989 : Sema::TryCapture_ExplicitByRef;
7990 SourceLocation EllipsisLoc;
7991 if (C->isPackExpansion()) {
7992 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7993 bool ShouldExpand = false;
7994 bool RetainExpansion = false;
7995 llvm::Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007996 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7997 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00007998 Unexpanded,
7999 ShouldExpand, RetainExpansion,
8000 NumExpansions))
8001 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008002
Douglas Gregora7365242012-02-14 19:27:52 +00008003 if (ShouldExpand) {
8004 // The transform has determined that we should perform an expansion;
8005 // transform and capture each of the arguments.
8006 // expansion of the pattern. Do so.
8007 VarDecl *Pack = C->getCapturedVar();
8008 for (unsigned I = 0; I != *NumExpansions; ++I) {
8009 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8010 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008011 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008012 Pack));
8013 if (!CapturedVar) {
8014 Invalid = true;
8015 continue;
8016 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008017
Douglas Gregora7365242012-02-14 19:27:52 +00008018 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008019 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8020 }
Douglas Gregora7365242012-02-14 19:27:52 +00008021 continue;
8022 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008023
Douglas Gregora7365242012-02-14 19:27:52 +00008024 EllipsisLoc = C->getEllipsisLoc();
8025 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008026
Douglas Gregordfca6f52012-02-13 22:00:16 +00008027 // Transform the captured variable.
8028 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008029 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008030 C->getCapturedVar()));
8031 if (!CapturedVar) {
8032 Invalid = true;
8033 continue;
8034 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008035
Douglas Gregordfca6f52012-02-13 22:00:16 +00008036 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008037 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008038 }
8039 if (!FinishedExplicitCaptures)
8040 getSema().finishLambdaExplicitCaptures(LSI);
8041
Douglas Gregordfca6f52012-02-13 22:00:16 +00008042
8043 // Enter a new evaluation context to insulate the lambda from any
8044 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008045 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008046
8047 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008048 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008049 /*IsInstantiation=*/true);
8050 return ExprError();
8051 }
8052
8053 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008054 StmtResult Body = getDerived().TransformStmt(E->getBody());
8055 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008056 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008057 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008058 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008059 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008060
Chad Rosier4a9d7952012-08-08 18:46:20 +00008061 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008062 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008063}
8064
8065template<typename Derived>
8066ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008067TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008068 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008069 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8070 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008071 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008072
Douglas Gregorb98b1992009-08-11 05:31:07 +00008073 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008074 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008075 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008076 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008077 &ArgumentChanged))
8078 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008079
Douglas Gregorb98b1992009-08-11 05:31:07 +00008080 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008081 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008082 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008083 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008084
Douglas Gregorb98b1992009-08-11 05:31:07 +00008085 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008086 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008087 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008088 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008089 E->getRParenLoc());
8090}
Mike Stump1eb44332009-09-09 15:08:12 +00008091
Douglas Gregorb98b1992009-08-11 05:31:07 +00008092template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008093ExprResult
John McCall865d4472009-11-19 22:55:06 +00008094TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008095 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008096 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008097 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008098 Expr *OldBase;
8099 QualType BaseType;
8100 QualType ObjectType;
8101 if (!E->isImplicitAccess()) {
8102 OldBase = E->getBase();
8103 Base = getDerived().TransformExpr(OldBase);
8104 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008105 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008106
John McCallaa81e162009-12-01 22:10:20 +00008107 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008108 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008109 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008110 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008111 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008112 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008113 ObjectTy,
8114 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008115 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008116 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008117
John McCallb3d87482010-08-24 05:47:05 +00008118 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008119 BaseType = ((Expr*) Base.get())->getType();
8120 } else {
8121 OldBase = 0;
8122 BaseType = getDerived().TransformType(E->getBaseType());
8123 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8124 }
Mike Stump1eb44332009-09-09 15:08:12 +00008125
Douglas Gregor6cd21982009-10-20 05:58:46 +00008126 // Transform the first part of the nested-name-specifier that qualifies
8127 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008128 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008129 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008130 E->getFirstQualifierFoundInScope(),
8131 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008132
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008133 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008134 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008135 QualifierLoc
8136 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8137 ObjectType,
8138 FirstQualifierInScope);
8139 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008140 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008141 }
Mike Stump1eb44332009-09-09 15:08:12 +00008142
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008143 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8144
John McCall43fed0d2010-11-12 08:19:04 +00008145 // TODO: If this is a conversion-function-id, verify that the
8146 // destination type name (if present) resolves the same way after
8147 // instantiation as it did in the local scope.
8148
Abramo Bagnara25777432010-08-11 22:01:17 +00008149 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008150 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008151 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008152 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008153
John McCallaa81e162009-12-01 22:10:20 +00008154 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008155 // This is a reference to a member without an explicitly-specified
8156 // template argument list. Optimize for this common case.
8157 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008158 Base.get() == OldBase &&
8159 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008160 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008161 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008162 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008163 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008164
John McCall9ae2f072010-08-23 23:25:46 +00008165 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008166 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008167 E->isArrow(),
8168 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008169 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008170 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008171 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008172 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008173 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008174 }
8175
John McCalld5532b62009-11-23 01:53:49 +00008176 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008177 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8178 E->getNumTemplateArgs(),
8179 TransArgs))
8180 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008181
John McCall9ae2f072010-08-23 23:25:46 +00008182 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008183 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008184 E->isArrow(),
8185 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008186 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008187 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008188 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008189 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008190 &TransArgs);
8191}
8192
8193template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008194ExprResult
John McCall454feb92009-12-08 09:21:05 +00008195TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008196 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008197 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008198 QualType BaseType;
8199 if (!Old->isImplicitAccess()) {
8200 Base = getDerived().TransformExpr(Old->getBase());
8201 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008202 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008203 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8204 Old->isArrow());
8205 if (Base.isInvalid())
8206 return ExprError();
8207 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008208 } else {
8209 BaseType = getDerived().TransformType(Old->getBaseType());
8210 }
John McCall129e2df2009-11-30 22:42:35 +00008211
Douglas Gregor4c9be892011-02-28 20:01:57 +00008212 NestedNameSpecifierLoc QualifierLoc;
8213 if (Old->getQualifierLoc()) {
8214 QualifierLoc
8215 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8216 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008217 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008218 }
8219
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008220 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8221
Abramo Bagnara25777432010-08-11 22:01:17 +00008222 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008223 Sema::LookupOrdinaryName);
8224
8225 // Transform all the decls.
8226 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8227 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008228 NamedDecl *InstD = static_cast<NamedDecl*>(
8229 getDerived().TransformDecl(Old->getMemberLoc(),
8230 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008231 if (!InstD) {
8232 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8233 // This can happen because of dependent hiding.
8234 if (isa<UsingShadowDecl>(*I))
8235 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008236 else {
8237 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008238 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008239 }
John McCall9f54ad42009-12-10 09:41:52 +00008240 }
John McCall129e2df2009-11-30 22:42:35 +00008241
8242 // Expand using declarations.
8243 if (isa<UsingDecl>(InstD)) {
8244 UsingDecl *UD = cast<UsingDecl>(InstD);
8245 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8246 E = UD->shadow_end(); I != E; ++I)
8247 R.addDecl(*I);
8248 continue;
8249 }
8250
8251 R.addDecl(InstD);
8252 }
8253
8254 R.resolveKind();
8255
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008256 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008257 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008258 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008259 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008260 Old->getMemberLoc(),
8261 Old->getNamingClass()));
8262 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008263 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008264
Douglas Gregor66c45152010-04-27 16:10:10 +00008265 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008266 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008267
John McCall129e2df2009-11-30 22:42:35 +00008268 TemplateArgumentListInfo TransArgs;
8269 if (Old->hasExplicitTemplateArgs()) {
8270 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8271 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008272 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8273 Old->getNumTemplateArgs(),
8274 TransArgs))
8275 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008276 }
John McCallc2233c52010-01-15 08:34:02 +00008277
8278 // FIXME: to do this check properly, we will need to preserve the
8279 // first-qualifier-in-scope here, just in case we had a dependent
8280 // base (and therefore couldn't do the check) and a
8281 // nested-name-qualifier (and therefore could do the lookup).
8282 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008283
John McCall9ae2f072010-08-23 23:25:46 +00008284 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008285 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008286 Old->getOperatorLoc(),
8287 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008288 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008289 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008290 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008291 R,
8292 (Old->hasExplicitTemplateArgs()
8293 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008294}
8295
8296template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008297ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008298TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008299 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008300 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8301 if (SubExpr.isInvalid())
8302 return ExprError();
8303
8304 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008305 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008306
8307 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8308}
8309
8310template<typename Derived>
8311ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008312TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008313 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8314 if (Pattern.isInvalid())
8315 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008316
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008317 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8318 return SemaRef.Owned(E);
8319
Douglas Gregor67fd1252011-01-14 21:20:45 +00008320 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8321 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008322}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008323
8324template<typename Derived>
8325ExprResult
8326TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8327 // If E is not value-dependent, then nothing will change when we transform it.
8328 // Note: This is an instantiation-centric view.
8329 if (!E->isValueDependent())
8330 return SemaRef.Owned(E);
8331
8332 // Note: None of the implementations of TryExpandParameterPacks can ever
8333 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008334 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008335 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8336 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008337 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008338 llvm::Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008339 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008340 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008341 ShouldExpand, RetainExpansion,
8342 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008343 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008344
Douglas Gregor089e8932011-10-10 18:59:29 +00008345 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008346 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008347
Douglas Gregor089e8932011-10-10 18:59:29 +00008348 NamedDecl *Pack = E->getPack();
8349 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008350 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008351 Pack));
8352 if (!Pack)
8353 return ExprError();
8354 }
8355
Chad Rosier4a9d7952012-08-08 18:46:20 +00008356
Douglas Gregoree8aff02011-01-04 17:33:58 +00008357 // We now know the length of the parameter pack, so build a new expression
8358 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008359 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8360 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008361 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008362}
8363
Douglas Gregorbe230c32011-01-03 17:17:50 +00008364template<typename Derived>
8365ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008366TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8367 SubstNonTypeTemplateParmPackExpr *E) {
8368 // Default behavior is to do nothing with this transformation.
8369 return SemaRef.Owned(E);
8370}
8371
8372template<typename Derived>
8373ExprResult
John McCall91a57552011-07-15 05:09:51 +00008374TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8375 SubstNonTypeTemplateParmExpr *E) {
8376 // Default behavior is to do nothing with this transformation.
8377 return SemaRef.Owned(E);
8378}
8379
8380template<typename Derived>
8381ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008382TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8383 // Default behavior is to do nothing with this transformation.
8384 return SemaRef.Owned(E);
8385}
8386
8387template<typename Derived>
8388ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008389TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8390 MaterializeTemporaryExpr *E) {
8391 return getDerived().TransformExpr(E->GetTemporaryExpr());
8392}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008393
Douglas Gregor03e80032011-06-21 17:03:29 +00008394template<typename Derived>
8395ExprResult
John McCall454feb92009-12-08 09:21:05 +00008396TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008397 return SemaRef.MaybeBindToTemporary(E);
8398}
8399
8400template<typename Derived>
8401ExprResult
8402TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008403 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008404}
8405
8406template<typename Derived>
8407ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008408TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8409 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8410 if (SubExpr.isInvalid())
8411 return ExprError();
8412
8413 if (!getDerived().AlwaysRebuild() &&
8414 SubExpr.get() == E->getSubExpr())
8415 return SemaRef.Owned(E);
8416
8417 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008418}
8419
8420template<typename Derived>
8421ExprResult
8422TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8423 // Transform each of the elements.
8424 llvm::SmallVector<Expr *, 8> Elements;
8425 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008426 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008427 /*IsCall=*/false, Elements, &ArgChanged))
8428 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008429
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008430 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8431 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008432
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008433 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8434 Elements.data(),
8435 Elements.size());
8436}
8437
8438template<typename Derived>
8439ExprResult
8440TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008441 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008442 // Transform each of the elements.
8443 llvm::SmallVector<ObjCDictionaryElement, 8> Elements;
8444 bool ArgChanged = false;
8445 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8446 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008447
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008448 if (OrigElement.isPackExpansion()) {
8449 // This key/value element is a pack expansion.
8450 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8451 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8452 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8453 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8454
8455 // Determine whether the set of unexpanded parameter packs can
8456 // and should be expanded.
8457 bool Expand = true;
8458 bool RetainExpansion = false;
8459 llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8460 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
8461 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8462 OrigElement.Value->getLocEnd());
8463 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8464 PatternRange,
8465 Unexpanded,
8466 Expand, RetainExpansion,
8467 NumExpansions))
8468 return ExprError();
8469
8470 if (!Expand) {
8471 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008472 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008473 // expansion.
8474 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8475 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8476 if (Key.isInvalid())
8477 return ExprError();
8478
8479 if (Key.get() != OrigElement.Key)
8480 ArgChanged = true;
8481
8482 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8483 if (Value.isInvalid())
8484 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008485
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008486 if (Value.get() != OrigElement.Value)
8487 ArgChanged = true;
8488
Chad Rosier4a9d7952012-08-08 18:46:20 +00008489 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008490 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8491 };
8492 Elements.push_back(Expansion);
8493 continue;
8494 }
8495
8496 // Record right away that the argument was changed. This needs
8497 // to happen even if the array expands to nothing.
8498 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008499
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008500 // The transform has determined that we should perform an elementwise
8501 // expansion of the pattern. Do so.
8502 for (unsigned I = 0; I != *NumExpansions; ++I) {
8503 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8504 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8505 if (Key.isInvalid())
8506 return ExprError();
8507
8508 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8509 if (Value.isInvalid())
8510 return ExprError();
8511
Chad Rosier4a9d7952012-08-08 18:46:20 +00008512 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008513 Key.get(), Value.get(), SourceLocation(), NumExpansions
8514 };
8515
8516 // If any unexpanded parameter packs remain, we still have a
8517 // pack expansion.
8518 if (Key.get()->containsUnexpandedParameterPack() ||
8519 Value.get()->containsUnexpandedParameterPack())
8520 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008521
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008522 Elements.push_back(Element);
8523 }
8524
8525 // We've finished with this pack expansion.
8526 continue;
8527 }
8528
8529 // Transform and check key.
8530 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8531 if (Key.isInvalid())
8532 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008533
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008534 if (Key.get() != OrigElement.Key)
8535 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008536
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008537 // Transform and check value.
8538 ExprResult Value
8539 = getDerived().TransformExpr(OrigElement.Value);
8540 if (Value.isInvalid())
8541 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008542
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008543 if (Value.get() != OrigElement.Value)
8544 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008545
8546 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008547 Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8548 };
8549 Elements.push_back(Element);
8550 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008551
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008552 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8553 return SemaRef.MaybeBindToTemporary(E);
8554
8555 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8556 Elements.data(),
8557 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008558}
8559
Mike Stump1eb44332009-09-09 15:08:12 +00008560template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008561ExprResult
John McCall454feb92009-12-08 09:21:05 +00008562TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008563 TypeSourceInfo *EncodedTypeInfo
8564 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8565 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008566 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008567
Douglas Gregorb98b1992009-08-11 05:31:07 +00008568 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008569 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008570 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008571
8572 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008573 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008574 E->getRParenLoc());
8575}
Mike Stump1eb44332009-09-09 15:08:12 +00008576
Douglas Gregorb98b1992009-08-11 05:31:07 +00008577template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008578ExprResult TreeTransform<Derived>::
8579TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8580 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8581 if (result.isInvalid()) return ExprError();
8582 Expr *subExpr = result.take();
8583
8584 if (!getDerived().AlwaysRebuild() &&
8585 subExpr == E->getSubExpr())
8586 return SemaRef.Owned(E);
8587
8588 return SemaRef.Owned(new(SemaRef.Context)
8589 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8590}
8591
8592template<typename Derived>
8593ExprResult TreeTransform<Derived>::
8594TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008595 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008596 = getDerived().TransformType(E->getTypeInfoAsWritten());
8597 if (!TSInfo)
8598 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008599
John McCallf85e1932011-06-15 23:02:42 +00008600 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008601 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008602 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008603
John McCallf85e1932011-06-15 23:02:42 +00008604 if (!getDerived().AlwaysRebuild() &&
8605 TSInfo == E->getTypeInfoAsWritten() &&
8606 Result.get() == E->getSubExpr())
8607 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008608
John McCallf85e1932011-06-15 23:02:42 +00008609 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008610 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008611 Result.get());
8612}
8613
8614template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008615ExprResult
John McCall454feb92009-12-08 09:21:05 +00008616TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008617 // Transform arguments.
8618 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008619 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008620 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008621 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008622 &ArgChanged))
8623 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008624
Douglas Gregor92e986e2010-04-22 16:44:27 +00008625 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8626 // Class message: transform the receiver type.
8627 TypeSourceInfo *ReceiverTypeInfo
8628 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8629 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008630 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008631
Douglas Gregor92e986e2010-04-22 16:44:27 +00008632 // If nothing changed, just retain the existing message send.
8633 if (!getDerived().AlwaysRebuild() &&
8634 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008635 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008636
8637 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008638 SmallVector<SourceLocation, 16> SelLocs;
8639 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008640 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8641 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008642 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008643 E->getMethodDecl(),
8644 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008645 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008646 E->getRightLoc());
8647 }
8648
8649 // Instance message: transform the receiver
8650 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8651 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008652 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008653 = getDerived().TransformExpr(E->getInstanceReceiver());
8654 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008655 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008656
8657 // If nothing changed, just retain the existing message send.
8658 if (!getDerived().AlwaysRebuild() &&
8659 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008660 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008661
Douglas Gregor92e986e2010-04-22 16:44:27 +00008662 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008663 SmallVector<SourceLocation, 16> SelLocs;
8664 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008665 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008666 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008667 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008668 E->getMethodDecl(),
8669 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008670 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008671 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008672}
8673
Mike Stump1eb44332009-09-09 15:08:12 +00008674template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008675ExprResult
John McCall454feb92009-12-08 09:21:05 +00008676TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008677 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008678}
8679
Mike Stump1eb44332009-09-09 15:08:12 +00008680template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008681ExprResult
John McCall454feb92009-12-08 09:21:05 +00008682TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008683 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008684}
8685
Mike Stump1eb44332009-09-09 15:08:12 +00008686template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008687ExprResult
John McCall454feb92009-12-08 09:21:05 +00008688TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008689 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008690 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008691 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008692 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008693
8694 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008695
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008696 // If nothing changed, just retain the existing expression.
8697 if (!getDerived().AlwaysRebuild() &&
8698 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008699 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008700
John McCall9ae2f072010-08-23 23:25:46 +00008701 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008702 E->getLocation(),
8703 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008704}
8705
Mike Stump1eb44332009-09-09 15:08:12 +00008706template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008707ExprResult
John McCall454feb92009-12-08 09:21:05 +00008708TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008709 // 'super' and types never change. Property never changes. Just
8710 // retain the existing expression.
8711 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008712 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008713
Douglas Gregore3303542010-04-26 20:47:02 +00008714 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008715 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008716 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008717 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008718
Douglas Gregore3303542010-04-26 20:47:02 +00008719 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008720
Douglas Gregore3303542010-04-26 20:47:02 +00008721 // If nothing changed, just retain the existing expression.
8722 if (!getDerived().AlwaysRebuild() &&
8723 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008724 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008725
John McCall12f78a62010-12-02 01:19:52 +00008726 if (E->isExplicitProperty())
8727 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8728 E->getExplicitProperty(),
8729 E->getLocation());
8730
8731 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008732 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008733 E->getImplicitPropertyGetter(),
8734 E->getImplicitPropertySetter(),
8735 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008736}
8737
Mike Stump1eb44332009-09-09 15:08:12 +00008738template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008739ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008740TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8741 // Transform the base expression.
8742 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8743 if (Base.isInvalid())
8744 return ExprError();
8745
8746 // Transform the key expression.
8747 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8748 if (Key.isInvalid())
8749 return ExprError();
8750
8751 // If nothing changed, just retain the existing expression.
8752 if (!getDerived().AlwaysRebuild() &&
8753 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8754 return SemaRef.Owned(E);
8755
Chad Rosier4a9d7952012-08-08 18:46:20 +00008756 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008757 Base.get(), Key.get(),
8758 E->getAtIndexMethodDecl(),
8759 E->setAtIndexMethodDecl());
8760}
8761
8762template<typename Derived>
8763ExprResult
John McCall454feb92009-12-08 09:21:05 +00008764TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008765 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008766 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008767 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008768 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008769
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008770 // If nothing changed, just retain the existing expression.
8771 if (!getDerived().AlwaysRebuild() &&
8772 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008773 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008774
John McCall9ae2f072010-08-23 23:25:46 +00008775 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008776 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008777}
8778
Mike Stump1eb44332009-09-09 15:08:12 +00008779template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008780ExprResult
John McCall454feb92009-12-08 09:21:05 +00008781TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008782 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008783 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008784 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008785 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008786 SubExprs, &ArgumentChanged))
8787 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008788
Douglas Gregorb98b1992009-08-11 05:31:07 +00008789 if (!getDerived().AlwaysRebuild() &&
8790 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008791 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008792
Douglas Gregorb98b1992009-08-11 05:31:07 +00008793 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008794 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008795 E->getRParenLoc());
8796}
8797
Mike Stump1eb44332009-09-09 15:08:12 +00008798template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008799ExprResult
John McCall454feb92009-12-08 09:21:05 +00008800TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008801 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008802
John McCallc6ac9c32011-02-04 18:33:18 +00008803 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8804 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8805
8806 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008807 blockScope->TheDecl->setBlockMissingReturnType(
8808 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008809
Chris Lattner686775d2011-07-20 06:58:45 +00008810 SmallVector<ParmVarDecl*, 4> params;
8811 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008812
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008813 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008814 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8815 oldBlock->param_begin(),
8816 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008817 0, paramTypes, &params)) {
8818 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008819 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008820 }
John McCallc6ac9c32011-02-04 18:33:18 +00008821
8822 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008823 QualType exprResultType =
8824 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008825
8826 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008827 if (exprResultType->isObjCObjectType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008828 getSema().Diag(E->getCaretLocation(),
8829 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008830 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008831 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008832 return ExprError();
8833 }
John McCall711c52b2011-01-05 12:14:39 +00008834
John McCallc6ac9c32011-02-04 18:33:18 +00008835 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008836 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008837 paramTypes.data(),
8838 paramTypes.size(),
8839 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008840 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008841 exprFunctionType->getExtInfo());
8842 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008843
8844 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008845 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008846 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008847
8848 if (!oldBlock->blockMissingReturnType()) {
8849 blockScope->HasImplicitReturnType = false;
8850 blockScope->ReturnType = exprResultType;
8851 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008852
John McCall711c52b2011-01-05 12:14:39 +00008853 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008854 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008855 if (body.isInvalid()) {
8856 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008857 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008858 }
John McCall711c52b2011-01-05 12:14:39 +00008859
John McCallc6ac9c32011-02-04 18:33:18 +00008860#ifndef NDEBUG
8861 // In builds with assertions, make sure that we captured everything we
8862 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008863 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8864 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8865 e = oldBlock->capture_end(); i != e; ++i) {
8866 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008867
Douglas Gregorfc921372011-05-20 15:32:55 +00008868 // Ignore parameter packs.
8869 if (isa<ParmVarDecl>(oldCapture) &&
8870 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8871 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008872
Douglas Gregorfc921372011-05-20 15:32:55 +00008873 VarDecl *newCapture =
8874 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8875 oldCapture));
8876 assert(blockScope->CaptureMap.count(newCapture));
8877 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008878 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008879 }
8880#endif
8881
8882 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8883 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008884}
8885
Mike Stump1eb44332009-09-09 15:08:12 +00008886template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008887ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008888TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008889 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008890}
Eli Friedman276b0612011-10-11 02:20:01 +00008891
8892template<typename Derived>
8893ExprResult
8894TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008895 QualType RetTy = getDerived().TransformType(E->getType());
8896 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008897 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008898 SubExprs.reserve(E->getNumSubExprs());
8899 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8900 SubExprs, &ArgumentChanged))
8901 return ExprError();
8902
8903 if (!getDerived().AlwaysRebuild() &&
8904 !ArgumentChanged)
8905 return SemaRef.Owned(E);
8906
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008907 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008908 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008909}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008910
Douglas Gregorb98b1992009-08-11 05:31:07 +00008911//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008912// Type reconstruction
8913//===----------------------------------------------------------------------===//
8914
Mike Stump1eb44332009-09-09 15:08:12 +00008915template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008916QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8917 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008918 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008919 getDerived().getBaseEntity());
8920}
8921
Mike Stump1eb44332009-09-09 15:08:12 +00008922template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008923QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8924 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008925 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008926 getDerived().getBaseEntity());
8927}
8928
Mike Stump1eb44332009-09-09 15:08:12 +00008929template<typename Derived>
8930QualType
John McCall85737a72009-10-30 00:06:24 +00008931TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8932 bool WrittenAsLValue,
8933 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008934 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008935 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008936}
8937
8938template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008939QualType
John McCall85737a72009-10-30 00:06:24 +00008940TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8941 QualType ClassType,
8942 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008943 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008944 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008945}
8946
8947template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008948QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008949TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8950 ArrayType::ArraySizeModifier SizeMod,
8951 const llvm::APInt *Size,
8952 Expr *SizeExpr,
8953 unsigned IndexTypeQuals,
8954 SourceRange BracketsRange) {
8955 if (SizeExpr || !Size)
8956 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8957 IndexTypeQuals, BracketsRange,
8958 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008959
8960 QualType Types[] = {
8961 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8962 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8963 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008964 };
8965 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8966 QualType SizeType;
8967 for (unsigned I = 0; I != NumTypes; ++I)
8968 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8969 SizeType = Types[I];
8970 break;
8971 }
Mike Stump1eb44332009-09-09 15:08:12 +00008972
Eli Friedman01f276d2012-01-25 23:20:27 +00008973 // Note that we can return a VariableArrayType here in the case where
8974 // the element type was a dependent VariableArrayType.
8975 IntegerLiteral *ArraySize
8976 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8977 /*FIXME*/BracketsRange.getBegin());
8978 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008979 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008980 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008981}
Mike Stump1eb44332009-09-09 15:08:12 +00008982
Douglas Gregor577f75a2009-08-04 16:50:30 +00008983template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008984QualType
8985TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008986 ArrayType::ArraySizeModifier SizeMod,
8987 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008988 unsigned IndexTypeQuals,
8989 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008990 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008991 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008992}
8993
8994template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008995QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008996TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008997 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008998 unsigned IndexTypeQuals,
8999 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009000 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009001 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009002}
Mike Stump1eb44332009-09-09 15:08:12 +00009003
Douglas Gregor577f75a2009-08-04 16:50:30 +00009004template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009005QualType
9006TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009007 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009008 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009009 unsigned IndexTypeQuals,
9010 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009011 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009012 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009013 IndexTypeQuals, BracketsRange);
9014}
9015
9016template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009017QualType
9018TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009019 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009020 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009021 unsigned IndexTypeQuals,
9022 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009023 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009024 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009025 IndexTypeQuals, BracketsRange);
9026}
9027
9028template<typename Derived>
9029QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009030 unsigned NumElements,
9031 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009032 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009033 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009034}
Mike Stump1eb44332009-09-09 15:08:12 +00009035
Douglas Gregor577f75a2009-08-04 16:50:30 +00009036template<typename Derived>
9037QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9038 unsigned NumElements,
9039 SourceLocation AttributeLoc) {
9040 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9041 NumElements, true);
9042 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009043 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9044 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009045 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009046}
Mike Stump1eb44332009-09-09 15:08:12 +00009047
Douglas Gregor577f75a2009-08-04 16:50:30 +00009048template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009049QualType
9050TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009051 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009052 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009053 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009054}
Mike Stump1eb44332009-09-09 15:08:12 +00009055
Douglas Gregor577f75a2009-08-04 16:50:30 +00009056template<typename Derived>
9057QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00009058 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009059 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00009060 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009061 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00009062 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00009063 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00009064 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00009065 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009066 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009067 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009068 getDerived().getBaseEntity(),
9069 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009070}
Mike Stump1eb44332009-09-09 15:08:12 +00009071
Douglas Gregor577f75a2009-08-04 16:50:30 +00009072template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009073QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9074 return SemaRef.Context.getFunctionNoProtoType(T);
9075}
9076
9077template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009078QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9079 assert(D && "no decl found");
9080 if (D->isInvalidDecl()) return QualType();
9081
Douglas Gregor92e986e2010-04-22 16:44:27 +00009082 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009083 TypeDecl *Ty;
9084 if (isa<UsingDecl>(D)) {
9085 UsingDecl *Using = cast<UsingDecl>(D);
9086 assert(Using->isTypeName() &&
9087 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9088
9089 // A valid resolved using typename decl points to exactly one type decl.
9090 assert(++Using->shadow_begin() == Using->shadow_end());
9091 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009092
John McCalled976492009-12-04 22:46:56 +00009093 } else {
9094 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9095 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9096 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9097 }
9098
9099 return SemaRef.Context.getTypeDeclType(Ty);
9100}
9101
9102template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009103QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9104 SourceLocation Loc) {
9105 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009106}
9107
9108template<typename Derived>
9109QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9110 return SemaRef.Context.getTypeOfType(Underlying);
9111}
9112
9113template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009114QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9115 SourceLocation Loc) {
9116 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009117}
9118
9119template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009120QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9121 UnaryTransformType::UTTKind UKind,
9122 SourceLocation Loc) {
9123 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9124}
9125
9126template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009127QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009128 TemplateName Template,
9129 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009130 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009131 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009132}
Mike Stump1eb44332009-09-09 15:08:12 +00009133
Douglas Gregordcee1a12009-08-06 05:28:30 +00009134template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009135QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9136 SourceLocation KWLoc) {
9137 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9138}
9139
9140template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009141TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009142TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009143 bool TemplateKW,
9144 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009145 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009146 Template);
9147}
9148
9149template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009150TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009151TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9152 const IdentifierInfo &Name,
9153 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009154 QualType ObjectType,
9155 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009156 UnqualifiedId TemplateName;
9157 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009158 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009159 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009160 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009161 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009162 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009163 /*EnteringContext=*/false,
9164 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009165 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009166}
Mike Stump1eb44332009-09-09 15:08:12 +00009167
Douglas Gregorb98b1992009-08-11 05:31:07 +00009168template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009169TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009170TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009171 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009172 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009173 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009174 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009175 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009176 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009177 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009178 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009179 Sema::TemplateTy Template;
9180 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009181 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009182 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009183 /*EnteringContext=*/false,
9184 Template);
9185 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009186}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009187
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009188template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009189ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009190TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9191 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009192 Expr *OrigCallee,
9193 Expr *First,
9194 Expr *Second) {
9195 Expr *Callee = OrigCallee->IgnoreParenCasts();
9196 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009197
Douglas Gregorb98b1992009-08-11 05:31:07 +00009198 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009199 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009200 if (!First->getType()->isOverloadableType() &&
9201 !Second->getType()->isOverloadableType())
9202 return getSema().CreateBuiltinArraySubscriptExpr(First,
9203 Callee->getLocStart(),
9204 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009205 } else if (Op == OO_Arrow) {
9206 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009207 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9208 } else if (Second == 0 || isPostIncDec) {
9209 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009210 // The argument is not of overloadable type, so try to create a
9211 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009212 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009213 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009214
John McCall9ae2f072010-08-23 23:25:46 +00009215 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009216 }
9217 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009218 if (!First->getType()->isOverloadableType() &&
9219 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009220 // Neither of the arguments is an overloadable type, so try to
9221 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009222 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009223 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009224 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009225 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009226 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009227
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009228 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009229 }
9230 }
Mike Stump1eb44332009-09-09 15:08:12 +00009231
9232 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009233 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009234 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009235
John McCall9ae2f072010-08-23 23:25:46 +00009236 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009237 assert(ULE->requiresADL());
9238
9239 // FIXME: Do we have to check
9240 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009241 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009242 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009243 // If we've resolved this to a particular non-member function, just call
9244 // that function. If we resolved it to a member function,
9245 // CreateOverloaded* will find that function for us.
9246 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9247 if (!isa<CXXMethodDecl>(ND))
9248 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009249 }
Mike Stump1eb44332009-09-09 15:08:12 +00009250
Douglas Gregorb98b1992009-08-11 05:31:07 +00009251 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009252 Expr *Args[2] = { First, Second };
9253 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009254
Douglas Gregorb98b1992009-08-11 05:31:07 +00009255 // Create the overloaded operator invocation for unary operators.
9256 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009257 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009258 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009259 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009260 }
Mike Stump1eb44332009-09-09 15:08:12 +00009261
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009262 if (Op == OO_Subscript) {
9263 SourceLocation LBrace;
9264 SourceLocation RBrace;
9265
9266 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9267 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9268 LBrace = SourceLocation::getFromRawEncoding(
9269 NameLoc.CXXOperatorName.BeginOpNameLoc);
9270 RBrace = SourceLocation::getFromRawEncoding(
9271 NameLoc.CXXOperatorName.EndOpNameLoc);
9272 } else {
9273 LBrace = Callee->getLocStart();
9274 RBrace = OpLoc;
9275 }
9276
9277 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9278 First, Second);
9279 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009280
Douglas Gregorb98b1992009-08-11 05:31:07 +00009281 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009282 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009283 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009284 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9285 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009286 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009287
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009288 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009289}
Mike Stump1eb44332009-09-09 15:08:12 +00009290
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009291template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009292ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009293TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009294 SourceLocation OperatorLoc,
9295 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009296 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009297 TypeSourceInfo *ScopeType,
9298 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009299 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009300 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009301 QualType BaseType = Base->getType();
9302 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009303 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009304 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009305 !BaseType->getAs<PointerType>()->getPointeeType()
9306 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009307 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009308 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009309 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009310 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009311 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009312 /*FIXME?*/true);
9313 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009314
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009315 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009316 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9317 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9318 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9319 NameInfo.setNamedTypeInfo(DestroyedType);
9320
Richard Smith6314db92012-05-15 06:15:11 +00009321 // The scope type is now known to be a valid nested name specifier
9322 // component. Tack it on to the end of the nested name specifier.
9323 if (ScopeType)
9324 SS.Extend(SemaRef.Context, SourceLocation(),
9325 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009326
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009327 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009328 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009329 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009330 SS, TemplateKWLoc,
9331 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009332 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009333 /*TemplateArgs*/ 0);
9334}
9335
Douglas Gregor577f75a2009-08-04 16:50:30 +00009336} // end namespace clang
9337
9338#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H